Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api/cpp/cbindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ fn gen_corelib(
"Flickable",
"SimpleText",
"ComplexText",
"MarkdownText",
"Path",
"WindowItem",
"TextInput",
Expand Down
5 changes: 4 additions & 1 deletion api/node/rust/interpreter/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum JsValueType {
Struct,
Brush,
Image,
StyledText,
}

impl From<slint_interpreter::ValueType> for JsValueType {
Expand All @@ -37,6 +38,7 @@ impl From<slint_interpreter::ValueType> for JsValueType {
slint_interpreter::ValueType::Struct => JsValueType::Struct,
slint_interpreter::ValueType::Brush => JsValueType::Brush,
slint_interpreter::ValueType::Image => JsValueType::Image,
slint_interpreter::ValueType::StyledText => JsValueType::StyledText,
_ => JsValueType::Void,
}
}
Expand Down Expand Up @@ -290,7 +292,8 @@ pub fn to_value(env: &Env, unknown: JsUnknown, typ: &Type) -> Result<Value> {
| Type::Easing
| Type::PathData
| Type::LayoutCache
| Type::ElementReference => Err(napi::Error::from_reason("reason")),
| Type::ElementReference
| Type::StyledText => Err(napi::Error::from_reason("reason")),
}
}

Expand Down
7 changes: 6 additions & 1 deletion internal/backends/testing/testing_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use i_slint_core::api::PhysicalSize;
use i_slint_core::graphics::euclid::{Point2D, Size2D};
use i_slint_core::item_rendering::PlainOrStyledText;
use i_slint_core::lengths::{LogicalLength, LogicalPoint, LogicalRect, LogicalSize};
use i_slint_core::platform::PlatformError;
use i_slint_core::renderer::{Renderer, RendererSealed};
Expand Down Expand Up @@ -164,7 +165,11 @@ impl RendererSealed for TestingWindow {
_max_width: Option<LogicalLength>,
_text_wrap: TextWrap,
) -> LogicalSize {
LogicalSize::new(text_item.text().len() as f32 * 10., 10.)
if let PlainOrStyledText::Plain(text) = text_item.text() {
LogicalSize::new(text.len() as f32 * 10., 10.)
} else {
Default::default()
}
}

fn char_size(
Expand Down
7 changes: 6 additions & 1 deletion internal/compiler/builtin_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ fn to_debug_string(
Type::Float32 | Type::Int32 => expr.maybe_convert_to(Type::String, node, diag),
Type::String => expr,
// TODO
Type::Color | Type::Brush | Type::Image | Type::Easing | Type::Array(_) => {
Type::Color
| Type::Brush
| Type::Image
| Type::Easing
| Type::StyledText
| Type::Array(_) => {
Expression::StringLiteral("<debug-of-this-type-not-yet-implemented>".into())
}
Type::Duration
Expand Down
6 changes: 4 additions & 2 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ component ComplexText inherits SimpleText {

export { ComplexText as Text }

export component MarkdownText inherits Empty {
component StyledTextItem inherits Empty {
in property <length> width;
in property <length> height;
in property <string> text;
in property <styled-text> text;
in property <length> font-size;
in property <int> font-weight;
in property <brush> color;
Expand All @@ -143,6 +143,8 @@ export component MarkdownText inherits Empty {
//-default_size_binding:implicit_size
}

export { StyledTextItem as StyledText }

export component TouchArea {
in property <bool> enabled: true;
out property <bool> pressed;
Expand Down
9 changes: 8 additions & 1 deletion internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub enum BuiltinFunction {
StopTimer,
RestartTimer,
OpenUrl,
ParseMarkdown,
EscapeMarkdown,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -276,7 +278,9 @@ declare_builtin_function_types!(
StartTimer: (Type::ElementReference) -> Type::Void,
StopTimer: (Type::ElementReference) -> Type::Void,
RestartTimer: (Type::ElementReference) -> Type::Void,
OpenUrl: (Type::String) -> Type::Void
OpenUrl: (Type::String) -> Type::Void,
EscapeMarkdown: (Type::String) -> Type::String,
ParseMarkdown: (Type::String) -> Type::StyledText
);

impl BuiltinFunction {
Expand Down Expand Up @@ -373,6 +377,7 @@ impl BuiltinFunction {
BuiltinFunction::StopTimer => false,
BuiltinFunction::RestartTimer => false,
BuiltinFunction::OpenUrl => false,
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => false,
}
}

Expand Down Expand Up @@ -451,6 +456,7 @@ impl BuiltinFunction {
BuiltinFunction::StopTimer => false,
BuiltinFunction::RestartTimer => false,
BuiltinFunction::OpenUrl => false,
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => true,
}
}
}
Expand Down Expand Up @@ -1427,6 +1433,7 @@ impl Expression {
Expression::EnumerationValue(enumeration.clone().default_value())
}
Type::ComponentFactory => Expression::EmptyComponentFactory,
Type::StyledText => Expression::Invalid,
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/compiler/generator/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4230,6 +4230,14 @@ fn compile_builtin_function_call(
let url = a.next().unwrap();
format!("slint::cbindgen_private::open_url({})", url)
}
BuiltinFunction::EscapeMarkdown => {
let text = a.next().unwrap();
format!("slint::cbindgen_private::escape_markdown({})", text)
}
BuiltinFunction::ParseMarkdown => {
let text = a.next().unwrap();
format!("slint::cbindgen_private::parse_markdown({})", text)
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions internal/compiler/generator/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn rust_primitive_type(ty: &Type) -> Option<proc_macro2::TokenStream> {
Type::Percent => Some(quote!(f32)),
Type::Bool => Some(quote!(bool)),
Type::Image => Some(quote!(sp::Image)),
Type::StyledText => Some(quote!(sp::StyledText)),
Type::Struct(s) => {
struct_name_to_tokens(&s.name).or_else(|| {
let elem =
Expand Down Expand Up @@ -3402,6 +3403,14 @@ fn compile_builtin_function_call(
let url = a.next().unwrap();
quote!(sp::open_url(&#url))
}
BuiltinFunction::EscapeMarkdown => {
let text = a.next().unwrap();
quote!(sp::escape_markdown(&#text))
}
BuiltinFunction::ParseMarkdown => {
let text = a.next().unwrap();
quote!(sp::parse_markdown(&#text))
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/compiler/langtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub enum Type {

/// This is a `SharedArray<f32>`
LayoutCache,

StyledText,
}

impl core::cmp::PartialEq for Type {
Expand Down Expand Up @@ -104,6 +106,7 @@ impl core::cmp::PartialEq for Type {
Type::UnitProduct(a) => matches!(other, Type::UnitProduct(b) if a == b),
Type::ElementReference => matches!(other, Type::ElementReference),
Type::LayoutCache => matches!(other, Type::LayoutCache),
Type::StyledText => matches!(other, Type::StyledText),
}
}
}
Expand Down Expand Up @@ -178,6 +181,7 @@ impl Display for Type {
}
Type::ElementReference => write!(f, "element ref"),
Type::LayoutCache => write!(f, "layout cache"),
Type::StyledText => write!(f, "styled-text"),
}
}
}
Expand Down Expand Up @@ -213,6 +217,7 @@ impl Type {
| Self::Array(_)
| Self::Brush
| Self::InferredProperty
| Self::StyledText
)
}

Expand Down Expand Up @@ -314,6 +319,7 @@ impl Type {
Type::UnitProduct(_) => None,
Type::ElementReference => None,
Type::LayoutCache => None,
Type::StyledText => None,
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/llr/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl Expression {
Expression::EnumerationValue(enumeration.clone().default_value())
}
Type::ComponentFactory => Expression::EmptyComponentFactory,
Type::StyledText => return None,
})
}

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/llr/optim_passes/inline_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
BuiltinFunction::StopTimer => 10,
BuiltinFunction::RestartTimer => 10,
BuiltinFunction::OpenUrl => isize::MAX,
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => isize::MAX,
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ declare_syntax! {
AtGradient -> [*Expression],
/// `@tr("foo", ...)` // the string is a StringLiteral
AtTr -> [?TrContext, ?TrPlural, *Expression],
AtMarkdown -> [*Expression],
/// `"foo" =>` in a `AtTr` node
TrContext -> [],
/// `| "foo" % n` in a `AtTr` node
Expand Down
34 changes: 34 additions & 0 deletions internal/compiler/parser/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ fn parse_at_keyword(p: &mut impl Parser) {
"tr" => {
parse_tr(p);
}
"markdown" => {
parse_markdown(p);
}
_ => {
p.consume();
p.test(SyntaxKind::Identifier); // consume the identifier, so that autocomplete works
Expand Down Expand Up @@ -438,6 +441,37 @@ fn parse_tr(p: &mut impl Parser) {
p.expect(SyntaxKind::RParent);
}

fn parse_markdown(p: &mut impl Parser) {
let mut p = p.start_node(SyntaxKind::AtMarkdown);
p.expect(SyntaxKind::At);
debug_assert!(p.peek().as_str().ends_with("markdown"));
p.expect(SyntaxKind::Identifier); //eg "markdown"
p.expect(SyntaxKind::LParent);

fn consume_literal(p: &mut impl Parser) -> bool {
let peek = p.peek();
if peek.kind() != SyntaxKind::StringLiteral
|| !peek.as_str().starts_with('"')
|| !peek.as_str().ends_with('"')
{
p.error("Expected plain string literal");
return false;
}
p.expect(SyntaxKind::StringLiteral)
}

if !consume_literal(&mut *p) {
return;
}

while p.test(SyntaxKind::Comma) {
if !parse_expression(&mut *p) {
break;
}
}
p.expect(SyntaxKind::RParent);
}

#[cfg_attr(test, parser_test)]
/// ```test,AtImageUrl
/// @image-url("foo.png")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn apply_default_properties_from_style(
}
});
}
"Text" | "MarkdownText" => {
"Text" | "StyledText" => {
elem.set_binding_if_not_set("color".into(), || Expression::Cast {
from: Expression::PropertyReference(NamedReference::new(
&palette.root_element,
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/passes/embed_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ pub fn collect_font_sizes_used(
.to_string()
.as_str()
{
"TextInput" | "Text" | "SimpleText" | "ComplexText" | "MarkdownText" => {
"TextInput" | "Text" | "SimpleText" | "ComplexText" | "StyledText" => {
if let Some(font_size) = try_extract_font_size_from_element(elem, "font-size") {
add_font_size(font_size)
}
Expand Down
Loading
Loading