diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index ab19f00ef..e1b6d5ff9 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -74,6 +74,8 @@ using cbindgen_private::PropertyAnimation; using cbindgen_private::Slice; using cbindgen_private::TextHorizontalAlignment; using cbindgen_private::TextVerticalAlignment; +using cbindgen_private::TextOverflow; +using cbindgen_private::TextWrap; using cbindgen_private::TraversalOrder; using cbindgen_private::ImageFit; using cbindgen_private::KeyEvent; diff --git a/docs/builtin_elements.md b/docs/builtin_elements.md index 0fca05617..dc510aa3b 100644 --- a/docs/builtin_elements.md +++ b/docs/builtin_elements.md @@ -121,9 +121,11 @@ A text simply show the text on the screen * **`font_family`** (*string*): The font name * **`font_size`** (*length*): The font size of the text * **`font_weight`** (*int*): The weight of the font. The values range from 100 (lightest) to 900 (thickest). 400 is the normal weight. -* **`color`** (*color*): The color of the text (default: transparent) +* **`color`** (*color*): The color of the text (default: black) * **`horizontal_alignment`** (*enum [`TextHorizontalAlignment`](#texthorizontalalignment)*): The horizontal alignment of the text. * **`vertical_alignment`** (*enum [`TextVerticalAlignment`](#textverticalalignment)*): The vertical alignment of the text. +* **`wrap`** (*enum [`TextWrap`](#textwrap)*): The way the text wraps (default: no-wrap). +* **`overflow`** (*enum [`TextOverflow`](#textoverflow)*): What happens when the text overflows (default: clip). ### Example @@ -439,9 +441,30 @@ This enum describes the different types of alignment of text along the vertical * **`TextVerticalAlignment.center`**: The text will be vertically centered within the contained box. * **`TextVerticalAlignment.bottom`** The text will be alignt to the bottom of the contained box. +## `TextWrap` + +This enum describes the how the text wrap if it is too wide to fit in the Text width. + +### Values + +* **`TextWrap.no-wrap`**: The text will not wrap, but instead will overflow. +* **`TextWrap.word-wrap`**: The text will be wrapped at word boundaries. + +## `TextOverflow` + +This enum describes the how the text appear if it is too wide to fit in the Text width. + +### Values + +* **`TextWrap.clip`**: The text will simpli be clipped. +* **`TextWrap.elide`**: The text will be ellided with `…`. + ## `EventResult` This enum describes whether an event was rejected or accepted by an event handler. +### Values + * **`EventResult.reject`**: The event is rejected by this event handler and may then be handled by parent item * **`EventResult.accept`**: The event is accepted and won't be processed further + diff --git a/sixtyfps_compiler/builtins.60 b/sixtyfps_compiler/builtins.60 index e4c354534..137f81093 100644 --- a/sixtyfps_compiler/builtins.60 +++ b/sixtyfps_compiler/builtins.60 @@ -62,6 +62,8 @@ export Text := _ { property color: #000; property horizontal_alignment; property vertical_alignment; + property overflow; + property wrap; property x; property y; property width; diff --git a/sixtyfps_compiler/typeregister.rs b/sixtyfps_compiler/typeregister.rs index 60dbd3ac4..9ea28c45f 100644 --- a/sixtyfps_compiler/typeregister.rs +++ b/sixtyfps_compiler/typeregister.rs @@ -117,6 +117,8 @@ impl TypeRegister { declare_enum("TextHorizontalAlignment", &["left", "center", "right"]); declare_enum("TextVerticalAlignment", &["top", "center", "bottom"]); + declare_enum("TextWrap", &["no_wrap", "word_wrap"]); + declare_enum("TextOverflow", &["clip", "elide"]); declare_enum( "LayoutAlignment", &["stretch", "center", "start", "end", "space_between", "space_around"], diff --git a/sixtyfps_runtime/corelib/items/text.rs b/sixtyfps_runtime/corelib/items/text.rs index 42eb584c8..da056e300 100644 --- a/sixtyfps_runtime/corelib/items/text.rs +++ b/sixtyfps_runtime/corelib/items/text.rs @@ -67,6 +67,34 @@ impl Default for TextVerticalAlignment { } } +#[derive(Copy, Clone, Debug, PartialEq, strum_macros::EnumString, strum_macros::Display)] +#[repr(C)] +#[allow(non_camel_case_types)] +pub enum TextWrap { + no_wrap, + word_wrap, +} + +impl Default for TextWrap { + fn default() -> Self { + Self::no_wrap + } +} + +#[derive(Copy, Clone, Debug, PartialEq, strum_macros::EnumString, strum_macros::Display)] +#[repr(C)] +#[allow(non_camel_case_types)] +pub enum TextOverflow { + clip, + elide, +} + +impl Default for TextOverflow { + fn default() -> Self { + Self::clip + } +} + /// The implementation of the `Text` element #[repr(C)] #[derive(FieldOffsets, Default, SixtyFPSElement)] @@ -79,6 +107,8 @@ pub struct Text { pub color: Property, pub horizontal_alignment: Property, pub vertical_alignment: Property, + pub wrap: Property, + pub overflow: Property, pub x: Property, pub y: Property, pub width: Property, diff --git a/sixtyfps_runtime/corelib/rtti.rs b/sixtyfps_runtime/corelib/rtti.rs index 1d826007f..2e4e1329c 100644 --- a/sixtyfps_runtime/corelib/rtti.rs +++ b/sixtyfps_runtime/corelib/rtti.rs @@ -38,6 +38,8 @@ declare_ValueType![ crate::animations::EasingCurve, crate::items::TextHorizontalAlignment, crate::items::TextVerticalAlignment, + crate::items::TextOverflow, + crate::items::TextWrap, crate::model::StandardListViewItem, crate::items::ImageFit, crate::input::KeyEvent, diff --git a/sixtyfps_runtime/interpreter/dynamic_component.rs b/sixtyfps_runtime/interpreter/dynamic_component.rs index 1e5d5b531..333191fbf 100644 --- a/sixtyfps_runtime/interpreter/dynamic_component.rs +++ b/sixtyfps_runtime/interpreter/dynamic_component.rs @@ -638,6 +638,8 @@ fn generate_component<'id>( "TextVerticalAlignment" => { property_info::() } + "TextWrap" => property_info::(), + "TextOverflow" => property_info::(), "ImageFit" => property_info::(), _ => panic!("unkown enum"), }, diff --git a/sixtyfps_runtime/interpreter/eval.rs b/sixtyfps_runtime/interpreter/eval.rs index 5b6c045c3..f45d325e0 100644 --- a/sixtyfps_runtime/interpreter/eval.rs +++ b/sixtyfps_runtime/interpreter/eval.rs @@ -244,6 +244,8 @@ macro_rules! declare_value_enum_conversion { declare_value_enum_conversion!(corelib::items::TextHorizontalAlignment, TextHorizontalAlignment); declare_value_enum_conversion!(corelib::items::TextVerticalAlignment, TextVerticalAlignment); +declare_value_enum_conversion!(corelib::items::TextOverflow, TextOverflow); +declare_value_enum_conversion!(corelib::items::TextWrap, TextWrap); declare_value_enum_conversion!(corelib::layout::LayoutAlignment, LayoutAlignment); declare_value_enum_conversion!(corelib::items::ImageFit, ImageFit); declare_value_enum_conversion!(corelib::input::KeyEventType, KeyEventType); diff --git a/tests/driver_lib/cbindgen.rs b/tests/driver_lib/cbindgen.rs index fdd695f69..273b2d4c0 100644 --- a/tests/driver_lib/cbindgen.rs +++ b/tests/driver_lib/cbindgen.rs @@ -65,6 +65,8 @@ fn gen_corelib(include_dir: &Path) -> anyhow::Result<()> { "EasingCurve", "TextHorizontalAlignment", "TextVerticalAlignment", + "TextOverflow", + "TextWrap", "ImageFit", "Window", "TextInput",