Skip to content

Commit 4923354

Browse files
committed
add StyledText Type and Value
1 parent 374e2b6 commit 4923354

File tree

7 files changed

+19
-2
lines changed

7 files changed

+19
-2
lines changed

internal/compiler/builtin_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ fn to_debug_string(
420420
}
421421
}
422422
Type::Enumeration(_) => Expression::Cast { from: Box::new(expr), to: (Type::String) },
423+
Type::StyledText => Expression::Invalid,
423424
}
424425
}
425426

internal/compiler/expression_tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ declare_builtin_function_types!(
281281
RestartTimer: (Type::ElementReference) -> Type::Void,
282282
OpenUrl: (Type::String) -> Type::Void,
283283
EscapeMarkdown: (Type::String) -> Type::String,
284-
ParseMarkdown: (Type::String) -> Type::String
284+
ParseMarkdown: (Type::String) -> Type::StyledText
285285
);
286286

287287
impl BuiltinFunction {
@@ -1434,6 +1434,7 @@ impl Expression {
14341434
Expression::EnumerationValue(enumeration.clone().default_value())
14351435
}
14361436
Type::ComponentFactory => Expression::EmptyComponentFactory,
1437+
Type::StyledText => Expression::Invalid,
14371438
}
14381439
}
14391440

internal/compiler/langtype.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub enum Type {
6464

6565
/// This is a `SharedArray<f32>`
6666
LayoutCache,
67+
68+
StyledText,
6769
}
6870

6971
impl core::cmp::PartialEq for Type {
@@ -104,6 +106,7 @@ impl core::cmp::PartialEq for Type {
104106
Type::UnitProduct(a) => matches!(other, Type::UnitProduct(b) if a == b),
105107
Type::ElementReference => matches!(other, Type::ElementReference),
106108
Type::LayoutCache => matches!(other, Type::LayoutCache),
109+
Type::StyledText => matches!(other, Type::StyledText),
107110
}
108111
}
109112
}
@@ -178,6 +181,7 @@ impl Display for Type {
178181
}
179182
Type::ElementReference => write!(f, "element ref"),
180183
Type::LayoutCache => write!(f, "layout cache"),
184+
Type::StyledText => write!(f, "styled-text"),
181185
}
182186
}
183187
}
@@ -213,6 +217,7 @@ impl Type {
213217
| Self::Array(_)
214218
| Self::Brush
215219
| Self::InferredProperty
220+
| Self::StyledText
216221
)
217222
}
218223

@@ -314,6 +319,7 @@ impl Type {
314319
Type::UnitProduct(_) => None,
315320
Type::ElementReference => None,
316321
Type::LayoutCache => None,
322+
Type::StyledText => None,
317323
}
318324
}
319325

internal/compiler/llr/expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl Expression {
267267
Expression::EnumerationValue(enumeration.clone().default_value())
268268
}
269269
Type::ComponentFactory => Expression::EmptyComponentFactory,
270+
Type::StyledText => return None,
270271
})
271272
}
272273

internal/interpreter/api.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub enum ValueType {
5151
Brush,
5252
/// Correspond to `image` type in .slint.
5353
Image,
54+
StyledText,
5455
/// The type is not a public type but something internal.
5556
#[doc(hidden)]
5657
Other = -1,
@@ -128,6 +129,7 @@ pub enum Value {
128129
#[doc(hidden)]
129130
/// Correspond to the `component-factory` type in .slint
130131
ComponentFactory(ComponentFactory) = 12,
132+
StyledText(()) = 13,
131133
}
132134

133135
impl Value {
@@ -173,6 +175,9 @@ impl PartialEq for Value {
173175
Value::ComponentFactory(lhs) => {
174176
matches!(other, Value::ComponentFactory(rhs) if lhs == rhs)
175177
}
178+
Value::StyledText(lhs) => {
179+
matches!(other, Value::StyledText(rhs) if lhs == rhs)
180+
}
176181
}
177182
}
178183
}
@@ -197,6 +202,7 @@ impl std::fmt::Debug for Value {
197202
Value::EnumerationValue(n, v) => write!(f, "Value::EnumerationValue({n:?}, {v:?})"),
198203
Value::LayoutCache(v) => write!(f, "Value::LayoutCache({v:?})"),
199204
Value::ComponentFactory(factory) => write!(f, "Value::ComponentFactory({factory:?})"),
205+
Value::StyledText(text) => write!(f, "Value::StyledText({text:?})"),
200206
}
201207
}
202208
}

internal/interpreter/dynamic_item_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ pub(crate) fn generate_item_tree<'id>(
12541254
}
12551255
Type::LayoutCache => property_info::<SharedVector<f32>>(),
12561256
Type::Function { .. } | Type::Callback { .. } => return None,
1257-
1257+
Type::StyledText => property_info::<Value>(),
12581258
// These can't be used in properties
12591259
Type::Invalid
12601260
| Type::Void

internal/interpreter/eval.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,7 @@ fn check_value_type(value: &Value, ty: &Type) -> bool {
17311731
}
17321732
Type::LayoutCache => matches!(value, Value::LayoutCache(_)),
17331733
Type::ComponentFactory => matches!(value, Value::ComponentFactory(_)),
1734+
Type::StyledText => matches!(value, Value::StyledText(_)),
17341735
}
17351736
}
17361737

@@ -2031,6 +2032,7 @@ pub fn default_value_for_type(ty: &Type) -> Value {
20312032
| Type::Function { .. } => {
20322033
panic!("There can't be such property")
20332034
}
2035+
Type::StyledText => Value::StyledText(Default::default()),
20342036
}
20352037
}
20362038

0 commit comments

Comments
 (0)