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
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.
* 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.
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
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
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
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.
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).
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.
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
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
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.
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.
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.