mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Add TextWrap and TextOverflow enum and corresponding property in Text
Although they ar enot working yet
This commit is contained in:
parent
edcd4b1d0b
commit
647f7effcd
9 changed files with 68 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ export Text := _ {
|
|||
property <color> color: #000;
|
||||
property <TextHorizontalAlignment> horizontal_alignment;
|
||||
property <TextVerticalAlignment> vertical_alignment;
|
||||
property <TextOverflow> overflow;
|
||||
property <TextWrap> wrap;
|
||||
property <length> x;
|
||||
property <length> y;
|
||||
property <length> width;
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -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<Color>,
|
||||
pub horizontal_alignment: Property<TextHorizontalAlignment>,
|
||||
pub vertical_alignment: Property<TextVerticalAlignment>,
|
||||
pub wrap: Property<TextWrap>,
|
||||
pub overflow: Property<TextOverflow>,
|
||||
pub x: Property<f32>,
|
||||
pub y: Property<f32>,
|
||||
pub width: Property<f32>,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -638,6 +638,8 @@ fn generate_component<'id>(
|
|||
"TextVerticalAlignment" => {
|
||||
property_info::<sixtyfps_corelib::items::TextVerticalAlignment>()
|
||||
}
|
||||
"TextWrap" => property_info::<sixtyfps_corelib::items::TextWrap>(),
|
||||
"TextOverflow" => property_info::<sixtyfps_corelib::items::TextOverflow>(),
|
||||
"ImageFit" => property_info::<sixtyfps_corelib::items::ImageFit>(),
|
||||
_ => panic!("unkown enum"),
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -65,6 +65,8 @@ fn gen_corelib(include_dir: &Path) -> anyhow::Result<()> {
|
|||
"EasingCurve",
|
||||
"TextHorizontalAlignment",
|
||||
"TextVerticalAlignment",
|
||||
"TextOverflow",
|
||||
"TextWrap",
|
||||
"ImageFit",
|
||||
"Window",
|
||||
"TextInput",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue