diff --git a/druid/examples/styled_text.rs b/druid/examples/styled_text.rs index 314f14089e..f5871b5921 100644 --- a/druid/examples/styled_text.rs +++ b/druid/examples/styled_text.rs @@ -118,7 +118,7 @@ fn ui_builder() -> impl Widget { let mono_checkbox = Checkbox::new("Monospace").lens(AppData::mono); let input = TextBox::new() - .with_text_size(38.0) + .with_placeholder("Your sample text here :)") .fix_width(200.0) .lens(AppData::text); @@ -133,5 +133,4 @@ fn ui_builder() -> impl Widget { .with_child(mono_checkbox) .with_spacer(8.0) .with_child(input.padding(5.0)) - .debug_widget_id() } diff --git a/druid/src/text/layout.rs b/druid/src/text/layout.rs index 57a0fbba6c..2ed0f15fc0 100644 --- a/druid/src/text/layout.rs +++ b/druid/src/text/layout.rs @@ -181,7 +181,7 @@ impl TextLayout { let line_metrics = layout.line_metric(pos.line).unwrap(); let p1 = (pos.point.x, line_metrics.y_offset); let p2 = (pos.point.x, (line_metrics.y_offset + line_metrics.height)); - dbg!(Line::new(p1, p2)) + Line::new(p1, p2) }) .unwrap_or_else(|| Line::new(Point::ZERO, Point::ZERO)) } diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index aaa6426eb4..b698432fab 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -360,7 +360,11 @@ impl Widget for TextBox { self.do_edit_action(edit_action, data); self.reset_cursor_blink(ctx); - self.text.set_text(data.as_str()); + if data.is_empty() { + self.text.set_text(self.placeholder.as_str()); + } else { + self.text.set_text(data.as_str()); + } self.text.rebuild_if_needed(ctx.text(), env); if !is_select_all { @@ -373,7 +377,12 @@ impl Widget for TextBox { match event { LifeCycle::WidgetAdded => { ctx.register_for_focus(); - self.text.set_text(data.clone()); + if data.is_empty() { + self.text.set_text(self.placeholder.as_str()); + self.text.set_text_color(theme::PLACEHOLDER_COLOR); + } else { + self.text.set_text(data.as_str()); + } self.text.rebuild_if_needed(ctx.text(), env); } // an open question: should we be able to schedule timers here?