Skip to content

Commit e86119c

Browse files
Add StyledText type (#10122)
* Add StyledText type * Move to styled-text.rs * Apply suggestions * Don't gate around experimental-rich-text feature * Gate pulldown_cmark behind std * [autofix.ci] apply automated fixes * Make thiserror optional * Make htmlparser optional * Gate color-parsing feature * [autofix.ci] apply automated fixes * Change flags * Change to pub(crate) * [autofix.ci] apply automated fixes * Better docs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 6593f11 commit e86119c

File tree

14 files changed

+590
-5
lines changed

14 files changed

+590
-5
lines changed

api/node/rust/interpreter/value.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum JsValueType {
2525
Struct,
2626
Brush,
2727
Image,
28+
StyledText,
2829
}
2930

3031
impl From<slint_interpreter::ValueType> for JsValueType {
@@ -37,6 +38,7 @@ impl From<slint_interpreter::ValueType> for JsValueType {
3738
slint_interpreter::ValueType::Struct => JsValueType::Struct,
3839
slint_interpreter::ValueType::Brush => JsValueType::Brush,
3940
slint_interpreter::ValueType::Image => JsValueType::Image,
41+
slint_interpreter::ValueType::StyledText => JsValueType::StyledText,
4042
_ => JsValueType::Void,
4143
}
4244
}
@@ -290,7 +292,8 @@ pub fn to_value(env: &Env, unknown: JsUnknown, typ: &Type) -> Result<Value> {
290292
| Type::Easing
291293
| Type::PathData
292294
| Type::LayoutCache
293-
| Type::ElementReference => Err(napi::Error::from_reason("reason")),
295+
| Type::ElementReference
296+
| Type::StyledText => Err(napi::Error::from_reason("reason")),
294297
}
295298
}
296299

internal/compiler/builtin_macros.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ fn to_debug_string(
343343
Type::Float32 | Type::Int32 => expr.maybe_convert_to(Type::String, node, diag),
344344
Type::String => expr,
345345
// TODO
346-
Type::Color | Type::Brush | Type::Image | Type::Easing | Type::Array(_) => {
346+
Type::Color
347+
| Type::Brush
348+
| Type::Image
349+
| Type::Easing
350+
| Type::StyledText
351+
| Type::Array(_) => {
347352
Expression::StringLiteral("<debug-of-this-type-not-yet-implemented>".into())
348353
}
349354
Type::Duration

internal/compiler/expression_tree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@ impl Expression {
14501450
Expression::EnumerationValue(enumeration.clone().default_value())
14511451
}
14521452
Type::ComponentFactory => Expression::EmptyComponentFactory,
1453+
Type::StyledText => Expression::Invalid,
14531454
}
14541455
}
14551456

internal/compiler/generator/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub fn rust_primitive_type(ty: &Type) -> Option<proc_macro2::TokenStream> {
9191
Type::Percent => Some(quote!(f32)),
9292
Type::Bool => Some(quote!(bool)),
9393
Type::Image => Some(quote!(sp::Image)),
94+
Type::StyledText => Some(quote!(sp::StyledText)),
9495
Type::Struct(s) => {
9596
struct_name_to_tokens(&s.name).or_else(|| {
9697
let elem =

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
@@ -258,6 +258,7 @@ impl Expression {
258258
Expression::EnumerationValue(enumeration.clone().default_value())
259259
}
260260
Type::ComponentFactory => Expression::EmptyComponentFactory,
261+
Type::StyledText => return None,
261262
})
262263
}
263264

internal/compiler/typeregister.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ impl TypeRegister {
403403
register.insert_type(Type::Angle);
404404
register.insert_type(Type::Brush);
405405
register.insert_type(Type::Rem);
406+
register.insert_type(Type::StyledText);
406407
register.types.insert("Point".into(), logical_point_type().into());
407408

408409
BUILTIN.with(|e| e.enums.fill_register(&mut register));

internal/core/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ std = [
4444
"dep:sys-locale",
4545
"dep:webbrowser",
4646
"shared-fontique",
47+
"dep:pulldown-cmark",
48+
"dep:thiserror",
49+
"dep:htmlparser",
50+
"i-slint-common/color-parsing",
4751
]
4852
# Unsafe feature meaning that there is only one core running and all thread_local are static.
4953
# You can only enable this feature if you are sure that any API of this crate is only called
@@ -68,7 +72,7 @@ raw-window-handle-06 = ["dep:raw-window-handle-06"]
6872

6973
experimental = []
7074

71-
experimental-rich-text = ["dep:pulldown-cmark", "dep:htmlparser", "dep:thiserror", "i-slint-common/color-parsing"]
75+
experimental-rich-text = []
7276

7377
unstable-wgpu-26 = ["dep:wgpu-26"]
7478
unstable-wgpu-27 = ["dep:wgpu-27"]

internal/core/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use crate::window::{WindowAdapter, WindowInner};
1515
use alloc::boxed::Box;
1616
use alloc::string::String;
1717

18+
mod styled_text;
19+
pub use styled_text::*;
20+
1821
/// A position represented in the coordinate space of logical pixels. That is the space before applying
1922
/// a display device specific scale factor.
2023
#[derive(Debug, Default, Copy, Clone, PartialEq)]

0 commit comments

Comments
 (0)