Commit graph

31 commits

Author SHA1 Message Date
Olivier Goffart
1dba04721a Add a qt_viewer example that uses QWidget 2021-03-23 17:13:41 +01:00
Olivier Goffart
6f88d78303 Rename Resource to ImageReference in the runtime 2021-03-11 10:06:23 +01:00
Simon Hausmann
27bdb4d481 Added Window.default-font-family
One step towards getting rid of `DemoText` in the printer demo
2021-03-02 13:25:21 +01:00
Simon Hausmann
8a66af0746 Clean up image size determination in the rendering backend
Don't use the item's rendering cache to determine the image size, as
that's soley for rendering. The Qt backend doesn't use the item cache
and the GL backend neither after this change. Instead both backends have
a cache for decoded images.
2021-02-10 17:34:29 +01:00
Olivier Goffart
ec90d0c525 wasm: Resize the canvas to make sure it fits the window constraints 2021-02-09 09:41:01 +01:00
Olivier Goffart
9bdb793ec1 Rename Window::color to background 2021-02-05 09:38:40 +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
Olivier Goffart
2d7817e049 Rename GenericWindow -> PlatformWindow 2021-01-15 18:32:55 +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
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
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
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
Olivier Goffart
84c7b28256 Decouple the ItemRenderer from QPainter so it can hold a cache 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
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
1ed35fb628 Replace uses of FIELD_OFFSETS.foo.apply_pin(bar) with bar.foo() 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
76cee4a598 Fix some warnings about unused variables or imports 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