Commit graph

222 commits

Author SHA1 Message Date
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
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
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
Olivier Goffart
6d316185fc Fix Painting of native widget
the cx and cy needs to be the same as the widget position
2021-01-14 08:52:22 +01:00
Olivier Goffart
b157648ab2 More work towards getting native widget with the femtovg backend 2021-01-14 08:52:22 +01:00