Commit graph

246 commits

Author SHA1 Message Date
Simon Hausmann
6913aa16e9 Fix placement of IME suggestions popup with Qt
The suggestions popup from the input method was off by the y-coordinate. This was due to
text_input_cursor_rect_for_byte_offset returning the y position of the line only.
However QTextLine::y() is relative to QTextLayout::position().y(),
which needs to be added to take any vertical alignment into account.
2022-10-13 11:13:13 +02:00
Simon Hausmann
41855b38cf Initial IME support for Qt
This comes with the same caveats as the winit one: The composition is
not committed when clicking with the mouse or generally aborting the
composition.
2022-10-13 11:13:13 +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
Simon Hausmann
2da2511f13
Use a vector for ItemRenderer::translate (#1700)
This simplifes call sites and implementations.
2022-10-02 10:06:20 +02:00
Simon Hausmann
37a8c50c12 Simplify FontRequest
It doesn't have to be generic as mostly the frontend code creates it with logical lengths.
2022-09-30 23:31:32 +02:00
Simon Hausmann
cc8ff56d98 Remove more uses of LogicalRect::from_untyped() 2022-09-30 13:00:37 +02:00
Simon Hausmann
a52d633b59 Change FontRequest to be a generic over the length
The API uses a logical length for pixel sizes and letter spacing,
but the renderer will need the physical length eventually.
2022-09-30 13:00:37 +02:00
Simon Hausmann
1624a66ebc Change the Renderer trait's text related functions to explicitly operate on logical lengths 2022-09-30 13:00:37 +02:00
Simon Hausmann
59368363c9 Change the ItemRenderer trait to use logical lengths 2022-09-30 13:00:37 +02:00
Simon Hausmann
dba137e3ba
Rename RequestedSize to WindowSize and RequestedPosition to WindowPosition (#1640) 2022-09-14 12:59:53 +02:00
Tobias Hunger
53a3c72b57
api: Change logical/physical position and size on window (#1620)
* Add `RequestedSize` and `RequestedPosition` enum to enable asking for
  logical or physical size/position.
* Rename `Window::size()` to `Window::physical_size()`
* Make `Window::set_size(...)` take an `Into<RequestedSize>`
* Rename `Window::position()` to `Window::physical_position()`
* Make `Window::set_position(...)` take an `Into<RequestedPosition>`
* Change `WindowAdapter` and related classes to be able to handle
  requests being made in the either physical or logical units.

Implement this for C++, Rust and node.
2022-09-13 08:55:31 +02:00
Olivier Goffart
911515bfd0 Fix the initial window size when the height depends on the width
We need to assign the width beofre computing the preferred height
otherwise zero or very small value can be assumed and it will case the
text engine return a huge preferred height.

Testcase:

```
export App := Window {
  VerticalLayout {
    padding: -10px;
    Text {
        text: "Lots of text with\nnewlines etc.\n lorem ipsum dolor sit amet";
        wrap: word-wrap;
    }
  }
}
```

In particular, this fixes the gallery window size being too high when
using the skia renderer, because when given a zero width, skia return
a big size for the height, (contrary to the Qt backend that consider 0
as infinite, or the femtovg backend that will stop rendering once a line
can't fit)

Replaces #1621
2022-09-12 12:12:18 +02:00
Simon Hausmann
7967bf1ab0 Replace the internal WindowHandleAccess trait with a helper function on WindowInner
The reversal of ownership removes the need for the glue trait in the
publicly visible API.
2022-09-06 16:17:06 +02:00
Simon Hausmann
7e5de3d5d3 Remove use of euclid types and tags for logical/physical position and size in the public API
Instead provide our own types.
2022-09-02 11:05:53 +02:00
Simon Hausmann
85461d380d Remove euclid from the public re-export of the Slint crate 2022-09-02 11:05:53 +02:00
Olivier Goffart
b9c2dec922 API: seal the WindowAdaptor trait
And hide most of its functions in the sealed trait.
2022-08-30 22:21:24 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Olivier Goffart
2e5ab86bea Rename backend module to platform
and the Backend trait into PlatfromAbstraction trait
2022-08-23 19:39:49 +02:00
Olivier Goffart
00e9fcc9dd backend API: polish and move the timer functions to the backend module 2022-08-22 14:41:50 +02:00
Simon Hausmann
1d436778c1 Remove the use of the PlatformWindowRc alias again
and use Rc<dyn PlatformWindow> instead. The alias has to stay with the ffi
functions though and the item vtable definitions,
because we don't have an Rc<> template in C++.
2022-08-19 15:07:27 +02:00
Simon Hausmann
fd026a3991 Change itemtable to use &PlatformWindowRc instead of &WindowInner
The former is cbindgen friendly, the latter is entirely Rust internal.
2022-08-19 15:07:27 +02:00
Simon Hausmann
af86f36157 Invert slint:🪟:WindowInner and PlatformWindow ownership
Previously: Window is an Rc<WindowInner>, which has an Rc<dyn
PLatformWindow> - and weak references the other way around.

Now: Rc<dyn PlatformWindow> is the root of window ownership. The impl
PlatformWindow has a slint::api::Window, which just holds a WindowInner.

This change is incomplete on a few levels, mainly that neither of the
code generators nor the interpreter is ported.
2022-08-19 15:07:27 +02:00
Simon Hausmann
f88b688fbf Simplify PlatformWindow receivers
For hide() we don't really need Rc<Self>, and for show() we had Rc<Self> because
for example for winit we need a Weak<Self> for the thread-local mapping of
window id to window.

However that can be encapsulated in the PlatformWindow impl using Rc::new_cyclic,
there's no need to expose this in the trait.
2022-08-19 15:07:27 +02:00
Simon Hausmann
8e84faa2c5 Prepare PlatformWindow API for exposing and (in the future) owning the Window
Move the self_weak of WindowInner into the impl of PlatformWindow. Most implementations already have it anyway.

While right now the method returns a `WindowRc`, at the end of the series
it should return a `&Window`.

From that `&Window` we can get to `&WindowInner` and all receivers there
are `&self`.
2022-08-19 15:07:27 +02:00
Olivier Goffart
02c60e5389 Refactor the way the backend sets the window size 2022-08-18 09:39:25 +02:00
Olivier Goffart
a62a5cbd19 Rename MouseEvent pos to position 2022-08-17 18:28:12 +02:00
Olivier Goffart
61739dcb81 Remove the Mouse prefix from enum value of the MouseEvent enum 2022-08-17 18:28:12 +02:00
Simon Hausmann
086880f605 Speed up rendering of clipped children
When the renderer does not re-implement visit_clip, we call combine_clip.
Then we're missing out on an optimization the GL renderer does: When the resulting clip region
is empty, we do not need to recurse into children for rendering.

That itself reduces the property dependency chain and avoids unnecessary
updates when invisible (clipped) children change properties.
2022-08-02 11:07:46 +02:00
Olivier Goffart
8c70cd7f57
Move the fonts out of the Backend trait (#1438)
and remove the `'static`
2022-07-26 16:45:54 +02:00
Olivier Goffart
793974ce9f Make just one function to fire both timers and animations
Also simplify the Qt backend since only the paint event will
query the animated properties that should then cause a refresh
one frame later
2022-07-26 15:13:07 +02:00
Simon Hausmann
369f347b29 Move the clipboard back from the Window to the Backend trait
Found a way to connect the clipboard to the wayland display through the winit event loop target.
2022-07-25 15:41:51 +02:00
Olivier Goffart
74c041010e Move the text functions out of the Window, into the Renderer trait 2022-07-25 12:04:34 +02:00
Simon Hausmann
0ab71ec503 Perform resolution of font properties against the window defaults in the core library
This simplifies the renderer handling - the FontRequest arriving there
will always be resolved.

And this reduces the amount of property dependencies: If a Text elements
specifies a font-family, no dependency to the window's
default-font-family is created.
2022-07-22 23:09:08 +02:00
Olivier Goffart
6de5a42ab2 Use the public Window as a result of the create_popup function 2022-07-22 18:12:00 +02:00
Olivier Goffart
29404e3f2c Rename i_slint_core:🪟:Window into WindowInner
We already have `api::Window` and also the Window element (`WindowItem`),
So rename the inner part to avoid confusion
2022-07-22 18:12:00 +02:00
Simon Hausmann
c494861ddd Change set_clipboard_set to take a &str instead of a String
Every backend will do something different with the string that needs to go into the clipboard.

Qt will convert it to a QString, copypasta to a String, in theory it could be written
directly to a socket.

Given that we don't know what the perfect representation on the backend side is, passing
a string slice avoids any immediate conversions.
2022-07-22 15:21:21 +02:00
Simon Hausmann
e5e7c61414 Simplify the rendering metrics collector API
Instead of a new() function and a start() and no stop() function, create the collector
when we want to measure and drop it when we're done.

This will also make it possible to move the collector into the renderer
in the future.
2022-07-22 15:18:13 +02:00
Olivier Goffart
ac4f3e97ad Change slint enum values to be PascalCase in rust
... while still being kebab-case in .slint

Some enums might become public API and we want to have them as
PascalCase to respect the rust conventions
2022-07-22 12:23:52 +02:00
Simon Hausmann
ee18236053 Remove unnecessary cfg guards 2022-07-22 08:10:44 +02:00
Simon Hausmann
8a3ff06eb5 Move the clipboard handling from the Backend trait into PlatformWindow
Access to the clipboard implies access to the windowing system.
2022-07-22 08:10:44 +02:00
Olivier Goffart
7ccd36f7f2 Simplify PopupWindow handling
When the popup is implemented as an overlay on the window, no need
for the backend to do anything
2022-07-21 12:36:53 +02:00
Olivier Goffart
847a532732 Move the SVG rendering to a buffer in core 2022-07-20 12:57:37 +02:00
Simon Hausmann
67a2f0ce3f WIP: Make image decoding a feature of the core library
This includes the cache of decoded images, the HTMLImage element support
and the SVG rendering adapter.

The objective is that Image holds an ImageInner, which is not a path
anymore that the backend has to process, but instead always either
decoded image data, a pointer to a static texture or an SVG tree that
can be rendered to the desired size.
2022-07-20 12:57:37 +02:00
Simon Hausmann
9799571396 Make it possible to implement the ItemRenderer trait with a lifetime
The as_any() method returning a `&mut dyn Any` meant that the type has to be
'static. The class solution of returning &()
doesn't work because it has to be a mutable ref. Therefore just return an Option.
2022-07-12 20:37:14 +02:00
Simon Hausmann
94b4f81be6 Translate logical to physical coordinates for window position and size
Our API exposes physical coordinates, Qt operates on "logical" coordinates.
2022-07-08 18:37:01 +02:00
Simon Hausmann
937c37677e Add API for setting and getting the size of a Window in Rust and C++ 2022-07-08 18:37:01 +02:00
Simon Hausmann
3ce9977f0a Add slint::Window::(set_)position
Fixes #323
2022-07-08 18:37:01 +02:00
Tobias Hunger
29248f0c6f Qt: Update the accessibility tree when the component tree changes
This makes the Qt accessibility story actually useful: It will now
update as the models in the UI update:-)
2022-06-30 11:51:49 +02:00
Tobias Hunger
dd59d41ee6 Rename init_*_items to register_component
I want to track component structure changes in the window without
generating more code. So use a more generic name for the init_*_items
functions, so that I can add the functionality I need in there.

Also add a register_component to PlatformWindow and call that.
2022-06-30 11:51:49 +02:00
Tobias Hunger
581533f302 Rename free_*_graphics_resources to unregister_component
I want a more generic name as I want to do to track component structure
changes in addition to resource freeing and I do not want to add another
call into the generated code.
2022-06-30 11:51:49 +02:00