From 376ad725248c9c50596adb8bbebab9d6c5c9dea7 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sun, 22 Feb 2026 08:45:12 +0000 Subject: task-085: can make Text italic --- schist_desktop_gui/src/gui/components/text.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/schist_desktop_gui/src/gui/components/text.rs b/schist_desktop_gui/src/gui/components/text.rs index 1760f4c..0cf9698 100644 --- a/schist_desktop_gui/src/gui/components/text.rs +++ b/schist_desktop_gui/src/gui/components/text.rs @@ -1,6 +1,6 @@ use std::borrow::Borrow; -use iced::widget::container; +use iced::{font, widget::container, Font}; use crate::{impl_focusable, style::*}; @@ -9,6 +9,7 @@ pub struct Text { pub content: String, align: Alignment, colour: Option, + font_style: font::Style, overflow_strategy: OverflowStrategy, size: Option, strength: Option, @@ -54,6 +55,7 @@ impl Text { align: Alignment::Left, content: String::from(content), colour: Some(Colour::Primary), + font_style: font::Style::Normal, overflow_strategy: OverflowStrategy::Grow, size: Some(Size::Base), strength: Some(Strength::Base), @@ -67,6 +69,7 @@ impl Text { align: Alignment::Left, content: String::from(content), colour: None, + font_style: font::Style::Normal, overflow_strategy: OverflowStrategy::Grow, size: None, strength: None, @@ -150,6 +153,13 @@ impl Text { ..self.clone() } } + + pub fn italic(&self) -> Self { + Self { + font_style: font::Style::Italic, + ..self.clone() + } + } } impl<'a, Message> From for iced::Element<'a, Message> @@ -178,6 +188,10 @@ where let overflow_strategy = &text.borrow().overflow_strategy.clone(); let text_elem: iced::widget::Text = iced::widget::text(text.borrow().content.clone()) + .font(Font { + style: text.borrow().font_style, + ..Default::default() + }) .size(match text.borrow().size { Some(Size::VSmall) => u32::from(TEXT_SIZE_V_SM), Some(Size::Small) => u32::from(TEXT_SIZE_SM), -- cgit v1.2.3