Commit graph

668 commits

Author SHA1 Message Date
Simon Hausmann
54934d1f0b Fix the cursor position when receiving composition update events
Since the DOM API doesn't provide the values, we can just place the
cursor ourselves.
2022-10-20 12:37:28 +02:00
Olivier Goffart
f3f34c3a02 wasm: Use the composition API
Pros: the composition shows up as selected
Cons: te cursor is shown at the begining of the preselection, and
clicking on the field commit the selection at the wrong place
2022-10-20 12:37:28 +02:00
Olivier Goffart
bbc5ce4375 Fix mcu build 2022-10-19 15:23:41 +02:00
Olivier Goffart
6ee932883a Rename stark-style to dark-color-scheme
That's the term used by CSS
2022-10-19 15:23:41 +02:00
Olivier Goffart
0ba468c236 Use a builtin function to access the dark-style
instead of a property on NativeStyleMetrics
2022-10-19 15:23:41 +02:00
Olivier Goffart
eb879a80b5 Ensure that the Qt's NativeStyleMetrics don't crash when called from different threads
The test system may run tests in threads using the fluent style and the
testing backend.  But because the Qt backend is compiled in, the
NativeStyleMetrics is going to be Qt's and it will potentially be
constructed several times in parallel from different thread, causing
warnings and crashes within Qt.
So don't initialize the StyleMetrics, it is only used for the dark style
anyway
2022-10-18 15:54:57 +02:00
Simon Hausmann
b727aba4a0
Fix quality of SVG rendering in the online editor (#1740)
SVGs are rendered using HTML image elements, that are converted to textures.
The size of the texture defaults to the SVGs viewbox, which may be small - despite
it being possible to render the SVG at a higher resolution with great quality.

Similar to the native code path, this patch also uses the target image size
and propagates it to the DOM HTML image element to instruct the browser to
render the SVG at a higher resolution.

Co-authored-by: Olivier Goffart <olivier.goffart@slint-ui.com>
2022-10-18 14:43:33 +02:00
Simon Hausmann
0577d8a20d Use physical lengths for the image cache rendering
This avoids accidental use of logical pixels, esp. for SVG, elimiates
one call to `to_untyped()` as well as an untyped scale factor in the
femtovg renderer.
2022-10-13 17:02:18 +02:00
Simon Hausmann
38a55f87a4 Change internal MouseEvent to use logical points 2022-10-13 17:02:18 +02:00
Simon Hausmann
c11b4305c1 Change Item::geometry() to return a LogicalRect 2022-10-13 17:02:18 +02:00
Simon Hausmann
299325370d Change generated accessor functions for Property<Coord> getters to return LogicalLength 2022-10-13 17:02:18 +02:00
Simon Hausmann
6913aa16e9 Fix placement of IME suggestions popup with Qt
The suggestions popup from the input method was off by the y-coordinate. This was due to
text_input_cursor_rect_for_byte_offset returning the y position of the line only.
However QTextLine::y() is relative to QTextLayout::position().y(),
which needs to be added to take any vertical alignment into account.
2022-10-13 11:13:13 +02:00
Simon Hausmann
41855b38cf Initial IME support for Qt
This comes with the same caveats as the winit one: The composition is
not committed when clicking with the mouse or generally aborting the
composition.
2022-10-13 11:13:13 +02:00
Simon Hausmann
6d1497d7a2 Fix wasm build 2022-10-07 11:16:36 +02:00
Simon Hausmann
dc8bc5690b Fix C++ build with changed KeyEvent
cbindgen does not support Option.
2022-10-07 11:16:36 +02:00
Simon Hausmann
8cba0622f5 Initial input method support for the winit backend and the FemtoVG/Skia renderers
Known caveats:

- winit doesn't forward mouse events to the IME, so clicking
  with the mouse while composing results in funny effects such
  as the pre-edit text following the cursor.
- With FemtoVG there's no text decoration support, thus no underlining
  of the preedit area.
2022-10-07 11:16:36 +02:00
Simon Hausmann
c40b82c509 Add ItemRc to focus_event and key_event
This will be needed to compute the cursor rectangle in window coordinates, by
traversal of the parent chain.
2022-10-07 11:16:36 +02:00
Be
ecb6fd5309 switch to yeslogic-fontconfig-sys from servo-fontconfig
This allows setting the RUST_FONTCONFIG_DLOPEN environment variable
to dlopen fontconfig at runtime rather than linking it at build
time. This is helpful for cross compiling to Linux, particularly
because fontconfig has lots of C dependencies. Building a vendored
copy of fontconfig does not work as expected:
https://github.com/slint-ui/slint/issues/88
2022-10-05 15:21:54 +02:00
Simon Hausmann
b849cf70da
Bump the Rust Skia bindings to the latest release (#1704)
This updates the Skia bindings to milestone 106
2022-10-03 12:01:05 +02:00
Simon Hausmann
2da2511f13
Use a vector for ItemRenderer::translate (#1700)
This simplifes call sites and implementations.
2022-10-02 10:06:20 +02:00
Simon Hausmann
37a8c50c12 Simplify FontRequest
It doesn't have to be generic as mostly the frontend code creates it with logical lengths.
2022-09-30 23:31:32 +02:00
Simon Hausmann
2278ac3581 Remove two more uses of LogicalRect::from_untyped 2022-09-30 13:00:37 +02:00
Simon Hausmann
cc8ff56d98 Remove more uses of LogicalRect::from_untyped() 2022-09-30 13:00:37 +02:00
Simon Hausmann
f95311bb3f Skia: Simplify item_rect implementation 2022-09-30 13:00:37 +02:00
Simon Hausmann
f40fc6500f Skia: make textlayout operate entirely on physical coordinates
This simplifes the call sites a little and allows conversion from logical to physical to be done earlier.
2022-09-30 13:00:37 +02:00
Simon Hausmann
57fe1b9c47 Replace manual calls to LogicalLength::new() for item fields with logical_XXX getters 2022-09-30 13:00:37 +02:00
Simon Hausmann
a52d633b59 Change FontRequest to be a generic over the length
The API uses a logical length for pixel sizes and letter spacing,
but the renderer will need the physical length eventually.
2022-09-30 13:00:37 +02:00
Simon Hausmann
1624a66ebc Change the Renderer trait's text related functions to explicitly operate on logical lengths 2022-09-30 13:00:37 +02:00
Simon Hausmann
59368363c9 Change the ItemRenderer trait to use logical lengths 2022-09-30 13:00:37 +02:00
Simon Hausmann
f66a2a5775
Port the FemtoVG renderer to use different types for logical and physical lengths (#1696) 2022-09-30 09:31:11 +02:00
Simon Hausmann
7f6a6aa57b Skia: centralized duplicated vertical alignment computation 2022-09-30 09:03:02 +02:00
Simon Hausmann
dc048a11db Port the Skia renderer to use different types for logical and physical lengths 2022-09-30 09:03:02 +02:00
Simon Hausmann
1af05c41d5 Skia: fix quality of SVG images when using scale factor
Suppose we render an SVG at 100px x 100px with a screen scale factor of 2.
Consequently we should be rendering the SVG at 200phx x 200phx, not 100x100.

Do this by applying the scale factor, just like it is done in the femtovg renderer.
2022-09-28 22:32:09 +02:00
Simon Hausmann
dbe9f33bb4 janitor: Fix warning about unused functions/modules when compiling with Skia and D3d or Metal
When using Metal or D3D, we don't need the glcontext module.
2022-09-22 14:35:17 +02:00
Simon Hausmann
4a1e2e2eaf janitor: remove obsolete commit
Commit 743a980e21 added text selection drawing.
2022-09-22 13:14:01 +02:00
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