Skip to content

Commit 8bdc1bc

Browse files
committed
Merge with master
[autofix.ci] apply automated fixes Fix api/node Don't use std:: for certain types Move test Fix testing backend thing Add allow missing docs to stuff Change rendertext trait to use enum Fill out styled text type Apply automated fixes Add comments and solve warnings Rename MarkdownText to StyledText [autofix.ci] apply automated fixes Implement more things add StyledText Type and Value
1 parent d229515 commit 8bdc1bc

24 files changed

+726
-619
lines changed

api/cpp/cbindgen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ fn gen_corelib(
305305
"Flickable",
306306
"SimpleText",
307307
"ComplexText",
308-
"MarkdownText",
308+
"StyledText",
309309
"Path",
310310
"WindowItem",
311311
"TextInput",

internal/backends/qt/qt_window.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,16 @@ impl ItemRenderer for QtItemRenderer<'_> {
686686
sharedparley::draw_text(self, text, Some(self_rc), size);
687687
}
688688

689+
fn draw_styled_text(
690+
&mut self,
691+
text: Pin<&i_slint_core::items::StyledText>,
692+
self_rc: &ItemRc,
693+
size: LogicalSize,
694+
_cache: &CachedRenderingData,
695+
) {
696+
sharedparley::draw_styled_text(self, text, Some(self_rc), size);
697+
}
698+
689699
fn draw_text_input(
690700
&mut self,
691701
text_input: Pin<&items::TextInput>,
@@ -2095,6 +2105,16 @@ impl i_slint_core::renderer::RendererSealed for QtWindow {
20952105
sharedparley::text_size(self, text_item, item_rc, max_width, text_wrap)
20962106
}
20972107

2108+
fn styled_text_size(
2109+
&self,
2110+
text_item: Pin<&i_slint_core::items::StyledText>,
2111+
item_rc: &ItemRc,
2112+
max_width: Option<LogicalLength>,
2113+
text_wrap: TextWrap,
2114+
) -> LogicalSize {
2115+
sharedparley::styled_text_size(self, text_item, item_rc, max_width, text_wrap)
2116+
}
2117+
20982118
fn char_size(
20992119
&self,
21002120
text_item: Pin<&dyn i_slint_core::item_rendering::HasFont>,

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/builtin_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ fn to_debug_string(
425425
}
426426
}
427427
Type::Enumeration(_) => Expression::Cast { from: Box::new(expr), to: (Type::String) },
428+
Type::StyledText => Expression::Invalid,
428429
}
429430
}
430431

internal/compiler/builtins.slint

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,17 @@ component ComplexText inherits SimpleText {
120120

121121
export { ComplexText as Text }
122122

123-
export component MarkdownText inherits Empty {
123+
export component StyledText 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;
130130
in property <TextHorizontalAlignment> horizontal-alignment;
131131
in property <TextVerticalAlignment> vertical-alignment;
132132
callback link-clicked(link: string);
133133
in property <color> link-color: #00f;
134-
135134
in property <string> font-family;
136135
in property <bool> font-italic;
137136
in property <TextOverflow> overflow;
@@ -143,6 +142,10 @@ export component MarkdownText inherits Empty {
143142
//-default_size_binding:implicit_size
144143
}
145144

145+
export component StyledText inherits Empty {
146+
in property <styled-text> text;
147+
}
148+
146149
export component TouchArea {
147150
in property <bool> enabled: true;
148151
out property <bool> pressed;

internal/compiler/expression_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ declare_builtin_function_types!(
277277
RestartTimer: (Type::ElementReference) -> Type::Void,
278278
OpenUrl: (Type::String) -> Type::Void,
279279
EscapeMarkdown: (Type::String) -> Type::String,
280-
ParseMarkdown: (Type::String) -> Type::String
280+
ParseMarkdown: (Type::String) -> Type::StyledText
281281
);
282282

283283
impl BuiltinFunction {
@@ -374,7 +374,7 @@ impl BuiltinFunction {
374374
BuiltinFunction::StopTimer => false,
375375
BuiltinFunction::RestartTimer => false,
376376
BuiltinFunction::OpenUrl => false,
377-
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => true,
377+
BuiltinFunction::ParseMarkdown | BuiltinFunction::EscapeMarkdown => false,
378378
}
379379
}
380380

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,

internal/compiler/passes/embed_glyphs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ pub fn collect_font_sizes_used(
546546
.to_string()
547547
.as_str()
548548
{
549-
"TextInput" | "Text" | "SimpleText" | "ComplexText" | "MarkdownText" => {
549+
"TextInput" | "Text" | "SimpleText" | "ComplexText" | "StyledText" => {
550550
if let Some(font_size) = try_extract_font_size_from_element(elem, "font-size") {
551551
add_font_size(font_size)
552552
}

internal/compiler/passes/resolving.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,9 @@ impl Expression {
848848
pos = end + 1;
849849
literal_start_pos = pos;
850850
}
851-
{
852-
let trailing = Expression::StringLiteral((&string[literal_start_pos..]).into());
851+
let trailing = &string[literal_start_pos..];
852+
if !trailing.is_empty() {
853+
let trailing = Expression::StringLiteral(trailing.into());
853854
expr = Some(match expr {
854855
None => trailing,
855856
Some(expr) => Expression::BinaryExpression {
@@ -876,7 +877,7 @@ impl Expression {
876877
Expression::FunctionCall {
877878
function: BuiltinFunction::ParseMarkdown.into(),
878879
arguments: vec![
879-
expr.unwrap_or_else(|| Expression::default_value_for_type(&Type::String))
880+
expr.unwrap_or_else(|| Expression::default_value_for_type(&Type::String)),
880881
],
881882
source_location: Some(node.to_source_location()),
882883
}

internal/compiler/typeregister.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl TypeRegister {
586586
register.elements.remove("DropArea").unwrap();
587587
register.types.remove("DropEvent").unwrap(); // Also removed in xtask/src/slintdocs.rs
588588

589-
register.elements.remove("MarkdownText").unwrap();
589+
register.elements.remove("StyledText").unwrap();
590590

591591
Rc::new(RefCell::new(register))
592592
}

0 commit comments

Comments
 (0)