Commit graph

946 commits

Author SHA1 Message Date
Olivier Goffart
46dbb1ee9e By default, enable the GL backend also on desktop
So it can be chosen with an env variable or if Qt is not available
2021-01-14 08:53:13 +01:00
Olivier Goffart
58904f1858 Revert "Switch to a released version of femtovg"
This reverts commit cce8fb8c3863eb9b734e0a6755ebec9fd72dc895.

The version 0.1.0 of femtovg brings an old version of harfbuzz_rs
which brings a conflicting version of freetype with font-kit
2021-01-14 08:53:13 +01:00
Simon Hausmann
930ef429ef Removed unused crate dependencies 2021-01-14 08:53:13 +01:00
Simon Hausmann
66a34cede9 Switch to a released version of femtovg
Only the wasm build will require a git version for now, which we'll patch.
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
Olivier Goffart
7bd1fb9ec8 Silence warning 2021-01-14 08:53:13 +01:00
Olivier Goffart
1ea522a7d0 Qt backend: Make the animation not take 100% CPU 2021-01-14 08:53:13 +01:00
Olivier Goffart
7dfc43977f Qt backend: animations 2021-01-14 08:53:13 +01:00
Olivier Goffart
118d40d9e9 QtBackend: Timer 2021-01-14 08:53:13 +01:00
Olivier Goffart
7b4c600a4f Fix compilation after rebase 2021-01-14 08:53:13 +01:00
Olivier Goffart
d4c357195d Qt backend: make clicking on a TextInput not panic 2021-01-14 08:53:13 +01:00
Olivier Goffart
1eac260d99 Qt Backend: font size fixes 2021-01-14 08:53:13 +01:00
Olivier Goffart
d71bb9ab84 Qt backend: Image rendering 2021-01-14 08:53:13 +01:00
Olivier Goffart
49c9881d10 fix compile 2021-01-14 08:53:13 +01:00
Olivier Goffart
7d91651b48 Qt backend: input events 2021-01-14 08:53:13 +01:00
Olivier Goffart
4aa9faf532 Qt backend: border rectangle 2021-01-14 08:53:13 +01:00
Olivier Goffart
aeb67fa927 Qt backend: Resize event and layouting 2021-01-14 08:53:13 +01:00
Olivier Goffart
531ff42973 WIP: Qt backend using Qt 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
Simon Hausmann
4aea74358c Improve rendering of rectangle borders
The border should extend to the inside of the rectangle,
like in CSS.
2021-01-14 08:53:13 +01:00
Simon Hausmann
fa15accbbd Load images referenced by multiple items only once
Re-apply the caching mechanism from the old renderer
that keeps weak references and drains them after frame rendering.

This fixes switching between the themes in the slide puzzle.
2021-01-14 08:53:13 +01:00
Simon Hausmann
edb17f996f Move the entire custom application font handling into the backend
Some backends may not require a copy of the data, for example.
2021-01-14 08:53:13 +01:00
Simon Hausmann
1ed35fb628 Replace uses of FIELD_OFFSETS.foo.apply_pin(bar) with bar.foo() 2021-01-14 08:53:13 +01:00
Simon Hausmann
65dcb2cb33 Merge BuiltinItem and GeneratePropertyAccessors derive macros
... into the new SixtyFPSElement macro. This generates getters for all properties.
2021-01-14 08:53:13 +01:00
Simon Hausmann
a48f4253a2 Minor cleanup in draw_text
Create the font request on the text item side to reduce duplication and
remove the fallback logic from the font_weight accessor, in preparation
for automatic generation of that getter.
2021-01-14 08:53:13 +01:00
Simon Hausmann
a02186df22 Add support for application fonts
Needed to run the sliding puzzle demo
2021-01-14 08:53:13 +01:00
Olivier Goffart
0522b04d70 Rename create_gl_window to create_window 2021-01-14 08:53:13 +01:00
Simon Hausmann
cd915ddbe0 More vertical text alignment fixes - makes the printer demo look better
* When calculating the height of text for vertical alignment purposes,
  don't use the minimum height but stick to ascent + descent - like the old
  renderer. This gives Text items a constant height that depends on the
  font size and not the content.
* Avoid scaling text metrics twice. It turns out that femtovg uses the
  device pixel ratio / dpi argument for `set_size` only for scaling text
  metrics. Since we do all the mapping from logical pixels to physical pixels
  it's correct to let femto only operate in physical pixel range. As a bonus
  this allows removing the refresh_window_scale_factor() dance in the
  backend (including making the context current, etc.)
2021-01-14 08:53:13 +01:00
Simon Hausmann
b61c1e3af7 Fix baseline for text items
In the previous renderer the text, by default, is drawn at the top of the
bounding box. The default femtovg alignment is more like QPainter, but
that's not quite what we want here.
2021-01-14 08:53:13 +01:00
Simon Hausmann
065d717814 Fix missing rectangle border rendering 2021-01-14 08:53:13 +01:00
Simon Hausmann
76cee4a598 Fix some warnings about unused variables or imports 2021-01-14 08:53:13 +01:00
Simon Hausmann
9d7e151cb9 Simplify property access code in the renderer
Generate convenient property accessors using a derive macro
2021-01-14 08:53:13 +01:00
Olivier Goffart
9ef1c36a52 Move the eventloop module to the backend 2021-01-14 08:53:13 +01:00
Olivier Goffart
ab08502c77 Move the GraphicsWindow to the graphics backend 2021-01-14 08:53:13 +01:00
Simon Hausmann
41910f6694 Remove HasFont trait
This was only used for syntactic sugar which, as it turns out,
we can also have with a regular associated function that takes
Pin<&Self> \o/
2021-01-14 08:53:13 +01:00
Simon Hausmann
727c9a19f7 Add basic text item support
This needs more work, but gets something onto the screen at least.
2021-01-14 08:53:13 +01:00
Olivier Goffart
9050c29305 Don't use the window through the eventloop module 2021-01-14 08:53:13 +01:00
Olivier Goffart
c7ff67d0fc Move the ItemRenderer to the item_rendering module 2021-01-14 08:52:22 +01:00
Simon Hausmann
769ad146e7 Preparation for text handling
Ensure the dpi on the canvas is up-to-date before/after rendering, as
measure_text etc. rely on it and it's otherwise initialized to 1 by
default. Unfortunately this requires jumping through some hoops, but
that can be fixed later in the canvas.
2021-01-14 08:52:22 +01:00
Simon Hausmann
5906f39a47 Silence some warnings 2021-01-14 08:52:22 +01:00
Simon Hausmann
c74c8592a0 Minor simplification of new_renderer trait function
It's not necesary to pass the window dimensions when the renderer owns
the window.
2021-01-14 08:52:22 +01:00
Simon Hausmann
de4194c9ba Make ItemRenderer take &mut again
It's cleaner and indeed possible
2021-01-14 08:52:22 +01:00
Olivier Goffart
16a1b7b2bd Cache the pixmap in the native style 2021-01-14 08:52:22 +01:00
Simon Hausmann
43127cb059 Implement releasing of textures when items are destroyed
This means going back to an immutable renderer reference and interior
mutability for the canvas and the gpu cache. This is because while
traversing the item tree for rendering we may end up destroying
other items due to the lazyness of the models.
2021-01-14 08:52:22 +01:00
Simon Hausmann
1f9ba94c59 Rename the image cache
... to a more general gpu_cache and store an enum. That way we can
encapsulate the resource releasing - in the future - entirely in the
backend through run-time polymorphism in the backend (gpu cache data
enum) instead of a vtable method in the item to destruct the correct
type of data.
2021-01-14 08:52:22 +01:00