Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TextEdit::hint_text_font #4517

Merged
merged 3 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use super::{TextEditOutput, TextEditState};
pub struct TextEdit<'t> {
text: &'t mut dyn TextBuffer,
hint_text: WidgetText,
hint_text_font: Option<FontSelection>,
id: Option<Id>,
id_source: Option<Id>,
font_selection: FontSelection,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -189,6 +191,13 @@ impl<'t> TextEdit<'t> {
self
}

/// Set a specific style for the hint text.
#[inline]
pub fn hint_text_font(mut self, hint_text_font: impl Into<FontSelection>) -> 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 {
Expand Down Expand Up @@ -436,6 +445,7 @@ impl<'t> TextEdit<'t> {
let TextEdit {
text,
hint_text,
hint_text_font,
id,
id_source,
font_selection,
Expand Down Expand Up @@ -651,10 +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 {
zaaarf marked this conversation as resolved.
Show resolved Hide resolved
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_id)
} else {
hint_text.into_galley(ui, Some(false), f32::INFINITY, font_id)
hint_text.into_galley(ui, Some(false), f32::INFINITY, hint_text_font_id)
};
painter.galley(rect.min, galley, hint_text_color);
}
Expand Down
Loading