Commit graph

170 commits

Author SHA1 Message Date
Olivier Goffart
5955d19706 Expose the individual rectangle in the dirty region 2024-04-26 14:45:23 +02:00
Olivier Goffart
f45bab6a3f swrenderer: Support multiple rectangles for the dirty regions
This allow to be much faster in the case two small area of the screen
changes.
2024-04-26 14:45:23 +02:00
Tobias Hunger
e10e97c944 live-preview: Add placeholder when removing the last eleemnt in a layout
Add a placeholder Rectangle into a layout whenever the last eleemnt is removed.
This makes sure we can drop into the Layout again.

Add infrastructure to find the parent element to ElementRcNode and move more
code into the ElementRcNode.
2024-04-25 10:28:15 +02:00
Olivier Goffart
5deb3add63 swrender: Fix panic in some cases
Can be preproduced on the esp-idf usecases p4 demo when going into the
combobox dans doing a long press in the popup.

Same fix as 4296ca2afe but for line by
line
2024-04-23 16:17:46 +02:00
Aurindam Jana
0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00
Olivier Goffart
02775f7783
swrenderer: Fix rendering of SVG when SLINT_SCALE_FACTOR is defined at compile time (#5013)
We call fit_to with the source size (which is not scaled by the scale
factor) while the actual image is already scaled, so we need to adjust
for the difference between the texture size and the original size.

Also pass the scale_factor at compile time to the screenshot test
2024-04-04 13:19:17 +02:00
Olivier Goffart
881da94737 Move the condition to render the text cursor in TextVisualRepresentation
And add a hack to make the screenshot test pass on Mac
2024-03-21 09:34:52 +01:00
Olivier Goffart
5e66fe9dc8 Fixup cursor color and appearence
On mobile and macOs, the cursor is the selection color.
Also don't show the cursor when there is a selection (all platforms)
2024-03-21 09:34:52 +01:00
Tobias Hunger
77c85aa703 janitor: fix clippy warnings about "bound is defined in more than one place" 2024-03-14 13:42:38 +01:00
Tobias Hunger
9873cfd7c0 janitor: Run cargo clippy --fix
Only the hand-picked sensible things, not all of it ;-)

Also fix a few typos that cspell complained about when I
tried to commit and some formatting changes that cargo fmt
insisted on when commiting.
2024-03-14 13:42:38 +01:00
Olivier Goffart
5a4e24529b swrenderer: Fix rendering of the first glyph if it has negative bearing
`src_rect.origin.x` can be negative and when casted to usize it becomes zero
2024-03-07 11:29:05 +01:00
Olivier Goffart
3910095e4d Tiling for the nine slice images 2024-02-26 12:16:41 +01:00
Olivier Goffart
5e7ddf3a19 Image Tiling
(Doesn't work yet with 9slice)
2024-02-26 12:16:41 +01:00
Tobias Hunger
a8f912900b janitor: Fix warnings in nightly about redandant use 2024-02-19 17:05:21 +01:00
Olivier Goffart
424f046416 swrenderer: refactor image drawing algorithm
For tiling, we will need to know the actual source size in addition to
the scaling factor that can be different. So store the scaling factors
in the scene command, as well as an offset where to start.

This is more accurate in case of clipping and rotation.
For rotation that doesn't matter (appart from the fact that the testing
can now be more strict)
But for clipping this prevent glitches with partial rendering where it
would seem like the image are moving a bit by a pixel when it is redrawn
with a different clip
2024-02-15 18:25:47 +01:00
Olivier Goffart
2a63df6ed6 Implementation of border image in the software renderer 2024-02-13 14:46:27 +01:00
Olivier Goffart
ce6c7f5527 Image: add horizontal and vertical alignment 2024-02-08 18:59:26 +01:00
Olivier Goffart
cb92ba1132 Add ImageFit.preserve and de-duplicate the fitting code 2024-02-08 10:10:56 +01:00
Olivier Goffart
e43f4d4c0c Fix a panic in the software renderer when rendering text
To reproduce, run the slide_puzzle with a SLINT_SCALE_FACTOR of 1.5 with
the software renderer.

The bug is that some text are rendered at some location, with an offset
of, say, 400.499999. And then the left and right side of the bounding
rectangle may be rounded differently and we may get to draw images that
are bigger than the glyph which cause panic. Fix that by ensuring we
never do that.
2024-02-07 15:51:55 +01:00
Olivier Goffart
b23c605ac1
Refactoring: Use a trait for Item being Images 2024-02-07 13:28:47 +01:00
Simon Hausmann
367af4fdf4 Align rotation between software renderer and LinuxKMS backend
As discussed a few days ago, let's define rotation to be always
clockwise, as it is done in other graphics frameworks as well as our
own image rotation. This means changing the definition for the
software renderer. Also fixed docs for the enum in the linuxkms backend
that was wrong.
2024-02-07 11:21:59 +01:00
J-P Nurmi
5e086971c9 Add RenderBorderRectangle trait 2024-02-06 18:01:35 +01:00
J-P Nurmi
031742246c Implement clipping 2024-02-06 18:01:35 +01:00
J-P Nurmi
1971f598bb SW: non-uniform border radius 2024-02-06 18:01:35 +01:00
Olivier Goffart
91adad0079 Fix panic in the software renderer when rendring Qt widget
we shall never have a geometry that is bigger than the image we want to
render
2024-02-01 11:42:13 +01:00
Simon Hausmann
95044c3a09
Rename WindowRotation to RenderingRotation in the software renderer (#4181)
Same term as we're going to use in the linuxkms backend.
2023-12-19 08:47:55 +01:00
Olivier Goffart
f25a419009 swrenderer: More fix to the screen rotation for line by line 2023-12-08 10:36:04 +01:00
xgroleau🐢
9bc8d203fe doc: matched the comments with the changes 2023-11-28 16:54:00 +01:00
xgroleau🐢
a6feda5233 fix: return transformed on render() 2023-11-28 16:54:00 +01:00
xgroleau🐢
15770ef7e6 fix: compare current line with dirty region 2023-11-28 16:54:00 +01:00
J-P Nurmi
c4864d62ff SW: stop breaking lines after reaching the max (elided) lines 2023-10-13 22:14:58 +02:00
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