Commit graph

1368 commits

Author SHA1 Message Date
Simon Hausmann
38abeaec41 text handling: clean up font traits
Separate the text shaping functionality from font metrics by having a
FontMetrics trait next to the TextShaper. AbstractFont is the combining
super trait. This allows eliminating the font height member from
TextParagraphLayout and improving the overall naming of fields and
types.

Finally, this prepares the API for composability of TextShaper for font
fallback handling.
2022-05-16 08:21:14 +02:00
Simon Hausmann
3ce142344a text handling: cleanup
Rename "byte_offset" in the Glyph structure to "text_byte_offset" to make
it clearer that this refers to the original text. Also added docs.
2022-05-16 08:21:14 +02:00
Simon Hausmann
02690bfde6 text handling: added some docs 2022-05-16 08:21:14 +02:00
Simon Hausmann
b6eba63f8e text handling: fix glyph cluster type names
Use the term glyph cluster instead of grapheme where we're dealing with
the glyphs for line breaking. Those may coincide with grapheme
boundaries, but aren't required to.
2022-05-15 12:03:29 +02:00
Simon Hausmann
93b5eda82e text handling: simplify glyph data structure handling
Replace the abstract glyph trait with a glyph struct. That way the text
layout code can operate properly on a struct with fields, instead of on
functions on a trait (some of which returning a mutable reference). The
input is a glyph with offset, advance, etc. - everything needed for the
layout and the output is a position along with the platform specific
glyph data.
2022-05-15 12:03:29 +02:00
Simon Hausmann
99ea6db9d4 text handling: simplify shaper <> glyph relation
Use the Glyph trait also for the byte offset handling, to avoid the use of
tuples.
2022-05-15 12:03:29 +02:00
Simon Hausmann
5f52f18df4 mcu text handling: Add support for letter spacing
This is implemented generically by adjusting the advances on the shape buffer, so that we can
use the same in the future in the GL backend.
2022-05-15 12:03:29 +02:00
Simon Hausmann
a7fb45365d text handling: remove unused advance getter on TextShaper
This is available via GlyphMetrics now.
2022-05-15 11:50:54 +02:00
Simon Hausmann
ba59bd5e52 text handling: simplify grapheme and text fragment iterators
Remove the font reference field anymore as it's not needed anymore and
remove the manual clone implementations. Those were needed because
otherwise the TextShaper trait would have to also support clone - as
[derive(Clone)] imposes that. Now we can impose that just on Glyph and
that's easy and makes sense.
2022-05-15 11:50:37 +02:00
Simon Hausmann
08e27fef4a text handling: move function from TextShaper to glyph trait
This will avoid the need to keep a reference to the TextShaper
around.
2022-05-15 11:50:14 +02:00
Simon Hausmann
a9cbac6d3e New line breaking implementation
This is a simpler design that handles various line breaking scenarios
(see added tests) much better.
2022-05-14 15:04:24 +02:00
Simon Hausmann
c91e49a555 Simplify shape buffer handling in line breaking
Replace the lazy text shaping with an up-front shaping of all text.  It
needs to be done eventually anyway, so by doing it in one go we can
avoid interior mutability and simplify the code overall.
2022-05-14 13:22:16 +02:00
Simon Hausmann
9f5445f457 Simplify GraphemeCursor and ShapeBoundaries
Make ShapeBoundaries produce single offsets, there's no need for
ranges as the boundaries are contiguous.

In GraphemeCursor collect all boundaries in one go as text runs, to
simplify state handling. This will be needed anyway for recording bidi
runs in the future.
2022-05-14 13:22:16 +02:00
Simon Hausmann
f1fb451791 Make the line break iterators implement Clone
This is needed in the future to be able to roll back state within the
line breaking when we can't fit even a single word into the line and
have to go back to fitting glyph by glyph.

For the unicode line break iterator the clone is a little more complicated.
The iterator is clone, but the type is anonymous. I first had an
implementation to moved the iterator into a closure, which was cloned
via another control closure. But that's complicated and still involves
allocating the various bits & pieces the closure captures.

So instead the simpler solution used here is to allocate the breaks
into a shared vector.
2022-05-13 17:33:01 +02:00
Simon Hausmann
0e16d7ef9f Fix build of tests with simple line breaker iterator
Add missing trait derivatives
2022-05-13 17:33:01 +02:00
Simon Hausmann
4765cd3c40 Fix inconsistency in line break iterators
The unicode linebreak iterator always produces a mandatory break at end
of text.  This is not only confusing, but also inconsistent with the
simple line break iterator and with trailing spaces it could cause the
line break algorithm to emit empty lines at the end of text.
2022-05-13 17:33:01 +02:00
Simon Hausmann
292db19c32 Simplify simple line break iterator
We don't need Option<char>, just a boolean is enough.
2022-05-13 17:33:01 +02:00
Lukas Jung
ff036d41ec Add model adapters
Co-authored-by: Olivier Goffart <olivier.goffart@slint-ui.com>
2022-05-11 15:50:43 +02:00
Lukas Jung
a36ac901db Add nth() implementation to ModelIterator to improve skip() performance 2022-05-11 15:50:43 +02:00
ogoffart
3709ded44d Bump version number to 0.2.5 2022-05-09 16:16:00 +00:00
ogoffart
c160ec2aef Bump version number to 0.2.4 2022-05-09 13:49:25 +00:00
Tobias Hunger
186e7c0ff2
Fix focus of next item with empty components (#1247)
Handle empty components in the item tree when looking for the next item
to focus.
2022-05-09 12:46:10 +02:00
Olivier Goffart
696ce933f7
Refactor the Model tracking in a module (#1223)
Contain the unsafe code in a smaller module.
Add an abstraction to make it easier to create change listener other
than the repeater.
2022-05-05 10:25:15 +02:00
ogoffart
6395cdfc09 Bump version number to 0.2.3 2022-05-04 12:32:58 +00:00
Olivier Goffart
525e9982d8 Re-export and document ModelExt 2022-05-04 11:08:14 +02:00
Lukas Jung
7c45be97cd Move row_data_tracked to ModelExt trait 2022-05-04 11:08:14 +02:00
Tobias Hunger
9a881f9a90
Clippy 0 2 3 (#1203)
* janitor: Fix clippy error in textlayout.rs

This one is almost certainly a bug.

* janitor: clippy fixes in inline_expressions.rs

Clippy claims the original code was slower and less clean, so let's
change this.
2022-05-02 13:23:35 +02:00
Olivier Goffart
86d893245e Model: When items are inserted, sets the components after that as dirty
Because their index property needs to be updated
2022-05-02 11:47:17 +02:00
Olivier Goffart
2a55daff32 Focus: fix looping in repeater when the repeater ends with a repeater 2022-04-29 17:27:59 +02:00
Olivier Goffart
36313e8182 Fix focus navigation involving repeater at the end of the chain
The parent_node function doesn't reset its argument if it is already
set while calling the function
2022-04-29 16:35:46 +02:00
Olivier Goffart
723f89d342 Fix changing the size of contrained window on x11
Changing the constraint doesn't work on non-rezsizable window.
So first set the window as resizeable, then change the constraints, then
maybe remove the resizable flag
2022-04-29 11:54:31 +02:00
Olivier Goffart
b2cdd8c2a0 Fix a bunch of documentation warnings
llr::optim_passes::count_property_use is referenced by some documentation
comment and that's why it must be public
2022-04-26 12:47:34 +02:00
Olivier Goffart
da82ecf29e janitor: Remove outdated comment 2022-04-26 08:10:35 +02:00
Olivier Goffart
13b12fd0e0 Fix MCU build 2022-04-22 15:55:20 +02:00
Olivier Goffart
63b38d7f89 Move the Flickable item and implementation in the same module
The flickable module was created to hold the implementation for the Flickable
at a time were all the items lived in the items.rs module.
Now that some items moved into sub modules of items, we can also move the Flickable
in such module, alongside its implementation
2022-04-22 15:26:13 +02:00
Tobias Hunger
ddc21cb8e5
Make ItemRc::parent_item(...) return an Option<ItemRc> (#1189) 2022-04-22 14:27:34 +02:00
Tobias Hunger
a9bb0065b0 Fix forward focus movement with nested components
This used to pick the wrong node, which was then detected as a
focus loop, which in turn prevented the window from moving focus
forward.
2022-04-22 12:05:32 +02:00
Tobias Hunger
3404a20135 Split up tests to get a better overview over issues 2022-04-22 12:05:32 +02:00
Tobias Hunger
4611c33470 Add test case for nested component focus traversal 2022-04-22 12:05:32 +02:00
Tobias Hunger
7ac4231150 Focus: Do not send keyboard event to invisible widgets
Do not send keyboard events to invisible widgets, reset the keyboard
focus instead.

That fixes #798 again with a bit less of a work-around. To properly fix
this we will need to make the tab widget (and probably others) more
intelligent though.
2022-04-21 12:37:32 +02:00
Tobias Hunger
416aa42d90 Component: Replace parent_item to parent_node
Remove the `parent_item` function. After the recent changes that did not
return an item anymore and since the item tree is exposed, this function
was only used to find the repeater a component was created by.

So replace the old function with a new one that only returns the parent
node in the parent component.

This saves a few lines of generated code that is not used anymore.

Co-authored-by: Simon Hausmann <hausmann@gmail.com>
2022-04-20 14:29:18 +02:00
Olivier Goffart
fd44b2e651 Model: Do not register row data tracker if not needed
Make track_row_data_changes not register a dependency to the row
if there is currently no binding being evaluated.
2022-04-19 15:12:15 +02:00
Olivier Goffart
67e9a59398 Add a Model::row_data_tracked function
Closes #1177
2022-04-19 15:12:15 +02:00
Olivier Goffart
e85e69fda0
Declare .slint enum in one place in i-slint-common
This avoid repeating the enums both in the compiler and in
the runtime library, and register them in a bunch of other places.

So it should be easier to add enums and enum values

Since cbindgen doesn't see through the macro, generate the enum
manually
2022-04-14 19:17:48 +02:00
Simon Hausmann
5a270313d2 Improve VecModel::set_vec test
Verify the values reported by `row_count()` in the rows added/remove
callbacks.
2022-04-14 14:20:27 +02:00
Olivier Goffart
f5030cff06
Add a reset function to the model notifier 2022-04-14 14:06:34 +02:00
Simon Hausmann
2b93504b93 Fix MCU build 2022-04-14 11:31:39 +02:00
Simon Hausmann
cb2a555c90 mcu: fall back to breaking text anywhere if we can't find with given break opportunities
cc #843
2022-04-14 10:58:04 +02:00
Olivier Goffart
6c59cefa9d Property system: setting a binding must mark all dependent property as dirty
When resetting the binding, we need to mark dependent property as dirty.
It just hapenned that the current implementation always set all bindings
before starting to query the properties, so this problem was not seen
before. But there is an exception when setting the two_way bindings,
then we may set the binding after the property was querried because
setting a two way binding actually queries the property
2022-04-13 21:16:32 +02:00
Simon Hausmann
1b656ecb0d Clean up optimization to skip layers for opacity elements 2022-04-13 17:38:56 +02:00