Commit graph

75 commits

Author SHA1 Message Date
Yuri Astrakhan
5356fdcf89 Fix clippy issues, plus a few manual cleanups
* Run `cargo clippy --fix`
*  `BackendSelector` is easier to instantiate with auto `Default`
2025-02-06 17:28:51 +01:00
Olivier Goffart
c98d234b9e Janitor: Always use `#![no_std] for runtime lib
And call `extern crate std` when the feature is enabled.
I've read this is the good practice on how to do it.
So that the std prelude is no longer included automatically.
There is then less difference between std and and no-std build which
should avoid surprises in the CI when we use things from the prelude.

The downside is that there is a bit of churn in the tests
2025-01-27 19:22:00 +01:00
Simon Hausmann
0b028bfb6f
Add support for a font-metrics property to Text/TextInput. (#6452)
The struct held provides access to the design metrics of the font scaled
to the font pixel size used by the element.

ChangeLog: Slint Language: Added font-metrics property to `Text` and `TextInput`.

Closes #6047
2024-10-05 17:00:46 +02:00
Daniel Stuart
436efaceea renderer: Use TextWrap enum for text_size function 2024-06-17 23:52:04 -07:00
Daniel Stuart
bac81bf350 Add character wrapping for software renderer
This adds `char-wrap` functionality to the software renderer.
2024-06-17 23:52:04 -07:00
Daniel Stuart
9f63d157d1 Add character wrapping for Qt Backend
This adds a new wrapping mode called `char-wrap`, which allows for wrapping at any character.
Currently, it only supports the Qt backend, with the other backends falling back to `word-wrap` when this option is selected.
2024-06-17 23:52:04 -07:00
Aurindam Jana
3523e86359
Simplify commercial license (#3063)
Base the commercial license on the Royalty-free license adding clauses pertaining to the fees.
2024-05-31 14:06:17 +02:00
Aurindam Jana
9a3aa265d5
Update Royalty-free license (#5257)
Add clarification that Application may not expose Slint APIs.
2024-05-31 10:53:19 +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
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
Tobias Hunger
a8f912900b janitor: Fix warnings in nightly about redandant use 2024-02-19 17:05:21 +01:00
J-P Nurmi
8ea3153e87
SW: fix eliding of multiline text (#3612)
SW: fix eliding and vertical alignment of multiline text
2023-10-18 10:15:55 +02: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
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
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
Tobias Hunger
e02c360000 Clippy polish 2023-06-28 14:22:30 +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
Florian Blasius
6bbbdce0e5
swr: improve text cursor placement by mouse and arrow keys (#2743) 2023-05-17 11:49:24 +02:00
Simon Hausmann
8ffd17007a textlayout: Fix cursor position calculation when clicking at the end of lines with forced line break
Make sure that the byte ranges of adjancent fragments have no gaps.

Co-authored-by: Florian Blasius <FloVanGH@users.noreply.github.com>
2023-05-17 09:58:45 +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
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
6ad30c9bd4 Fix cursor_pos_for_byte_offset to return the correct x coordinate when the cursor is within the trailing whitespace of a line
Co-authored-by: Florian Blasius <FloVanGH@users.noreply.github.com>
2023-05-11 10:34:49 +00:00
Simon Hausmann
13697bc63c Implement a line-skipping shortcut for cursor_pos_for_byte_offset() 2023-05-11 10:34:49 +00:00
Simon Hausmann
51d9c08356 Add basic cursor_pos_for_byte_offset implementation for the text layout
Co-authored-by: Florian Blasius <FloVanGH@users.noreply.github.com>
2023-05-11 10:34:49 +00:00
Simon Hausmann
0fffa71af7 textlayout: Add the text byte offset to positioned glyphs 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
Tobias Hunger
3ac01c3f07 clippy: Fix clippy warnings 2023-03-09 09:35:29 +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
Olivier Goffart
9d0e90c5b1 Test that trailing newline don't add a line 2022-09-07 13:49:02 +02:00
Simon Hausmann
90ba9ffa17 Fix "glyph box" in AboutSlint when rendered on MCU
The AboutSlint text has a forced linebreak in it, which becomes a box
glyph on MCUs when the font on the host system doesn't use an empty
glyph but a box glyph for \n.

This patch explicitly excludes glyph clusters from text fragments that
feed into lines that originate from one of the three valid separators:
ascii newline, unicode paragraph and unicode line separators.
2022-09-05 21:42:26 +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
Olivier Goffart
dc7117eeb1 swrenderer: move some computation outside of loop 2022-06-08 16:36:46 +02:00
Simon Hausmann
77445e9dc5 text handling: simplify text_size signature
We can calculate the line height in the common code, that doesn't need to be done in the backends.
2022-05-16 08:21:14 +02:00
Simon Hausmann
0f06d7ea93 text handling: minor cleanup
Use a usize for the line count, not the font length.
2022-05-16 08:21:14 +02:00
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
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
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
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