Implement the partial rendering with winit and our software renderer.
When the background is not opaque, we must still initialize all the
pixel with 0 otherwise we blend over the previous frame.
(That wasn't visible before because the buffer was always empty)
The cursor is loaded by the window adapter from the cache. When it's
loaded the first time, its format will be Svg, so we convert it to a
pixel buffer. That way the skia backend can convert it on first draw
into a skia_safe::Image and replace the cache entry with the backend
storage variant.
In some case, when the clip is, eg on a 0.25 of a pixel, but the offset is 0.75,
(such that the begining of the glyph starts at 0.5) difference in
rounding in different computation can result in a width which is one
pixel bigger than the source image.
I couldn't reproduce this in a testcase, but this can be reproduced
while resizing or scrolling through a TextEdit
I think this fixes#2957
The panic fixed by this commit looks like this:
```
thread 'main' panicked at 'index out of bounds: the len is 131 but the index is 131', /home/olivier/slint/internal/core/software_renderer/draw_functions.rs:81:19
stack backtrace:
3: i_slint_core::software_renderer::draw_functions::draw_texture_line
at ./internal/core/software_renderer/draw_functions.rs:81:19
4: <i_slint_core::software_renderer::RenderToBuffer<T> as i_slint_core::software_renderer::ProcessScene>::process_shared_image_buffer
at ./internal/core/software_renderer.rs:1023:13
5: i_slint_core::software_renderer::SceneBuilder<T>::draw_text_paragraph::{{closure}}
at ./internal/core/software_renderer.rs:1404:37
6: i_slint_core::textlayout::TextParagraphLayout<Font>::layout_lines::{{closure}}
at ./internal/core/textlayout.rs:219:17
```
We ended rendering glyphs with empty or even negative size, causing
panics down the line.
I added a way in the screenshot tester to change the scale factor
CC: #2957
Note: the addition of MinimalSoftwareWindow::set_size is there because
it would be a breaking change for user who called set_size on the
MinimalSoftwareWindow while also using the WindowAdapter trait.
This was the case of a test.
The same problem theorically exist with set_position and position, but
is unlikely to be a problem because i don't think people would use the
position with a MinimalSoftwareWindow
The renderer() is now public as well. That's because I want to make sure
that the scealed trait don't have non-provided method
With Qt and eglfs it may happen that when creating a popup, Qt delivers
a paint event via show() before we've had a chance to set the component
on the slint::Window. In that case unwrapping the component in
draw_contents() panics.
This fix is covered by reproducing the same scenario using public
MinimalSoftwareWindow API.
Fixes#2799
Co-authored-by: Olivier Goffart <olivier.goffart@slint-ui.com>
* add screenshot test for text input
* Update tests/screenshots/cases/software/basic/text_input.slint
Co-authored-by: Simon Hausmann <simon.hausmann@slint-ui.com>
* swr: fix clipping of text cursor
---------
Co-authored-by: Simon Hausmann <simon.hausmann@slint-ui.com>
Make text_input_byte_offset_for_position and text_input_cursor_rect_for_byte_offset
low-level in the API, where the implementation becomes easier. Two
helper functions in TextInput in turn collect the necessary parameters
and thus also reduce the amount of duplicated code.
This also decouples the renderer further from the window.
So that we don't need to query the geometry multiple time, and this pave
the way to not have the geometry in the items
Part of #1932
As a drive by, fix the clipping of the Path element which incorrectly
offseted the clip by (x,y).
Similar fixes happen in the Clip element in some renderer, but that
didn't have effect because x and y are always 0 for the Clip element
This would cause some of the image to be drawn outside of the clip
region, which may even lead to panics
(Fix changing pages in the energy-monitor demo)
Having a const generic for that didn't turn to be a good API.
Also made the C++ side more difficult
(Also renamed buffer_stride to pixel_stride)
Closes#2135