From 0f0d2de6654dbd05f1ac0ab1928614e53946483a Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Fri, 31 Oct 2025 15:13:36 +0100 Subject: [PATCH 1/2] MarkdownText: link color handling --- internal/compiler/builtins.slint | 1 + internal/core/item_rendering.rs | 7 ++++++- internal/core/items/text.rs | 13 +++++++++++++ internal/core/textlayout/sharedparley.rs | 6 +++--- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/internal/compiler/builtins.slint b/internal/compiler/builtins.slint index ba00a130a90..cf25cf33c94 100644 --- a/internal/compiler/builtins.slint +++ b/internal/compiler/builtins.slint @@ -130,6 +130,7 @@ export component MarkdownText inherits Empty { in property horizontal-alignment; in property vertical-alignment; callback link-clicked(link: string); + in property link-color: #00f; in property font-family; in property font-italic; diff --git a/internal/core/item_rendering.rs b/internal/core/item_rendering.rs index 64c62ca6622..31a4f03cfb7 100644 --- a/internal/core/item_rendering.rs +++ b/internal/core/item_rendering.rs @@ -5,7 +5,7 @@ //! module for rendering the tree of items use super::items::*; -use crate::graphics::{FontRequest, Image, IntRect}; +use crate::graphics::{Color, FontRequest, Image, IntRect}; use crate::item_tree::ItemTreeRc; use crate::item_tree::{ItemVisitor, ItemVisitorVTable, VisitChildrenResult}; use crate::lengths::{ @@ -299,6 +299,7 @@ pub trait RenderText { fn letter_spacing(self: Pin<&Self>) -> LogicalLength; fn stroke(self: Pin<&Self>) -> (Brush, LogicalLength, TextStrokeStyle); fn is_markdown(self: Pin<&Self>) -> bool; + fn link_color(self: Pin<&Self>) -> Color; } impl RenderText for (SharedString, Brush) { @@ -318,6 +319,10 @@ impl RenderText for (SharedString, Brush) { self.1.clone() } + fn link_color(self: Pin<&Self>) -> Color { + Default::default() + } + fn alignment( self: Pin<&Self>, ) -> (crate::items::TextHorizontalAlignment, crate::items::TextVerticalAlignment) { diff --git a/internal/core/items/text.rs b/internal/core/items/text.rs index 9d4b58f0e58..db5787c795b 100644 --- a/internal/core/items/text.rs +++ b/internal/core/items/text.rs @@ -179,6 +179,10 @@ impl RenderText for ComplexText { self.color() } + fn link_color(self: Pin<&Self>) -> Color { + Default::default() + } + fn alignment( self: Pin<&Self>, ) -> (super::TextHorizontalAlignment, super::TextVerticalAlignment) { @@ -242,6 +246,7 @@ pub struct MarkdownText { pub stroke: Property, pub stroke_width: Property, pub stroke_style: Property, + pub link_color: Property, pub cached_rendering_data: CachedRenderingData, } @@ -396,6 +401,10 @@ impl RenderText for MarkdownText { self.color() } + fn link_color(self: Pin<&Self>) -> Color { + self.link_color() + } + fn alignment( self: Pin<&Self>, ) -> (super::TextHorizontalAlignment, super::TextVerticalAlignment) { @@ -571,6 +580,10 @@ impl RenderText for SimpleText { self.color() } + fn link_color(self: Pin<&Self>) -> Color { + Default::default() + } + fn alignment( self: Pin<&Self>, ) -> (super::TextHorizontalAlignment, super::TextVerticalAlignment) { diff --git a/internal/core/textlayout/sharedparley.rs b/internal/core/textlayout/sharedparley.rs index 896c3eeee83..780b8979144 100644 --- a/internal/core/textlayout/sharedparley.rs +++ b/internal/core/textlayout/sharedparley.rs @@ -141,7 +141,7 @@ impl LayoutOptions { stroke: None, text_wrap: text_input.wrap(), text_overflow: TextOverflow::Clip, - link_color: crate::Color::from_rgb_u8(64, 64, 255), + link_color: Default::default(), } } } @@ -1188,7 +1188,7 @@ pub fn draw_text( text_overflow, selection: None, selection_foreground_color: None, - link_color: crate::Color::from_rgb_u8(64, 64, 255), + link_color: text.link_color(), }, ); @@ -1372,7 +1372,7 @@ pub fn text_size( text_overflow: TextOverflow::Clip, selection: None, selection_foreground_color: None, - link_color: crate::Color::from_rgb_u8(64, 64, 255), + link_color: Default::default(), }, ); PhysicalSize::from_lengths(layout.max_width, layout.height) / scale_factor From e78517e96a278df49bb978314d5f179bc716acb1 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 3 Nov 2025 10:02:13 +0100 Subject: [PATCH 2/2] Set color in link_under_cursor fn --- internal/core/textlayout/sharedparley.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/core/textlayout/sharedparley.rs b/internal/core/textlayout/sharedparley.rs index 780b8979144..8cc00f9335e 100644 --- a/internal/core/textlayout/sharedparley.rs +++ b/internal/core/textlayout/sharedparley.rs @@ -1248,7 +1248,7 @@ pub fn link_under_cursor( text_overflow: text.overflow(), selection: None, selection_foreground_color: None, - link_color: crate::Color::from_rgb_u8(64, 64, 255), + link_color: text.link_color(), }, );