Commit graph

1368 commits

Author SHA1 Message Date
Simon Hausmann
247772104a Move WindowEvent, PointerEventButton and Key to the platform module
For `Key` this is a move, as it is a new type. For `WindowEvent` and `PointerEventButton` deprecated aliases
are provided.
2022-11-24 11:34:28 +01:00
Simon Hausmann
66871da47b doc: remove stray triple slash 2022-11-24 09:15:05 +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
Olivier Goffart
73a16a171c Janitor: upgrade a few crates 2022-11-22 18:38:05 +01:00
Florian Blasius
00bd4909e1
SoftwareRenderer: render texture with opacity and color alpha channel (#1877)
* swr: add alpha field to texture
2022-11-21 15:26:35 +01:00
Olivier Goffart
39aebc1f4e Use the std::ops::Range as range in the repeater
And fix the preview highlight to use that
2022-11-17 12:23:23 +01:00
Olivier Goffart
0d39e6f721 Make use of ItemRc::map_to_window 2022-11-17 12:23:23 +01:00
Simon Hausmann
907b58161c Add support for invoking an init callback on component and element construction
This enables imperative code to be run. To be used sparingly :-)
2022-11-17 10:12:08 +01:00
Olivier Goffart
9baf6f2bde swrender: Fix drawing of border rectangle with only border
(no radius or background, just a border)

Fixup previous commit that remove the wrong brace
2022-11-16 12:26:33 +01:00
Florian Blasius
c83e04bb52
swr: apply opacity on rect and rect with (#1866) 2022-11-16 12:20:52 +01:00
Simon Hausmann
0f25000610 internal: Replace calls to the internal process_key_input with the public dispatch_event API
This can be done for key press and release events, for composition we
need to extend the API first.
2022-11-16 09:47:54 +01:00
Florian Blasius
61c39b5fa1 Add support for dispatching key events through the public platform API
This change adds `KeyPress` and `KeyRelease` variants to the
`WindowEvent` enum, along with the new `slint::Key` enum, that allows
encoding keys.
2022-11-15 10:34:17 +01:00
Simon Hausmann
e3838543fe Implement From<char> for SharedString 2022-11-15 10:34:17 +01:00
Olivier Goffart
27347de92b Properties: fix extra dependency when making a two way binding
This can be reproduced with this example:

```
import { TabWidget } from "std-widgets.slint";
App := Window {
    preferred-width: 700px;
    preferred-height: 500px;
    HorizontalLayout {
        side-bar := TouchArea {
            property <int> current-item: 1;
            clicked => { current-item =  current-item == 0 ? 1 : 0 ; }
        }
        if(side-bar.current-item == 0) :  TabWidget {  }
    }
}
```

With the native style. (click on the window, then resize)
This will result in a stack overflow, because we have a cycle in the
dependency graph and they are marked dirty forever.
The NativeTabWidget will create two way binding internally. And it will
be crated as a result of the layout cache property because that's when
the model will be evaluated and created.  This will inatvertently create
a dependency between the layout cache property, and the two way link.
2022-11-09 12:57:11 +01:00
Florian Blasius
646cbecfa5
Fix background in swr is not drawn (#1830)
There was an error drawing the window background in the software renderer because of a wrong check.
2022-11-09 12:23:22 +01:00
Simon Hausmann
e9db914fb1
Add is_visible to NodeJS and C++ Window types (#1816)
Amends commit 82278a5742
2022-11-04 16:24:24 +01:00
Simon Hausmann
39121994ca Always set Window.default-font-size
Permit the style metrics to provide a `default-font-size` and bind that
to the `Window` if set. If not provided, then the backend can set a
`default-font-size`. By ensuring that the value is non-zero at run-time,
we can later introduce a rem unit that can act as factor relative to
this non-zero font size.
2022-11-03 17:15:44 +01:00
Simon Hausmann
a95504ad4f Remove stray and duplicated call to request_window_properties() 2022-11-03 17:15:44 +01:00
Simon Hausmann
63cd49fb46 Use LogicalPoint for the internal popup location 2022-11-01 12:15:51 +01:00
Simon Hausmann
64588c70f1 Make popup related data structures internal to the window module 2022-11-01 12:15:51 +01:00
Simon Hausmann
b835290f83 Use LogicalRect for the geometry of popups in WindowAdapterSealed 2022-11-01 12:15:51 +01:00
Simon Hausmann
65e4e7bf15 Bump resvg/usvg/tiny-skia dependencies 2022-11-01 10:44:33 +01:00
David John
82278a5742 api: add Window::is_visible 2022-10-29 09:21:26 +02:00
ogoffart
2171773a3e Bump version number to 0.3.2 2022-10-28 09:30:14 +00:00
Simon Hausmann
3d2daf6073
Fix crash when editing text that's rendered using the Skia renderer (#1786)
Olivier found the following steps that reproduce the crash with Skia:

1. Open the gallery and select the "Text Edit" tab.
2. In the first text edit widget, select the first three letters.
3. Click into the second text edit (while the first one shows the selected text)
4. At the beginning of the text, insert the letter "ù" a few times.

This sequence would result in the cursor_position property get out of
sync.  Since it represents a byte offset in the utf-8 text, it would
point straight into a utf-8 sequence, resulting in a panic when the
renderer would try to create a slice of the selected text.

As a remedy, this patch renames the cursor_position and anchor_position
properties and provides wrapper getter accessors for use within the
TextInput to safely bound the stored offset.

Eventually we need to intercept changes to the text property and adjust
the cursor and anchor position properties accordingly, so that they
remain valid.  However this requires that the compiler is aware that a
property is not accessible directly but has a setter that needs to be
called instead.

This likely/hopefully also fixes #1707.
2022-10-27 21:47:14 +02:00
Olivier Goffart
788e24494b Flickable: do not capture the event when moving the mouse bellow threshold
Because an inner item (eg, another Flickable) way still want
to intercept the delayed event
2022-10-27 18:55:47 +02:00
Olivier Goffart
6e87073181 Flickable: only grab the mouse if the flickable can be flicked
We already checked before that we can flick in that direction
(horizontally or vertically), but we did not check that we were not
actually at the end already.
2022-10-27 18:55:47 +02:00
Olivier Goffart
f055afd2de New syntax: allow to create component without base 2022-10-26 18:09:57 +02:00
Simon Hausmann
d7e366864b Bump various dependencies
Bump fontdb, foreign-types (used for skia/metal), ttf-parser and winit.

The winit bump is explicit on the patch version to ensure the IME crash
fix is included.
2022-10-26 18:01:29 +02:00
Florian Blasius
a4313c3e32
API changes for SortModel and FilterModel (rust and cpp) (#1768)
* Rust SortModel: Rename parameter `S` to `F`
* Rust SortModel: Rename parameter `apply_sorting` to `reset`
* Rust FilterModel: Rename parameter `apply_filter` to `reset`
* C++ SortModel: Rename parameter `sort_fn` to `comp`
* C++ SortModel: Add pub reset function
* C++ FilterModel: Rename parameter `apply_filter` to `reset`
2022-10-26 11:16:12 +02:00
Simon Hausmann
40f6174d19 janitor: Fix build of corelib tests
rustbyzz 0.5.3 was released, which also removes the ttf parser re-export. Bump to 0.6 to fix that.
2022-10-24 17:44:17 +02:00
Simon Hausmann
c16253d29f Use Property<LogicalLength> instead of Property<Coord>
This removes the special code for the generated property getters and
ensures type safety in the run-time library for property value setting.

In the Rust generated code we continue to do arithmetic on the scalar
values, that means we immediately extract the scalar, do arithmetic and
rely on the compiler to only allow compatible units.

Danger zone alert: In the interpreter Value::Number can now be converted
to LogicalLength as-is.
2022-10-24 12:49:37 +02:00
Olivier Goffart
2e08b7dd1e Fix the rendering size of svg
- On the web, to return the image size, we need to use the natural size
   of the image, and not its dom size, as the later get modified since
   commit  b727aba4a0

 - The target size did not take in account the image fit, that's because
   former version of resvg could only render by respecting the aspect
   ratio. But since the web don't have this limitation, we now need to
   take it into account. And new version of resvg can also scale with
   any aspect ratio
2022-10-24 10:05:38 +02:00
Simon Hausmann
6dc67d5b7b janitor: work around rustybuzz version incompatibility
Use the re-export to avoid a version clash for ttf-parser.
2022-10-23 14:36:44 +02:00
Florian Blasius
c58c704f16
Change type of Window background from color to brush (#1755) 2022-10-21 16:17:22 +02:00
Olivier Goffart
6ee932883a Rename stark-style to dark-color-scheme
That's the term used by CSS
2022-10-19 15:23:41 +02:00
Olivier Goffart
0ba468c236 Use a builtin function to access the dark-style
instead of a property on NativeStyleMetrics
2022-10-19 15:23:41 +02:00
Simon Hausmann
b727aba4a0
Fix quality of SVG rendering in the online editor (#1740)
SVGs are rendered using HTML image elements, that are converted to textures.
The size of the texture defaults to the SVGs viewbox, which may be small - despite
it being possible to render the SVG at a higher resolution with great quality.

Similar to the native code path, this patch also uses the target image size
and propagates it to the DOM HTML image element to instruct the browser to
render the SVG at a higher resolution.

Co-authored-by: Olivier Goffart <olivier.goffart@slint-ui.com>
2022-10-18 14:43:33 +02:00
Olivier Goffart
285ddbe6ca Upgrade clru dep 2022-10-17 17:04:51 +02:00
Olivier Goffart
7d90a3673f Add VecModel::extend, tests, and changelog entry for last commit
CC #1678  #1647
2022-10-17 14:40:48 +02:00
David John
a049d72ac5 add VecModel::extend_from_slice 2022-10-17 14:04:49 +02:00
Simon Hausmann
0577d8a20d Use physical lengths for the image cache rendering
This avoids accidental use of logical pixels, esp. for SVG, elimiates
one call to `to_untyped()` as well as an untyped scale factor in the
femtovg renderer.
2022-10-13 17:02:18 +02:00
Simon Hausmann
38a55f87a4 Change internal MouseEvent to use logical points 2022-10-13 17:02:18 +02:00
Simon Hausmann
c11b4305c1 Change Item::geometry() to return a LogicalRect 2022-10-13 17:02:18 +02:00
Simon Hausmann
299325370d Change generated accessor functions for Property<Coord> getters to return LogicalLength 2022-10-13 17:02:18 +02:00
Simon Hausmann
27fea8b9f3 Fix rustdoc warnings with nightly
Use backticks as recommended by rustdoc for items that could be interpreted as HTML tags.
2022-10-12 17:29:46 +02:00
Florian Blasius
129ee0acae
Florian/sort todo (#1721)
Implement `set_row_data` for `SortModel` and `FilterModel` (rust and cpp). Add sort and filter example to the todo example.
2022-10-11 18:58:00 +02:00
Florian Blasius
5fb31ace02
Florian/rust sorting model (#1712)
Add Rust version of SortModel
2022-10-07 16:24:48 +02:00
Simon Hausmann
dc8bc5690b Fix C++ build with changed KeyEvent
cbindgen does not support Option.
2022-10-07 11:16:36 +02:00
Simon Hausmann
8cba0622f5 Initial input method support for the winit backend and the FemtoVG/Skia renderers
Known caveats:

- winit doesn't forward mouse events to the IME, so clicking
  with the mouse while composing results in funny effects such
  as the pre-edit text following the cursor.
- With FemtoVG there's no text decoration support, thus no underlining
  of the preedit area.
2022-10-07 11:16:36 +02:00