Skip to content

Commit b004797

Browse files
committed
Merge with master
2 parents e86119c + feac54a commit b004797

File tree

22 files changed

+330
-608
lines changed

22 files changed

+330
-608
lines changed

api/cpp/cbindgen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ fn gen_corelib(
305305
"Flickable",
306306
"SimpleText",
307307
"ComplexText",
308-
"MarkdownText",
309308
"Path",
310309
"WindowItem",
311310
"TextInput",

internal/backends/testing/testing_backend.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use i_slint_core::api::PhysicalSize;
55
use i_slint_core::graphics::euclid::{Point2D, Size2D};
6+
use i_slint_core::item_rendering::PlainOrStyledText;
67
use i_slint_core::lengths::{LogicalLength, LogicalPoint, LogicalRect, LogicalSize};
78
use i_slint_core::platform::PlatformError;
89
use i_slint_core::renderer::{Renderer, RendererSealed};
@@ -164,7 +165,11 @@ impl RendererSealed for TestingWindow {
164165
_max_width: Option<LogicalLength>,
165166
_text_wrap: TextWrap,
166167
) -> LogicalSize {
167-
LogicalSize::new(text_item.text().len() as f32 * 10., 10.)
168+
if let PlainOrStyledText::Plain(text) = text_item.text() {
169+
LogicalSize::new(text.len() as f32 * 10., 10.)
170+
} else {
171+
Default::default()
172+
}
168173
}
169174

170175
fn char_size(

internal/compiler/builtins.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ component ComplexText inherits SimpleText {
120120

121121
export { ComplexText as Text }
122122

123-
export component MarkdownText inherits Empty {
123+
component StyledTextItem inherits Empty {
124124
in property <length> width;
125125
in property <length> height;
126-
in property <string> text;
126+
in property <styled-text> text;
127127
in property <length> font-size;
128128
in property <int> font-weight;
129129
in property <brush> color;
@@ -143,6 +143,8 @@ export component MarkdownText inherits Empty {
143143
//-default_size_binding:implicit_size
144144
}
145145

146+
export { StyledTextItem as StyledText }
147+
146148
export component TouchArea {
147149
in property <bool> enabled: true;
148150
out property <bool> pressed;

internal/compiler/expression_tree.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ pub enum BuiltinFunction {
114114
StopTimer,
115115
RestartTimer,
116116
OpenUrl,
117+
ParseMarkdown,
118+
EscapeMarkdown,
117119
}
118120

119121
#[derive(Debug, Clone)]
@@ -273,7 +275,9 @@ declare_builtin_function_types!(
273275
StartTimer: (Type::ElementReference) -> Type::Void,
274276
StopTimer: (Type::ElementReference) -> Type::Void,
275277
RestartTimer: (Type::ElementReference) -> Type::Void,
276-
OpenUrl: (Type::String) -> Type::Void
278+
OpenUrl: (Type::String) -> Type::Void,
279+
EscapeMarkdown: (Type::String) -> Type::String,
280+
ParseMarkdown: (Type::String) -> Type::StyledText
277281
);
278282

279283
impl BuiltinFunction {
@@ -370,6 +374,7 @@ impl BuiltinFunction {
370374
BuiltinFunction::StopTimer => false,
371375
BuiltinFunction::RestartTimer => false,
372376
BuiltinFunction::OpenUrl => false,
377+
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => false,
373378
}
374379
}
375380

@@ -448,6 +453,7 @@ impl BuiltinFunction {
448453
BuiltinFunction::StopTimer => false,
449454
BuiltinFunction::RestartTimer => false,
450455
BuiltinFunction::OpenUrl => false,
456+
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => true,
451457
}
452458
}
453459
}

internal/compiler/generator/cpp.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,6 +4213,14 @@ fn compile_builtin_function_call(
42134213
let url = a.next().unwrap();
42144214
format!("slint::cbindgen_private::open_url({})", url)
42154215
}
4216+
BuiltinFunction::EscapeMarkdown => {
4217+
let text = a.next().unwrap();
4218+
format!("slint::cbindgen_private::escape_markdown({})", text)
4219+
}
4220+
BuiltinFunction::ParseMarkdown => {
4221+
let text = a.next().unwrap();
4222+
format!("slint::cbindgen_private::parse_markdown({})", text)
4223+
}
42164224
}
42174225
}
42184226

internal/compiler/generator/rust.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,14 @@ fn compile_builtin_function_call(
33833383
let url = a.next().unwrap();
33843384
quote!(sp::open_url(&#url))
33853385
}
3386+
BuiltinFunction::EscapeMarkdown => {
3387+
let text = a.next().unwrap();
3388+
quote!(sp::escape_markdown(&#text))
3389+
}
3390+
BuiltinFunction::ParseMarkdown => {
3391+
let text = a.next().unwrap();
3392+
quote!(sp::parse_markdown(&#text))
3393+
}
33863394
}
33873395
}
33883396

internal/compiler/llr/optim_passes/inline_expressions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
155155
BuiltinFunction::StopTimer => 10,
156156
BuiltinFunction::RestartTimer => 10,
157157
BuiltinFunction::OpenUrl => isize::MAX,
158+
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => isize::MAX,
158159
}
159160
}
160161

internal/compiler/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ declare_syntax! {
383383
AtGradient -> [*Expression],
384384
/// `@tr("foo", ...)` // the string is a StringLiteral
385385
AtTr -> [?TrContext, ?TrPlural, *Expression],
386+
AtMarkdown -> [*Expression],
386387
/// `"foo" =>` in a `AtTr` node
387388
TrContext -> [],
388389
/// `| "foo" % n` in a `AtTr` node

internal/compiler/parser/expressions.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ fn parse_at_keyword(p: &mut impl Parser) {
255255
"tr" => {
256256
parse_tr(p);
257257
}
258+
"markdown" => {
259+
parse_markdown(p);
260+
}
258261
_ => {
259262
p.consume();
260263
p.test(SyntaxKind::Identifier); // consume the identifier, so that autocomplete works
@@ -438,6 +441,37 @@ fn parse_tr(p: &mut impl Parser) {
438441
p.expect(SyntaxKind::RParent);
439442
}
440443

444+
fn parse_markdown(p: &mut impl Parser) {
445+
let mut p = p.start_node(SyntaxKind::AtMarkdown);
446+
p.expect(SyntaxKind::At);
447+
debug_assert!(p.peek().as_str().ends_with("markdown"));
448+
p.expect(SyntaxKind::Identifier); //eg "markdown"
449+
p.expect(SyntaxKind::LParent);
450+
451+
fn consume_literal(p: &mut impl Parser) -> bool {
452+
let peek = p.peek();
453+
if peek.kind() != SyntaxKind::StringLiteral
454+
|| !peek.as_str().starts_with('"')
455+
|| !peek.as_str().ends_with('"')
456+
{
457+
p.error("Expected plain string literal");
458+
return false;
459+
}
460+
p.expect(SyntaxKind::StringLiteral)
461+
}
462+
463+
if !consume_literal(&mut *p) {
464+
return;
465+
}
466+
467+
while p.test(SyntaxKind::Comma) {
468+
if !parse_expression(&mut *p) {
469+
break;
470+
}
471+
}
472+
p.expect(SyntaxKind::RParent);
473+
}
474+
441475
#[cfg_attr(test, parser_test)]
442476
/// ```test,AtImageUrl
443477
/// @image-url("foo.png")

internal/compiler/passes/apply_default_properties_from_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn apply_default_properties_from_style(
6262
}
6363
});
6464
}
65-
"Text" | "MarkdownText" => {
65+
"Text" | "StyledText" => {
6666
elem.set_binding_if_not_set("color".into(), || Expression::Cast {
6767
from: Expression::PropertyReference(NamedReference::new(
6868
&palette.root_element,

0 commit comments

Comments
 (0)