Commit graph

139 commits

Author SHA1 Message Date
J-P Nurmi
6686861523 SW: fix vertical alignment of elided multiline text 2023-10-11 14:35:20 +02:00
Olivier Goffart
b88a3caacd swrenderer: Put the rotation feature behind a freature gate
We're not ready to make the API public as we want to have the API as
part of the Window rather than part of the renderer
2023-10-09 18:07:23 +02:00
Olivier Goffart
b6636b2e94 swrender: Implement window rotation by 180° and 270°
(The tests are still failling)
2023-10-09 18:07:23 +02:00
Olivier Goffart
ec36d46740 WIP: experiment with screen rotation
TODO:
 - Polish the API
 - Most screenshot test are failling because the rotation don't draw the
   rounded rectangle exactly the same (that's because the border
   rectangle algo is not perfect), and also scaled image are not pixel
   perfect

The updated screenshot is because of a small change in the image
rendering algorithm that changes the rounding slightly.
2023-10-09 18:07:23 +02:00
Olivier Goffart
852b4d906d Rename ComponentVTable to ItemTreeVTable
and their related name.
Also move the component module in the item_Tree module
register_component -> register_item_tree
ComponentItemTree -> ItemTreeNodeArray

For #3323

Rationale from that issue:

Right now, we use the term `component` in the Slint language and in the compiler to be a a tree of elements that can be used as an element in a .slint file.

The term is also currently used in the runtime as a tree of runtime Items that are allocated together. (declared in ComponentVTable)

But there are no 1 to 1 mapping between a `component` in the slint language, and a runtime Component.
(for example, the items behind a `if` or `for` or `PopupMenu` are in a different runtime component. And `component` declared in Slint are often inlined)

So we should rename the internal runtime `Component` to  `ItemTree`

The currently public `slint::ComponentHandle` wraps the "root" of the ItemTree, but that's ok because it is generated from a .slint `component`,  so it doesn't change name
2023-10-09 11:01:56 +02:00
J-P Nurmi
af60d060ca
SW: fix horizontal alignment of text cursor and selection
A partial fix to #3580.
2023-10-02 12:44:03 +02:00
Olivier Goffart
e0ac0ed319
Frame per second counter for the software renderer 2023-09-28 16:23:07 +02:00
Olivier Goffart
46ec7875ed Software renderer: partial rendering with winit and fix non-opaque background
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)
2023-09-13 16:08:57 +02:00
Simon Hausmann
84ddfc6c2f Add support for rendering the mouse cursor with linuxkms
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.
2023-07-31 13:06:28 +02:00
Olivier Goffart
3a807e46c1
Renderer feature refactor 2023-07-27 19:11:24 +02:00
Olivier Goffart
a9fa51469c swrenderer: use interior mutability for the repaint_buffer_type 2023-07-27 14:44:28 +02:00
Olivier Goffart
49485dbf7d SoftwareRenderer: add API to construct and change the buffer type 2023-07-27 14:44:28 +02:00
Simon Hausmann
c05ee8b87d Fix empty window test
When render() is called on an renderer that's not associated with a component yet,
then just return a default constructed region.
2023-07-25 17:28:08 +02:00
Simon Hausmann
5a9f8a4c90 Clear caches in the renderers when "changing" the window adapter
This helps to keep the allocation peak low.
2023-07-25 17:28:08 +02:00
Simon Hausmann
7d136b6568 Remove the window parameter from the render() function of all the renderers
This makes for a slimmer API and instead we can create the renderer <-> window association
behind the scenes ourselves,
in set_component.
2023-07-25 17:28:08 +02:00
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
Olivier Goffart
4a56531dab swr: Fix panic when drawing clipped text
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
```
2023-07-07 13:12:33 +02:00
Olivier Goffart
c0ac2acbef Avoid panicking when asked to render an empty window 2023-07-07 13:12:33 +02:00
Olivier Goffart
4296ca2afe Software renderer: Fix another panic when the coordinate are NaN 2023-07-07 13:12:33 +02:00
Olivier Goffart
6eef589043 Fix panic in the software renderer with clipped text and scale factor
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
2023-07-07 13:12:33 +02:00
Olivier Goffart
db0dd19447 Sotfware renderer: Fix panic when pressing the End key
(The runtime create a point which is in f32::MAX away, so we need to
keep it within the bounds of i16)

Fixes #3058
2023-07-06 16:34:26 +02:00
Tobias Hunger
e02c360000 Clippy polish 2023-06-28 14:22:30 +02:00
Olivier Goffart
e4bf8ca9d4 Add an assert in the software renderer if the buffer is too small
So it panics early instead of panicking deep in the renderer when trying
to draw outside of the buffer

Fixes #2027
Replaces #2973
cc: #2957
2023-06-27 14:34:13 +02:00
Olivier Goffart
8cf57badbf swrenderer: basic text selection 2023-06-22 23:20:49 +02:00
Olivier Goffart
11dea135f7 Domain: slint-ui.com -> slint.dev 2023-06-16 10:55:08 +02:00
Aurindam Jana
039e54a5de
Add royalty free license to files except examples and docs (#2888) 2023-06-15 11:20:50 +02:00
Olivier Goffart
4dd10f4a78 Make WindowAdaptor::request_redraw public 2023-06-13 20:29:52 +02:00
Olivier Goffart
0e31f097a4 Un-seal the WindowAdapter trait 2023-06-13 17:44:04 +02:00
Olivier Goffart
23b910725f Rename WindowAdapterSealed to WindowAdapterInternal 2023-06-13 17:44:04 +02:00
Olivier Goffart
f4dba7bcfd Seal the Renderer trait
Because we need to make the Render trait public so one can re-implement
the WindowAdapter trait
2023-06-13 17:44:04 +02:00
Olivier Goffart
6341769cbd WindowAdaptor: move a few function to the public trait
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
2023-06-13 17:44:04 +02:00
Simon Hausmann
e3e9131dc3
Fix panic when attempting to render window contents without a component (#2800)
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>
2023-06-01 12:40:01 +02:00
Simon Hausmann
fe4a434ce4 Remove the WindowAdapter from the renderer constructor
This allows disentangling the native window creation from the renderer
creation, which is rather ugly and complicated on the C++ side.
2023-05-21 14:40:43 +02:00
Olivier Goffart
dd5ef9993f
Platform: Add a Resized event and use that to convey the changes in size (#2759) 2023-05-21 12:12:30 +02:00
Florian Blasius
757a744123
Add screenshot test for TextInput (#2746)
* 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>
2023-05-17 15:43:43 +02:00
Florian Blasius
6bbbdce0e5
swr: improve text cursor placement by mouse and arrow keys (#2743) 2023-05-17 11:49:24 +02:00
Simon Hausmann
4abc26688e textlayout: Fix bug in byte_offset_for_position
Skip correctly over lines.

Co-authored-by: Florian Blasius <FloVanGH@users.noreply.github.com>
2023-05-17 09:58:45 +02:00
Simon Hausmann
8a2b40ca7d Simplify core Renderer trait for easier implementation
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.
2023-05-17 09:01:02 +02:00
Florian Blasius
a03046a3e4 swr: code review
Co-Authored-By: Simon Hausmann <simon.hausmann@slint-ui.com>
2023-05-15 13:23:05 +00:00
Florian Blasius
e25e7cf1b0 swr: implement text_input_byte_offset_for_position
* add byte_offset_for_position to TextParagraphLayout
2023-05-15 13:23:05 +00:00
Simon Hausmann
13697bc63c Implement a line-skipping shortcut for cursor_pos_for_byte_offset() 2023-05-11 10:34:49 +00:00
Florian Blasius
8fcf48fdbf swr: implement text_input_cursor_rect_for_byte_offset and cursor rendering
Co-Authored-By: Florian Blasius <FloVanGH@users.noreply.github.com>
Co-Authored-By: Simon Hausmann <simon.hausmann@slint-ui.com>
2023-05-11 10:34:49 +00:00
Simon Hausmann
c8c39e82b4 textlayout: Add the ability for the line callback to break with a value 2023-05-11 10:34:49 +00:00
Olivier Goffart
37e70c302e Refactoring: Pass the size to to the render function
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
2023-05-05 19:53:57 +02:00
Florian Blasius
4a39cdbc86
swr: display text on text input (#2550) 2023-04-14 11:14:00 +02:00
Simon Hausmann
b38df20d9a Add a feature to enable system fonts with the software renderer
If we have a file system, then we can allow users of the software
renderer to support text rendering by from fonts served by the file
system.

cc #2100
2023-03-28 11:33:44 +02:00
Olivier Goffart
476ab383ea software_renderer: return the modified region from the render call
Closes #2389
2023-03-24 17:29:01 +01:00
Olivier Goffart
17e7c1f0c7 software_renderer: implement draw_cached_pixmap
needed to render the native style
2023-03-24 16:29:21 +01:00
Simon Hausmann
2872c13fff Fix using the software renderer with the native style
Provide access to the window inner also from within the software
renderer, so that the native style rendering can query the active state.

Fixes #2404
2023-03-24 16:29:21 +01:00
Simon Hausmann
8ffb5131c7
Introduce error handling in the FemtoVG and Skia renderers (#2402)
Avoid unwrap() and expect() and instead propagate errors all the way
down to run_event_loop(), show(), and hide() in the Slint AIP.
2023-03-24 14:18:11 +01:00