From 12607bfdbededa2c4b43cb4e2106a0615d2e7879 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Tue, 21 May 2024 13:03:39 +0200 Subject: [PATCH 1/3] feat: hint text styling --- crates/egui/src/widgets/text_edit/builder.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 440916f31b2..fa9edff30b6 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -60,6 +60,7 @@ use super::{TextEditOutput, TextEditState}; pub struct TextEdit<'t> { text: &'t mut dyn TextBuffer, hint_text: WidgetText, + hint_text_font: Option, id: Option, id_source: Option, font_selection: FontSelection, @@ -111,6 +112,7 @@ impl<'t> TextEdit<'t> { Self { text, hint_text: Default::default(), + hint_text_font: None, id: None, id_source: None, font_selection: Default::default(), @@ -189,6 +191,13 @@ impl<'t> TextEdit<'t> { self } + /// Forces a specific style for the hint text. + #[inline] + pub fn hint_text_font(mut self, hint_text_font: impl Into) -> Self { + self.hint_text_font = Some(hint_text_font.into()); + self + } + /// If true, hide the letters from view and prevent copying from the field. #[inline] pub fn password(mut self, password: bool) -> Self { @@ -436,6 +445,7 @@ impl<'t> TextEdit<'t> { let TextEdit { text, hint_text, + hint_text_font, id, id_source, font_selection, @@ -652,9 +662,9 @@ impl<'t> TextEdit<'t> { if text.as_str().is_empty() && !hint_text.is_empty() { let hint_text_color = ui.visuals().weak_text_color(); let galley = if multiline { - hint_text.into_galley(ui, Some(true), desired_inner_size.x, font_id) + hint_text.into_galley(ui, Some(true), desired_inner_size.x, hint_text_font.unwrap_or(font_id.into())) } else { - hint_text.into_galley(ui, Some(false), f32::INFINITY, font_id) + hint_text.into_galley(ui, Some(false), f32::INFINITY, hint_text_font.unwrap_or(font_id.into())) }; painter.galley(rect.min, galley, hint_text_color); } From 75c42f3cb85e3b884d5867e86b1e88769aa90c9f Mon Sep 17 00:00:00 2001 From: zaaarf Date: Tue, 21 May 2024 13:05:40 +0200 Subject: [PATCH 2/3] chore: fmt --- crates/egui/src/widgets/text_edit/builder.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index fa9edff30b6..a2cf4897a1c 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -662,9 +662,19 @@ impl<'t> TextEdit<'t> { if text.as_str().is_empty() && !hint_text.is_empty() { let hint_text_color = ui.visuals().weak_text_color(); let galley = if multiline { - hint_text.into_galley(ui, Some(true), desired_inner_size.x, hint_text_font.unwrap_or(font_id.into())) + hint_text.into_galley( + ui, + Some(true), + desired_inner_size.x, + hint_text_font.unwrap_or(font_id.into()), + ) } else { - hint_text.into_galley(ui, Some(false), f32::INFINITY, hint_text_font.unwrap_or(font_id.into())) + hint_text.into_galley( + ui, + Some(false), + f32::INFINITY, + hint_text_font.unwrap_or(font_id.into()), + ) }; painter.galley(rect.min, galley, hint_text_color); } From 84c255fc9d10162fb9607c939cbcde8159ed996f Mon Sep 17 00:00:00 2001 From: zaaarf Date: Mon, 27 May 2024 17:21:06 +0200 Subject: [PATCH 3/3] requested changes --- crates/egui/src/widgets/text_edit/builder.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index a2cf4897a1c..b27227c5c41 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -191,7 +191,7 @@ impl<'t> TextEdit<'t> { self } - /// Forces a specific style for the hint text. + /// Set a specific style for the hint text. #[inline] pub fn hint_text_font(mut self, hint_text_font: impl Into) -> Self { self.hint_text_font = Some(hint_text_font.into()); @@ -661,20 +661,11 @@ impl<'t> TextEdit<'t> { if text.as_str().is_empty() && !hint_text.is_empty() { let hint_text_color = ui.visuals().weak_text_color(); + let hint_text_font_id = hint_text_font.unwrap_or(font_id.into()); let galley = if multiline { - hint_text.into_galley( - ui, - Some(true), - desired_inner_size.x, - hint_text_font.unwrap_or(font_id.into()), - ) + hint_text.into_galley(ui, Some(true), desired_inner_size.x, hint_text_font_id) } else { - hint_text.into_galley( - ui, - Some(false), - f32::INFINITY, - hint_text_font.unwrap_or(font_id.into()), - ) + hint_text.into_galley(ui, Some(false), f32::INFINITY, hint_text_font_id) }; painter.galley(rect.min, galley, hint_text_color); }