Commit graph

328 commits

Author SHA1 Message Date
Simon Hausmann
1f091cb1c0 Rename Rectangle.color to Rectangle.background
Add support for built-in property aliases and rename `color` to
`background` - in preparation for it also changing to type brush.

Right now the alias is silent, a deprecation and overall change
will come in a subsequent change.
2021-02-02 17:01:12 +01:00
Simon Hausmann
69508575ec Fix rendering of Flickable
It should clip to its geometry
2021-02-01 15:35:36 +01:00
Simon Hausmann
08413212f9 Improve rendering of circles with the GL backend
Rendering a circle using `rounded_rect` will create a path with `LineTo`
verbs for the edges. Unfortunately those create visible artefacts,
especially in lower resolutions.

Therefore this patch attempts to detect this scenario and draw a circle instead.

Fixes #152
2021-02-01 12:50:26 +01:00
Simon Hausmann
5df6c99f4f Improve application font support for WASM and simplify font handling
We can use fontdb on all platforms, which gives consistent font query
behavior of application fonts. And then we also don't need our hand-made
"db" anymore for the wasm build and the included DejaVu font.
2021-01-28 21:47:52 +01:00
Simon Hausmann
615ead0db0 Include SVG support also in the wasm build
This disables text in SVG, but that's not really working yet anyway
because it needs to be connected to the font selection SixtyFPS uses.
2021-01-28 21:24:07 +01:00
Simon Hausmann
e387d72421 Fix rendering artifacts with the GL backend in the memory tutorial
When a tile is open artifacts would be visible around the edge of the
tile. That's because a zero width rectangle would cause pixels to appear
with femtovg. The Qt backend however has an early abort in
`get_geometry!`.

This patches applies the same early-abort semantics to both backends and
switches to `<= 0`, corresponding to euclid::Size's `is_empty()`.
2021-01-28 17:57:35 +01:00
Olivier Goffart
fea2478859 Update version number everywhere 2021-01-28 16:34:13 +01:00
Olivier Goffart
61ea404faa Disable default feature of dependent libs 2021-01-27 18:14:38 +01:00
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
4df0334ed2 Fix regular key press event handling with winit
With commit

    9ca87ab312

and

    c62b0e5316

the winit event loop sends our KeyPress for
winit::event::WindowEvent::KeyboardInput only when the virtual key code
matches our specially encoded keys. For regular keys we rely on
winit::event::WindowEvent::ReceivedCharacter, for which we sent only
KeyRelease (which TextInput listens for), but not KeyPressed. With
this patch we simulate press & release.
2021-01-23 10:11:57 +01:00
Simon Hausmann
2d5f5fb821 Fix copy & paste shortcuts with Qt
* Rename logo to the more generic meta as keyboard modifier.
* Use control as the real modifier and map command key to it with
  winit and keep Qt semantics as-is.
2021-01-22 17:06:35 +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
Simon Hausmann
c62b0e5316 Fix copy & paste with the GL backend
We rely on ReceivedCharacter to send the event to the item for
combinations like Ctrl+C, instead of the single KeyEvent from winit. We
use the latter only for special key codes.
2021-01-22 15:18:38 +01:00
Simon Hausmann
d022dc1293 Make KeyEvent a struct
This way it's easier to expose to .60
2021-01-22 13:47:52 +01:00
Simon Hausmann
ae1178dd55 Make the modifiers simple booleans in the key event
This will give a nicer API to expose to .60. If the struct weren't
repr(C) then the booleans would be nicely packed, but alas that's not
happening. On the other hand we're not keeping many instances of them
around.
2021-01-22 13:47:52 +01:00
Simon Hausmann
886dd425fc Rename KeyEvent::KeyPress::string to text
It's the textual representation of the key
2021-01-22 13:47:52 +01:00
Simon Hausmann
44687bd219 Fix wasm build 2021-01-22 10:25:26 +01:00
Simon Hausmann
22749d4240 Remove the winit dependency from corelib
The last dependency were the keyboard modifiers, which we can map
manually.
2021-01-22 10:15:05 +01:00
Simon Hausmann
9ca87ab312 Simplify KeyEvent
Fold CharacterInput into KeyPressed/KeyReleased and store the "key" as a string.

Also, instead of exposing the KeyCode we're encoding special characters
into the string.
2021-01-22 10:15:05 +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
2bd1f75aeb Minor cleanup
We don't need to borrow_mut() to call a function that takes &self.
2021-01-16 12:41:30 +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
Olivier Goffart
2d7817e049 Rename GenericWindow -> PlatformWindow 2021-01-15 18:32:55 +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
f397e08abc Also update neon 2021-01-15 16:04:14 +01:00
Olivier Goffart
d65a655333 Fix Wasm build error and warnings 2021-01-15 15:23:17 +01:00
Olivier Goffart
cb0a21115f Remove set_width/height from GenericWindow trait 2021-01-15 15:12:12 +01:00
Olivier Goffart
dcb347fb7b Move more functions from the GenericWindow to the Window 2021-01-15 15:02:55 +01:00
Olivier Goffart
0ab60dff81 continue Window refactoring. Remove a few function from GenericWindow 2021-01-15 15:02:55 +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