Commit graph

170 commits

Author SHA1 Message Date
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
Simon Hausmann
032faad210 software renderer: Fix rendering artefacts when deleting components when using the partial renderer
Upon deletion we have little choice but to refresh the screen :(
2023-03-09 15:14:15 +01:00
Tobias Hunger
3ac01c3f07 clippy: Fix clippy warnings 2023-03-09 09:35:29 +01:00
Olivier Goffart
db12795032 swrenderer: gradient with opacity 2023-03-07 07:16:31 +01:00
Olivier Goffart
5a54fcfeb1 swrenderer: fix image drawing when the image is not stretched to the geometry
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)
2023-03-06 17:13:33 +01:00
Olivier Goffart
a19efc30db
Replace the MAX_BUFFER_AGE const generic with a runtime enum
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
2023-02-08 14:44:01 +01:00
Olivier Goffart
a4eb1ab287 swrenderer support for linear gradient
Only simple rectangle (no borders or radius)
2023-02-02 15:54:07 +01:00
Olivier Goffart
5050e4fea8 swrenderer: move the SceneCommend vector into a separate struct
Simplifies a bit the code as we will add more vectors that need to be
passed from the SceneBuilder to the Scene
2023-02-02 15:54:07 +01:00
Simon Hausmann
8c807cb1da
Remove slint::Image::stride() (#2147)
cc #2138
2023-01-30 13:59:31 +01:00
Olivier Goffart
35c16b9a69 Fix panics in the software renderer system font
Two bugs:
 - There was an extra `* 4` that caused panic when the Text was clipped
 - There was a bug in glyph handling when the text is being split in
   several runs
2023-01-27 12:34:45 +01:00
Olivier Goffart
cd6cfa2521 Software renderer: fix drawing of border rectangle with transparent border
The current implementation of the software renderer doesn't drawn the
background under the border, so if the border is translusent, we don't
see the background color.
This patch blend the color of the border with the coler of the
background.

Software renderer part of #1988  (minus clipping)
2023-01-18 11:39:53 +01:00
Olivier Goffart
5cd38adb14 Move the colorize property to the Image item
Instead of the ClippedImage. Because we use the colorize property more
often than the source property, and these are soon going to be even more
expensive
2022-12-20 08:42:47 -08:00
Simon Hausmann
dee1b11a83 Initial support for truetype fonts in the software renderer
This works, but it's super slow as for every glyph the font is loaded
again and the glyphs are rasterized every time they're drawn.
2022-12-16 18:20:12 +01:00
Simon Hausmann
d69b4b81ba Simplify glyph handling in the software renderer
Remove platform glyph abstraction, just use non-zero u16 as glyph index
like everyone else.  As a bonus, this reduces the memory consumption of
the glyph buffers per glyph from a size of a pointer to the size of the
u16.
2022-12-16 18:20:12 +01:00
Simon Hausmann
8145d10b5b janitor: adaptor -> adapter 2022-12-13 08:35:20 +01:00
Simon Hausmann
b2ebac63c2 Remove component_destroyed from winit's internal renderer interface
The default impl of unregister_component in WindowAdapterSealed would call free_graphics_resources
on the rendere. Any re-implementation would have to do the same,
which the winit backend forwarded through
the winit backend specific internal renderer interface.

Instead, the original call site for unregister_component now calls
free_graphics_resources and unregister_component (for accessibility tree dirty notification).
2022-12-09 09:03:27 +01:00
Simon Hausmann
f5bbca9fce Remove default_font_size() from internal winit renderer interface
Replace register_root_component in the WindowAdapterSealed altogether with
a default font size getter on the renderer.

This is overall simpler and allows removing the doc-hidden getter in the software renderer.
2022-12-09 09:03:27 +01:00
Olivier Goffart
6d0a3f2f9d swrenderer: Fix text hacing the alpha multiplied twice
and do some renaming
2022-11-30 16:49:23 +01:00
Olivier Goffart
830e33876f swrenderer: Fix drawing of images
There was some confusin on the meaning of the alpha and colorize and how
it is computed for AlphaMap images
2022-11-30 16:49:23 +01:00
Tobias Hunger
47300a7495
janitor: Fix clippy errors (#1895)
* janitor: Fix clippy error drop_copy

Clippy says cache_entry is Copy, so calling drop on it is useless since
it will drop a copied value.

* janitor: Fix clippy error

... about cloning a double ref.

Co-authored-by: Olivier Goffart <olivier@woboq.com>
2022-11-23 15:06:07 +01:00