Skip to content

Commit 9877fe8

Browse files
committed
add StyledText Type and Value
1 parent 98907e2 commit 9877fe8

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
@@ -418,6 +418,7 @@ fn to_debug_string(
418418
}
419419
}
420420
Type::Enumeration(_) => Expression::Cast { from: Box::new(expr), to: (Type::String) },
421+
Type::StyledText => Expression::Invalid,
421422
}
422423
}
423424

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 {
@@ -1429,6 +1429,7 @@ impl Expression {
14291429
Expression::EnumerationValue(enumeration.clone().default_value())
14301430
}
14311431
Type::ComponentFactory => Expression::EmptyComponentFactory,
1432+
Type::StyledText => Expression::Invalid,
14321433
}
14331434
}
14341435

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
@@ -265,6 +265,7 @@ impl Expression {
265265
Expression::EnumerationValue(enumeration.clone().default_value())
266266
}
267267
Type::ComponentFactory => Expression::EmptyComponentFactory,
268+
Type::StyledText => return None,
268269
})
269270
}
270271

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
@@ -1253,7 +1253,7 @@ pub(crate) fn generate_item_tree<'id>(
12531253
}
12541254
Type::LayoutCache => property_info::<SharedVector<f32>>(),
12551255
Type::Function { .. } | Type::Callback { .. } => return None,
1256-
1256+
Type::StyledText => property_info::<Value>(),
12571257
// These can't be used in properties
12581258
Type::Invalid
12591259
| Type::Void

internal/interpreter/eval.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ fn check_value_type(value: &Value, ty: &Type) -> bool {
17271727
}
17281728
Type::LayoutCache => matches!(value, Value::LayoutCache(_)),
17291729
Type::ComponentFactory => matches!(value, Value::ComponentFactory(_)),
1730+
Type::StyledText => matches!(value, Value::StyledText(_)),
17301731
}
17311732
}
17321733

@@ -2027,6 +2028,7 @@ pub fn default_value_for_type(ty: &Type) -> Value {
20272028
| Type::Function { .. } => {
20282029
panic!("There can't be such property")
20292030
}
2031+
Type::StyledText => Value::StyledText(Default::default()),
20302032
}
20312033
}
20322034

0 commit comments

Comments
 (0)