Commit graph

399 commits

Author SHA1 Message Date
Olivier Goffart
6effc6449e resvg can't compile for wasm 2021-01-27 18:09:44 +01:00
Olivier Goffart
8e8e25b0b5 Render SVG images in the GL backend 2021-01-27 18:04:03 +01:00
Simon Hausmann
680995432e Minor fixes to the BoxShadow element
* Use the same property names as `Rectangle`
* Use the same sizing behavior

Also added a "manual" test.
2021-01-27 15:34:27 +01:00
Simon Hausmann
96263e04ca Fix fitted path rendering
In the old backend we transformed the path to fit into the given width/height.

The new printer page uses that.
2021-01-27 15:03:24 +01:00
Olivier Goffart
d934a20bfa Text word wrap and elide 2021-01-27 12:55:20 +01:00
Simon Hausmann
628e6fdb38 Add a BoxShadow element
This intends to provide a configurable rectangular "drop shadow". The
API is modeled after CSS/HTML5 Canvas where the element can be "bound"
to an existing rectangular shape (geometry and radius), the offset can
be used to place the shadow and color and blur configure the shadow.

The shadow's color fades into transparent.

TODO (in subsequent changes):
 * Documentation
 * Qt implementation
2021-01-26 13:56:12 +01:00
Simon Hausmann
918aab667c Fix path rendering
Don't emit move() to for every relative event, as that starts a new subpath
2021-01-25 22:04:27 +01:00
Simon Hausmann
a69ce3a397 Remove the 'align-' prefix from TextHorizontal/TextVerticalAlignment 2021-01-25 10:59:18 +01:00
Simon Hausmann
9e0927f324 Move the clipboard access from corelib to the backend
This way the backend doesn't need to depend on copypasta.
2021-01-22 15:25:06 +01:00
Olivier Goffart
3340730ff7 Use lyon to convert to path to QPainterPath or femtovg::Path 2021-01-21 13:21:03 +01:00
Olivier Goffart
15b055f89f Workaround the visible \n 2021-01-21 10:22:43 +01:00
Olivier Goffart
265efbbf4f Draw multi-line text with GL backend 2021-01-19 12:10:16 +01:00
Olivier Goffart
0fe5c535c1 Use text_size instead of text_width in FontMetrics
So that multi-line text can work
(At least it magically works with Qt)
2021-01-19 10:17:12 +01:00
Simon Hausmann
c08ad1676f Fix custom scale factor in the GL backend
Don't use the winit window's scale factor, instead use the one from the
GraphicsWindow, as tests may want to override it.
2021-01-19 09:57:00 +01:00
Simon Hausmann
5f265ffc09 Split up ComponentWindow::run() into show(), hide() and sixtyfps::run_event_loop()
This allows creating multiple windows for example, and it will allow for
showing windows in those tests that require a mapped window.

As a bonus, the run() function on generated components is not consuming
anymore.
2021-01-19 09:50:22 +01:00
Simon Hausmann
2b7a1eebcd Prepare winit event loop for show()/hide() on PlatformWindow
Reduce the dependency of the GLRenderer to a new trait that exposes the
EventLoopTarget and EventLoopProxy. Those are provided by either an
winit::event_loop::EventLoop or, once the loop is started using the
self-consuming run(), by the event loop target provided to the run_fn.

This way renderers can be created from either within run or before.
The initial event loop instance is kept in TLS. When starting the loop,
it's taken out and instead the event loop target is placed into a scoped
tls variable.
2021-01-18 20:26:09 +01:00
Simon Hausmann
88839ea6a6 Fix panic during rendering with GL backend
During rendering the GLRenderer's Option<WindowedContext<NotCurrent>>
is None. That however leads to any font_metrics() calls such as due to
implicit sizing to panic, because the call requires access to the
window's scale factor.

This is fixed by keeping a shared reference to the PossiblyCurrent
WindowedContext also in the GLRenderer.
2021-01-18 20:26:09 +01:00
Simon Hausmann
003fdb2564 Fix property dependency chain for Image::implicit_size()
The GL backend uses the item graphics cache for the image size function,
which uses a PropertyTracker. That tracker must have the Image's source
included in its dependencies, to avoid that when loading a HTML image
for example, the cache isn't invalidated when the source is changed
before the HTML image was loaded async. That's why the get() call on the
source property must happen from within the PropertyTracker's callback.
2021-01-18 08:50:41 +01:00
Simon Hausmann
2b8a24dc3e Minor cleanup
For loading cached images the resource getter is called only once,
so we can require an FnOnce and avoid cloning the resource.
2021-01-16 12:40:34 +01:00
Simon Hausmann
94c1d884ba Allow specifying 0/0 as width/height of an image
With the support for a default binding to width/height on the implicit
size, we can now revert commit 42a5a62fb5.
2021-01-15 17:58:32 +01:00
Simon Hausmann
77b5a86168 Add an implicit size to text and image items
For all other items the default is the empty size.

This also required three fixes for the HTML image loading:

  * The upload_pending property value was inverted, it needs to start
    out as true (pending yes) and be set to false when it finished
    loading (not pending anymore)
  * Mark the upload_pending property as dirty before scheduling the
    redraw, in case it's sync
  * Pass the item rendering cache to the image_size function to ensure
    that the Rc<CachedImage> is not only weak inside the image_cache
    of the GLRendererData but also strong on the item.
2021-01-15 17:56:49 +01:00
Olivier Goffart
d65a655333 Fix Wasm build error and warnings 2021-01-15 15:23:17 +01:00
Olivier Goffart
f1ce103c7b WIP: start splitting Window and PLatformWindow 2021-01-15 15:02:55 +01:00
Simon Hausmann
76fbf46f23 Fix rendering of the memory puzzle with the GL backend
Femtovg only accepts certain image sources. A comment in the source
suggests that a conversion could be done but that it's an expensive
operation the user should decide if it's okay or not. For us it's
okay, so let's do it.

Similarly, avoid the potential ImageSource::try_from failure when
querying just for the size, as GenericImage view has the dimensions we
need.
2021-01-15 14:09:27 +01:00
Olivier Goffart
547b2a7f6e Introduce Backend trait
Such that the font are properly registered when the GL backend is chosen at runtime
2021-01-15 12:20:32 +01:00
Simon Hausmann
c8cd073d92 Add support for partial image loading
Allow images to be just decoded and uploaded to the GPU in a separate
step. This is in preparation to implicit size support, where the actual
dimension of the image can be determined by decoding it immediately when
needed and uploaded to the GPU later (when we can be sure to have a
current GL context).

For images loaded through HTMLImageElement this is trickier, in the
sense that - unlike when loading off disk - it is inherently async.
Therefore we use a Property<bool> that we toggle when loading is
complete, in order to mark any dependent bindings as dirty, after
reporting an initial (1, 1) size.
2021-01-15 10:02:36 +01:00
Simon Hausmann
4dcbe94bff Some GL renderer cleanup
Move data structures shared between the GLRenderer and the
GLItemRenderer into a *ka-ching* shared data structure. This reduces the
amount of separate Rc instances.

Also moving the image loading functions from GLItemRenderer to
GLRendererData will allow for re-use from the GLRenderer in the future.
2021-01-15 10:02:26 +01:00
Olivier Goffart
aa7f362f10 Actually remove the GraphicsBackend completely
It is not longer in used for the abstraction between backend,
we'll make a new trait for it later
2021-01-14 17:46:30 +01:00
Olivier Goffart
7931896027 GL: Remove the Backend generic in the GenericWindow 2021-01-14 17:33:12 +01:00
Olivier Goffart
fff024731b Don't pass Pin by reference
(consistant with other method in that trait)
2021-01-14 11:54:17 +01:00
Simon Hausmann
42a5a62fb5 Fix rendering of image elements without specified width/height
Fall back to the source image dimensions like the old renderer
2021-01-14 08:53:14 +01:00
Simon Hausmann
de67b865dc Implement basic font fallbacks for WASM and macOS
Our demos use some symbols such as the back arrow and the ugly style
uses a down arrow for the combo box. These symbols are not in Roboto and
also not in the default font font_kit gives us on macOS.

Therefore for WASM we switch over to DejaVu, which is bigger than
Roboto.

For macOS this patch implements rudimentary fallback list generation
using CTFontCopyDefaultCascadeListForLanguages. This needs further work
to respect the locale and correctly translate styles - eventually this
should go into font-kit.

A general aspect with the font fallback handling is that femtovg doesn't
support on-demand loading yet. Instead it uses owned_ttf_parser, so
every font will be read entirely off disk. That's why for macOS we trim
the list. We could perhaps do the analysis ourselves.

Linux and Windows are to follow.
2021-01-14 08:53:14 +01:00
Simon Hausmann
f4d3395f61 Prepare for font fallback lists
Separate GLFont from GLFontMetrics, the latter being as light as keeping
primarily the request around (and canvas), the former holding the list
of font resolution.
2021-01-14 08:53:14 +01:00
Olivier Goffart
fa3d26fea8 Make the fallback to GL when Qt is not available work 2021-01-14 08:53:14 +01:00
Simon Hausmann
653fa491d9 Fix sub-image rendering
* Fix passing the correct source clip rect (width and height were missing)
* Adjust to nanovg's image rendering model where the image is basically
  a patter underneath the path rendered. So for a sub-image
  we need to offset the image pattern and scale the pattern and the path.
2021-01-14 08:53:14 +01:00
Simon Hausmann
1c8ab9829c Minor cleanup in GLFont's paint creation 2021-01-14 08:53:14 +01:00
Simon Hausmann
b79e4180c8 Rename trait Font to trait FontMetrics
This name more closely resembles the functionality it provides.
2021-01-14 08:53:14 +01:00
Simon Hausmann
98162e6325 Implement image fitting
Based on the old renderer code
2021-01-14 08:53:13 +01:00
Simon Hausmann
6c24a98036 Unify image drawing functions 2021-01-14 08:53:13 +01:00
Simon Hausmann
30bc16db73 Avoid possible leaks when loading html images and then destroying the window
Keep weak references to the canvas, etc. for the DOM closure
2021-01-14 08:53:13 +01:00
Simon Hausmann
54ae1310af Add support for loading remote images for wasm builds 2021-01-14 08:53:13 +01:00
Simon Hausmann
3dba030243 Fix wasm build
This re-enables the wasm port through femtovg's wasm support. The Roboto
is included as a generic fallback font.
2021-01-14 08:53:13 +01:00
Olivier Goffart
10dffa7d79 Use the QPainter directly when using the Qt paint engine 2021-01-14 08:53:13 +01:00
Simon Hausmann
8c23155cae Implement text selection drawing 2021-01-14 08:53:13 +01:00
Simon Hausmann
cdfc36e881 Fix clicking into text input to place the cursor
Implement text_offset_for_x_position
2021-01-14 08:53:13 +01:00
Simon Hausmann
743bcc77f6 Render text inputs and cursors
The selection is still missing
2021-01-14 08:53:13 +01:00
Simon Hausmann
cb972402e7 Fix rendering of rectangles with large borders
Constrain the border width by the rectangle to avoid that the border
would cancel itself out when too big.

This fixes most of the checkbox rendering in the slide puzzle.
2021-01-14 08:53:13 +01:00
Simon Hausmann
35f51fe339 Clean up FontRequest interface
Represent a non-specified pixel size and font weight through a None option.

This is cleaner and has the added benefit that the backend can now
easily decide what the default size/weight should be.
2021-01-14 08:53:13 +01:00
Simon Hausmann
36c41ef758 Simplify font interface in the backend
For the GL backend a resolved font is just a handle (femtovg::FontId)
and we can cache that. Consequently we don't really need Rc<dyn Font>
but can let `fn font(...)` on the backend return a "resolved" font that
includes the pixel size, which in turn simplifies the Font trait
signatures.

The only caveat is that because on the item level we don't know what the
chosen backend type is, we can only receive a `dyn Font`, which means
it's wrapped - for now - in a Box.
2021-01-14 08:53:13 +01:00
Simon Hausmann
a684f36b8d Simplify children clip handling
Use a save/restore state pattern for the entire renderer instead of passing around clip rectangles as data structure.

That's less data copying and maps naturally to existing mechanisms,
which in turn can use their own dirty handling to make
save_state/restore_state as cheap as possible.
2021-01-14 08:53:13 +01:00