Commit graph

692 commits

Author SHA1 Message Date
Simon Hausmann
d26b7f9428 Skia: fix height of empty text lines
Apply the text style with font, etc. as default on the paragraph style, so that it applies to empty lines.

cc #1480
2022-09-22 09:56:53 +02:00
Simon Hausmann
743a980e21 Skia: add support for rendering text selections
cc #1480
2022-09-22 09:04:27 +02:00
Simon Hausmann
74d3bf07e7 Skia: Fix text cursor at end of text and in empty text inputs
At end of text, take the right edge of the glyph cluster; otherwise the left edge
of what's to the right of the cursor.

For empty text inputs, just return the height of the text to be.

cc #1480
2022-09-22 09:04:27 +02:00
Simon Hausmann
ea73253d16 Fix panic in online editor when resizing the preview widget
A resize of the HTML canvas element would trigger our own resize
handler, which tried to do a special dance to trigger a redraw.

As it turns out, this breaks with current winit as the event loop target
is gone, so calling with_window_target() panics.

See also commit 8b728df021

Instead, this patch reverts to the simpler method of calling
invoke_from_event_loop, has workarounds for how to properly wake up the
event loop and return poll. In there we can just call request_redraw()
on the winit window directly to trigger a draw.
2022-09-20 10:12:39 +02:00
ogoffart
261614b914 Bump version number to 0.3.1 2022-09-15 14:39:51 +02:00
Simon Hausmann
dba137e3ba
Rename RequestedSize to WindowSize and RequestedPosition to WindowPosition (#1640) 2022-09-14 12:59:53 +02:00
Olivier Goffart
4b0af4bea3 Skia: fix the cursor computations
Skia understands glyph offsets, not byte offsets, so the conversion must
be made
2022-09-13 15:37:53 +02:00
Olivier Goffart
e17d07fbc8 winit: Set the icon from the builder
Also simplify the code that sets the property to the builder
2022-09-13 13:39:09 +02:00
Olivier Goffart
8aeea6d8df
Winit: fix entering of character containing dead key (#1628)
The regression happened when upgrading winit as they added support for IME
2022-09-13 13:38:41 +02:00
Tobias Hunger
53a3c72b57
api: Change logical/physical position and size on window (#1620)
* Add `RequestedSize` and `RequestedPosition` enum to enable asking for
  logical or physical size/position.
* Rename `Window::size()` to `Window::physical_size()`
* Make `Window::set_size(...)` take an `Into<RequestedSize>`
* Rename `Window::position()` to `Window::physical_position()`
* Make `Window::set_position(...)` take an `Into<RequestedPosition>`
* Change `WindowAdapter` and related classes to be able to handle
  requests being made in the either physical or logical units.

Implement this for C++, Rust and node.
2022-09-13 08:55:31 +02:00
Olivier Goffart
911515bfd0 Fix the initial window size when the height depends on the width
We need to assign the width beofre computing the preferred height
otherwise zero or very small value can be assumed and it will case the
text engine return a huge preferred height.

Testcase:

```
export App := Window {
  VerticalLayout {
    padding: -10px;
    Text {
        text: "Lots of text with\nnewlines etc.\n lorem ipsum dolor sit amet";
        wrap: word-wrap;
    }
  }
}
```

In particular, this fixes the gallery window size being too high when
using the skia renderer, because when given a zero width, skia return
a big size for the height, (contrary to the Qt backend that consider 0
as infinite, or the femtovg backend that will stop rendering once a line
can't fit)

Replaces #1621
2022-09-12 12:12:18 +02:00
Simon Hausmann
2a26be5c94 WIP: Skia: Begin with support for text input
This puts the basics in place for text input. There are a few missing pieces (and probably more not yet discovered):

* Selections are not rendered yet.
* The cursor is not show at end of text.
* Cursor up and down doesn't work correctly in preserving the x position.

cc #1480
2022-09-12 11:26:49 +02:00
Simon Hausmann
22f21f16a4 Move the trick to return Poll when request_redraw() is called during draw() straight into the event loop handler 2022-09-08 11:35:34 +02:00
Simon Hausmann
372e6b0ffc winit: Work around request_redraw() not always resulting in a Event::RedrawRequested
The old workaround doesn't work anymore (commit
575665994a removed the
redraw_all_windows() but that was correct as well). Instead we take an
approach that is hopefully more idiomatic to winit:

The winit documention suggests two methods: For continuously repainting
windows, we can just draw in MainEventsCleared. Otherwise call
request_redraw() and wait for Event::RedrawRequested(id).

In practice sometimes a call to request_redraw() from within the input
event processing results right away in a Event::RedrawRequested
(observed on Windows). Sometimes a request_redraw() results in waking up
with NewEvents() but no Event::RedrawRequested, and then in the next
iteration a new request_redraw() is included (observed on Windows).

We will continue to issue request_redraw() but for any windows that
haven't received Event::RedrawRequested() we will just draw. This still
allows the windowing system to compress / combine paint events.

If during draw() request_redraw() is called, we assume that the
application wants to redraw ASAP and we fall back to Poll. This was
previously the workaround in corelib that's now only in the winit code.

Fixes #1574
2022-09-08 11:35:34 +02:00
Simon Hausmann
4095622303 Clean up internal WinitWindow trait
Since event_loop.rs is not shared anymore between the winit backend and
the "mcu" backend, we can reduce the WinitWindow trait to the features
that are needed for the event loop code to store it as trait object.
2022-09-08 08:56:17 +02:00
Olivier Goffart
8850959a2c Rename the backend feature flags 2022-09-07 17:11:57 +02:00
Olivier Goffart
e708f5c903 femtovg backend: fix the cursor position when the text ends with '\n'
Fixes #1318
2022-09-07 15:25:13 +02:00
Simon Hausmann
9e1bb1044c Clean up from-event-loop callback handling
Join wrapping call site and implementation.
2022-09-07 12:03:37 +02:00
Simon Hausmann
8b728df021 Don't panic when calling hide() and request_window_properties_update() on the wasm interpreter generated instance
Similar to commit 0fe29cd196 we need
to wrap access to the event loop :(

hide() is directly exposed in public API,
request_window_properties_update() will be called from outside the event
loop when we expose create_with_existing_window() for the interpeter to
re-use the canvas (which calls set_component on the window).
2022-09-07 12:03:37 +02:00
Olivier Goffart
b2c1d89e2f Fix compile when only the renderer-software is enabled 2022-09-07 11:06:51 +02:00
Simon Hausmann
b78b6ab723 Fix non-SVG images with transparency being rendered incorrectly in WASM builds
Commit 05b16bed89 introduced an exception
for SVGs images to treat them as premultiplied, but commit
3ef35c5ef9 accidentally applied the flag
to all HTML images, which is wrong.
2022-09-07 10:15:27 +02:00
Olivier Goffart
b3605cb4ec Fix errors and warnings in the wasm build 2022-09-07 10:13:58 +02:00
Olivier Goffart
6ede77436b api: Return an error from invoke_from_event_loop and quit_event_loop 2022-09-07 10:13:58 +02:00
Tobias Hunger
d880ef8eb5 api: Remove software-renderer feature 2022-09-07 10:11:11 +02:00
Tobias Hunger
639dcaf702 api: Rename module swrenderer to software_renderer
Also rename the `swrenderer` feature to `software-renderer`.
2022-09-07 10:11:11 +02:00
Simon Hausmann
6b2968c067 janitor: fix warning in wasm build
Remove unnecessary parentheses as suggested by the compiler.
2022-09-07 09:01:59 +02:00
Olivier Goffart
4706d529e2 Rename BUFFER_COUNT to MAX_BUFFER_AGE
and remove the default value from the SoftwareRenderer
2022-09-06 18:30:45 +02:00
Simon Hausmann
7967bf1ab0 Replace the internal WindowHandleAccess trait with a helper function on WindowInner
The reversal of ownership removes the need for the glue trait in the
publicly visible API.
2022-09-06 16:17:06 +02:00
Olivier Goffart
594131a7ea winit: Enforce the min/max size in the WindowBuilder and set size again for wasm
In previous version, we were setting the constraint with wasm after
the window was shown, but this is no longer the case because we delay
the window creation by an iteration of the event loop.
Now should apply the constraint before showing the window.

But on wasm, we also must manually enforce these constraint because the
size given to the WindowBuilder is not applied
2022-09-06 14:23:58 +02:00
ogoffart
05a49da906 Bump version number to 0.3.0 2022-09-06 13:00:22 +02:00
Simon Hausmann
5fe212f459 Make sure that skia_backend_opengl is always set on Linux 2022-09-05 14:07:27 +02:00
Simon Hausmann
3a1817de3f Skia: Make it possible to explicitly select the OpenGL backend of Skia
When opting into the Skia renderer, we default to metal on macOS and D3D on Windows.
However if you want to develop a cross-platform application with Skia and
for example rely on OpenGL to be able to implement an OpenGL underlay or overlay,
then we need the ability to explicitly opt into skia's GL renderer.

cc #1445
2022-09-05 14:07:27 +02:00
Simon Hausmann
3ebdb1b86d Add debug info about the Skia back buffer color depths
Include the number of bits per pixel in the existing output
2022-09-05 13:53:04 +02:00
Simon Hausmann
7323e0b93d Bump Skia version to 0.54
This release upgrades to Skia milestone 105 and  includes binaries for
the new windows-textlayout-d3d-opengl configuration that is available as
opt-in.
2022-09-05 11:27:30 +02:00
Olivier Goffart
3f1324cc61 Allow to run the software backend without the femtovg backend 2022-09-02 16:38:35 +02:00
Simon Hausmann
7e5de3d5d3 Remove use of euclid types and tags for logical/physical position and size in the public API
Instead provide our own types.
2022-09-02 11:05:53 +02:00
Simon Hausmann
85461d380d Remove euclid from the public re-export of the Slint crate 2022-09-02 11:05:53 +02:00
Olivier Goffart
e0f1fdf298 Rgb565Pixel: remove color accessor, add conversion to Rgb8Pixel
Closes #1540

(Went or Rgb8Pixel instead of color, because color can have alpha)
2022-09-01 13:58:38 +02:00
Olivier Goffart
fcca38e0f6 Rename set_event_loop_quit_on_last_window_closed to remove EventLoopQuitBehavior
For the winit backend, also make the function work after a call to run()
2022-09-01 12:08:05 +02:00
Simon Hausmann
c1dbf47d15 Fix appearance of drop shadows with Skia
Similar to commit 957186acb7 we need to take the blur into account in the box shadow image:

We add blur margins around the entire image, but we also need to start drawing at (blur, blur) instead of (0, 0).
The same offset needs to be subtracted again when drawing the cached image.
2022-08-31 11:36:04 +02:00
Simon Hausmann
7fd0af8b63 Fix box shadow not rendering correctly when using scale factors != 1
Despite the blur being an abstract float, in reality in femtovg as well
as Skia it's a pixel radius. Commit
1a8a295e38 removed the scaling to physical
pixels, which was wrong.  This restores it and along with it the same
appearance as before.
2022-08-31 11:36:04 +02:00
Simon Hausmann
9338d31535 Remove the use of euclid types from the software renderer public API
Closes #1538
2022-08-31 09:23:38 +02:00
Olivier Goffart
b9c2dec922 API: seal the WindowAdaptor trait
And hide most of its functions in the sealed trait.
2022-08-30 22:21:24 +02:00
Simon Hausmann
0fe29cd196 Fix preview in online editor not updating when making changes
Creating a new window requires access to an event loop instance. The
winit upgrade prevents us from creating multiple EventLoop instances.
Therefore we have to re-use the existing event loop instance, which is
only accessible from within the event handler.
2022-08-30 16:56:27 +02:00
Tobias Hunger
3430a13bf8 API cleanup: Remove quit behavior parameter from run_event_loop 2022-08-30 08:34:45 +02:00
Tobias Hunger
38350db9a0 Fixes pointed out by Olivier and CI 2022-08-29 16:53:47 +02:00
Tobias Hunger
107e3ed2e2 janitor: Fix some typos 2022-08-29 16:53:47 +02:00
Tobias Hunger
88cf874d03 API cleanup: Rename create_window to create_window_adapter 2022-08-29 16:53:47 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Olivier Goffart
344f5c437b swrenderer: Move the DirtyTracking enum into a const generic
Closes: 1541
2022-08-29 14:13:55 +02:00