Commit graph

946 commits

Author SHA1 Message Date
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
Olivier Goffart
fb690dc815 Fix infinite resize in Gnome (wayland)
The gnome compositor don't like when we resize the window while it
is being resized by the user

Fixes #226
2021-05-20 13:41:26 +02:00
Simon Hausmann
a7ce64657c Restore source compatibility for drop-shadow-blur
Let's keep source compatibility and define `drop-shadow-blur` to be a radius.
The CSS spec says that the standard deviation is half of the radius.

We just need to scale again and increase the shadow rect to make sure that no borders are visible.
2021-05-20 12:14:05 +02:00
Simon Hausmann
2ba883b8e2 Fix WebGL demos
Commit bb7b301b10 pulled in a branch of femtovg, which
had a change to its shader that used a variable in the loop condition.
That is unfortunately not supported in WebGL 1.0 / GLES 2.0.

The pinned femtovg works around that limitation.

Fixes #230
2021-05-20 09:39:28 +02:00
Simon Hausmann
9a4dc4a8dc Clean up femtovg crate dependencies
Let only the GL backend depend on femtovg, by moving the color functions.
This way it's easier to change the femtovg version in one place.
2021-05-20 08:56:11 +02:00
Simon Hausmann
bb7b301b10 GL backend: new box drop shadow implementation
This replaces the box gradient with a new implementation that
behaves like the HTML Canvas element, by applying a gaussian
blur to the alpha of the rectangle to shadow.

The drop-shadow-blur property is changed to be now just a "level", like
the HTML Canvas shadowBlur property, which is defined to be half of the
standard deviation of the gaussian blur to be applied.
2021-05-20 08:50:02 +02:00
Olivier Goffart
3983e47720 Fix initial window size 2021-05-18 16:55:07 +02:00
Olivier Goffart
fbdbe69fe7 Window: make hight and width fixed size, preferred-* property set the initial size
Issue #227
2021-05-18 10:23:06 +02:00
Olivier Goffart
987f4666b8 Fix Qt6 build 2021-05-14 14:02:43 +02:00
Simon Hausmann
5b9d64b26e Fix failing assert in QFont with the printer demo
We use a weight of 900 in the demo, which results in a QFont::Weight of 100.
Unfortunately QFont::setWeight() doesn't cap itself, but brutally asserts
if the value is > 99. So let's cap ourselves.
2021-05-14 09:25:47 +02:00
Simon Hausmann
290759cf16 Fix Qt build
Amends ea358d9b2c
2021-05-12 22:06:39 +02:00
Simon Hausmann
ea358d9b2c Simplify internal image_size API
We don't need a property reference anymore, a plain image reference is fine AFAICS.

Dirtyness of the source is tracked on the caller side of layouting_info()
or in the draw_image_impl anyway.
2021-05-12 19:40:09 +02:00