Commit graph

657 commits

Author SHA1 Message Date
Tobias Hunger
68259162c8 Janitor: Fix typo in local variable name
No behavior change is intended here.
2021-06-28 08:32:00 +02:00
Olivier Goffart
6ed58fb041 Testing backend: don't panic on popup close 2021-06-23 15:25:29 +02:00
Simon Hausmann
55d4a4f79e Bump femtovg to a released version 2021-06-22 18:06:43 +02:00
Olivier Goffart
dcbbd0cd7d Update dependencies 2021-06-22 11:15:20 +02:00
Simon Hausmann
930412d3bb Fix size of default constructed sixtyfps::Image with GL backend
An empty image should have a zero (empty) size, like it does with the
testing and Qt backend.

The datastructures test in the CI revealed this.
2021-06-20 11:18:28 +02:00
Simon Hausmann
0fdb87cc69 Add Image::size()
This requires the image size query to be window independent and go
through the backend instead.

This implies minor changes for the Qt backend and bigger ones for the GL
backend:

* There exists now a thread-local IMAGE_CACHE, which is used by the
  backend's image_size() function as well as by the renderer for
  loading CPU side images.
* The image remain as decoded images in there (including SVG tree)
  and the window now has a texture_cache, which holds CachedImage
  with ImageData::Texture.
* Rendering an image item therefore fetches the CPU side image,
  calls upload_to_gpu() on it, which creates a new Rc<CachedImage>
  and that's stored in the texture_cache.
* The texture cache continues to be pruned when hiding the window.
2021-06-20 11:18:28 +02:00
Olivier Goffart
c1a144c282 Layout height for width for the Text 2021-06-17 11:23:58 +02:00
Olivier Goffart
ce37cd2552 Rename a function to avoid confusion with a field 2021-06-16 15:14:07 +02:00
Olivier Goffart
deaa0fddb0 WIP layout: split vertical and horizontal cache
Split the vertical and horizontal pass into different property cache
This will allow to implement "height for with"

This patch does not port the Rust or C++ binding yet
2021-06-16 15:14:07 +02:00
Olivier Goffart
7f9bb18b9a Fix warning introduced in last commit 2021-06-10 11:18:35 +02:00
Olivier Goffart
9b8efbf5ad GL backend: Properly clip Text that has too many lines for its height
Qt already does that
2021-06-10 10:52:04 +02:00
Olivier Goffart
0d09f69fb9 Upgrade lyon_path version since the PR in lyon_path was merged.
This should help for #253
2021-06-06 09:37:32 +02:00
Simon Hausmann
5cad61bcd0 Fix disappearing text in vertical layouts with word-wrap and alignment
When a Text element has wrapping enabled, it should not have zero
minimum size. Otherwise the layout will give it a height of zero in the
layout in the test case and that'll make the text disappear. There are
different options but this patch goes for minimum height as if no
wrapping was enabled (so at least one line plus forced line breaks).

Fixes #246
2021-06-01 10:52:26 +02:00
Simon Hausmann
5b9ce15ae2 GL backend: Implement image_size getter without mapped window
By moving the image cache to the GraphicsWindow we can now decode images
first without a window and later upload to the GPU.

This also allows removing the window_map_pending property hack.
2021-06-01 08:29:39 +02:00
Simon Hausmann
c38696f652 GL backend: Prepare for image cache without window
The HTMLImage only needs the event loop proxy to notify for a repaint, we can repaint all windows.
2021-06-01 08:29:39 +02:00
Simon Hausmann
ad24802fed GL backend: Clean up HTML image loading code
Decouple the Texture from the HTML image loading logic and introduce an
ImageData state that represents just the DOM element.

This will make it possible later to also load the images without a canvas.
2021-06-01 08:29:39 +02:00
Simon Hausmann
3ef6f95659 GL backend: minor cleanup
Move the image cache key also into the images module
2021-06-01 08:29:39 +02:00
Simon Hausmann
4a13bba32a Clean up GL resource handling
Make sure that we have a current GL context before deleting textures or other GL resources
2021-06-01 08:29:39 +02:00
Simon Hausmann
6fa6b28661 Simplify GL context handling further
Move the borrow/option business to work around the glutin enum API into
the OpenGLContext type, to simplify its use.
2021-06-01 08:29:39 +02:00
Simon Hausmann
e1be835942 Simplify wasm event loop invocation
We don't need the scoped_tls_hkt trick anymore
2021-05-31 18:03:23 +02:00
Simon Hausmann
357dd9826d Fix HTML images not being rendered after being loaded
Instead a "manual" refresh is needed (like mouse mover). This regressed
in commit 8d2554ff3b, which removed the
event loop proxy clone. For some reason that's not sending the event
from the DOM callback, but winit requires a clone of the proxy.
2021-05-31 12:56:35 +02:00
Olivier Goffart
32b92aba08 Fix the viewer and LSP preview when they reload the widow breaking the layout
the must_resize was not set to true when the with and height are set to the prefered
size, but it must be set for the layout to apply.

Note that even with this patch, the window will be resized to the preferred
size when reloading. Because we have no way to know there if this is the first time
the window is shown, or not.
2021-05-31 09:43:09 +02:00
Simon Hausmann
949dc9612b Use the new 0.2.0 release of femtovg 2021-05-28 20:26:37 +02:00
Simon Hausmann
f9df83d593 Fix initial rendering of widget gallery with GL backend
This issue is not quite specific to the gallery, a simpler test case is
this:

```
App := Window {
    preferred-width: 500px;
    preferred-height: 750px;
    HorizontalLayout {
        Rectangle {
            background: blue;
        }
    }
}
```

As there is no fixed width/height set, the size is calculated by layout and
apply_window_properties() sets the inner size correctly on the winit window.
However the width/height properties on the root Window item are not set, remain
zero and thus lead to incorrect rendering. They are not set because they are
identical with what window.inner_size() reports - we assume no change and that
they are in sync.

The bug however is in the creation phase, when we decide on an initial size to
pass to the window_builder, we should also set those on the root item. This is
where window.inner_size() and the root item's width/height get out of sync.
2021-05-28 17:54:30 +02:00
Olivier Goffart
142a8dc185 Rename ImageReference to ImageInner and make Immage.0 private 2021-05-28 17:05:16 +02:00
Olivier Goffart
0b3fecf300 WIP: API to expose image loading from C++ and Rust 2021-05-28 17:05:16 +02:00
Olivier Goffart
4584c40544 Rename items::Image to ImageItem
Because there will be soon a sixtyfps::Image and the names
can't clash
2021-05-28 17:05:16 +02:00
Olivier Goffart
24a3d868ef Avoid compiling image format we don't need 2021-05-28 15:03:45 +02:00
Simon Hausmann
d4385280eb Fix disappearing images or panics when hiding and showing a window with wayland
Properly release GL resource when unmapping a window and detect stale
cache indices using a generation count. This fixes the disappearing
images (GL textures would be invalid and need to be re-created) as well
as the panics when an item's cache index ended up being re-used because
some other item was drawn first and allocated that indices. The latter
is fixed by using a generational counter on the cache that's bumped when
clearing, instead of a single "cache_ok" bool.
2021-05-28 09:16:24 +02:00
Simon Hausmann
9503ba69b3 GL backend: Move all font related code into the fonts module 2021-05-27 18:51:32 +02:00
Simon Hausmann
7ddbfbdd64 Clean up font_metrics interface on corelib:🪟:Window
Since the GL backend can't really fail on this anymore we can now
remove the Option from the return value.
2021-05-27 17:04:45 +02:00
Simon Hausmann
9b02f2e4a2 GL backend: provide font metrics even when the window is not mapped
Move the item graphics cache into the GraphicsWindow and then, together
with the new femtovg::TextContext, we can provide the metrics and can
stop using the window_map_pending notifier for this query.
2021-05-27 17:00:44 +02:00
Simon Hausmann
61a5859d70 Further encapsulate also the context creation in OpenGLContext 2021-05-27 15:55:38 +02:00
Simon Hausmann
3723aa6f42 Encapsulate the winit WindowContext and wasm winit::Window handling
With wasm there is no current context (can alwasy render) but we own the
winit::Window. With glutin own the ContextWrapper and have to make it
current (and resize). This patch hides all that behind the OpenGLContext
type.
2021-05-27 15:53:33 +02:00
Simon Hausmann
77a064ecab Simplify glutin GL context resizing slightly
Move the resize call into make_current, in preparation for additional
encapsulation in that type.
2021-05-27 15:52:54 +02:00
Simon Hausmann
4a0a9f8a2c Make the font cache thread local 2021-05-27 15:52:54 +02:00
Simon Hausmann
e3264f02d7 Switch to femtovg's TextContext API
This is primarly search & replace for now, slightly simplifying function
signatures.
However this paves the way to a thread-local font cache that can share
fonts across windows (not glyph atlas) and also measure without a canvas.
2021-05-27 15:52:54 +02:00
Simon Hausmann
6d65236813 GL backend: simplify window factory function signature
We can retrieve the event loop window target from anywhere
2021-05-27 15:49:33 +02:00
Simon Hausmann
8d2554ff3b Remove internal event loop proxy clone in the GL renderer
We don't need it since we can send events through the TLS
2021-05-27 15:45:29 +02:00
Simon Hausmann
4b98e05a8f Fix broken layout in web version of gallery
When we calculate the initial layout without a mapped window early on,
we end up with zero text metrics with the GL backend due to an API
limitation of femtovg.

While working on that, this patch introduces a workaround to mark the callers of
image_size() and font_metrics() as dirty when the window is mapped.
2021-05-25 18:37:53 +02:00
Simon Hausmann
7acbe93bf1 Adjust the pin of femtovg
The blur is now in master, so use that instead until release.
2021-05-25 11:32:46 +02:00
Olivier Goffart
74418db9ad Try to create the window with a proper size already
CC #235
2021-05-21 18:43:41 +02:00
Simon Hausmann
655aff24e4 Fix CI
Remove trailing whitespace to silence cargo fmt
2021-05-21 17:52:29 +02:00
Simon Hausmann
431c433e8b Clean up blur effect C++ code
Use Olivier's advice and use the more modern using declaration to access
the draw function, locally.
2021-05-21 17:33:21 +02:00
Simon Hausmann
1d92ab4d36 Simplify Qt blur effect application slightly
Call draw on the blur effect directly instead of going through QGraphicsScene::render().
2021-05-21 17:33:21 +02:00
Simon Hausmann
27dcfa0f11 Improved rendering of drop shadow for Qt
Use QGraphicsBlurEffect as public API to take the blur into account
2021-05-21 17:33:21 +02:00
Olivier Goffart
1f46fd05ec Allow the qt_viewer to compile if cmake finds qt, but not qttypes
This can happen when setting the SIXTYFPS_NO_QT env variable

cc #232
2021-05-21 07:45:38 +02:00
Olivier Goffart
7f117829f2 Display a warning if Qt is older than 5.15
cc #232
2021-05-20 18:28:52 +02:00
Simon Hausmann
235e102f31 Fix slide puzzle not showing with the Qt backend
The window in .60 in the slide puzzle has no preferred size set. Therefore fall back to QWidget::sizeHint().
2021-05-20 18:19:20 +02:00
Olivier Goffart
6540fd48ae GL backend: set the proper size on the rendering context
Otherwise we draw garbage with wayland
2021-05-20 15:19:33 +02:00