Skip to content

Commit

Permalink
Split Text item into SimpleText and ComplexText
Browse files Browse the repository at this point in the history
SimpleText has all the most common properties and is half the size
  • Loading branch information
ogoffart committed Jul 5, 2024
1 parent 8b5df70 commit 35a6e7b
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 76 deletions.
3 changes: 2 additions & 1 deletion api/cpp/cbindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ fn gen_corelib(
"TouchArea",
"FocusScope",
"Flickable",
"Text",
"SimpleText",
"ComplexText",
"Path",
"WindowItem",
"TextInput",
Expand Down
14 changes: 10 additions & 4 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ export component Rotate inherits Empty {
//-is_internal
}

export component Text inherits Empty {
component SimpleText inherits Empty {
in property <length> width;
in property <length> height;
in property <string> text;
in property <string> font-family;
in property <length> font-size;
in property <bool> font-italic;
in property <int> font-weight;
in property <brush> color; // StyleMetrics.default-text-color set in apply_default_properties_from_style
in property <TextHorizontalAlignment> horizontal-alignment;
in property <TextVerticalAlignment> vertical-alignment;
//-default_size_binding:implicit_size
}

component ComplexText inherits SimpleText {
in property <string> font-family;
in property <bool> font-italic;
in property <TextOverflow> overflow;
in property <TextWrap> wrap;
in property <length> letter-spacing;
Expand All @@ -108,6 +112,8 @@ export component Text inherits Empty {
//-default_size_binding:implicit_size
}

export { ComplexText as Text }

export component TouchArea {
in property <bool> enabled: true;
out property <bool> pressed;
Expand Down Expand Up @@ -420,7 +426,7 @@ export component NativeSpinBox {
in-out property <int> value;
in property <int> minimum;
in property <int> maximum: 100;
in property <int> step-size: 1;
in property <int> step-size: 1;
callback edited(int /* value */);
//-is_internal
//-accepts_focus
Expand Down
3 changes: 1 addition & 2 deletions internal/compiler/passes/check_rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub fn check_rotation(doc: &crate::object_tree::Document, diag: &mut BuildDiagno
.iter()
.any(|(property_name, _)| is_property_set(&e, property_name))
{
if matches!(e.native_class(), Some(native) if native.class_name != "ClippedImage" && native.class_name != "Text")
{
if !e.builtin_type().is_some_and(|b| matches!(b.name.as_str(), "Image" | "Text")) {
let span = e
.bindings
.get("rotation-angle")
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/passes/embed_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ pub fn collect_font_sizes_used(
.to_string()
.as_str()
{
"TextInput" | "Text" => {
"TextInput" | "Text" | "SimpleText" | "ComplexText" => {
if let Some(font_size) = try_extract_font_size_from_element(elem, "font-size") {
add_font_size(font_size)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/core/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,11 @@ declare_item_vtable! {
}

declare_item_vtable! {
fn slint_get_TextVTable() -> TextVTable for Text
fn slint_get_ComplexTextVTable() -> ComplexTextVTable for ComplexText
}

declare_item_vtable! {
fn slint_get_SimpleTextVTable() -> SimpleTextVTable for SimpleText
}

declare_item_vtable! {
Expand Down
Loading

0 comments on commit 35a6e7b

Please sign in to comment.