From ba7f3572a037f8a8539e011232c96041e714f89c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 24 Oct 2020 18:44:25 +0200 Subject: [PATCH] Give TextEdit a default width --- egui/src/style.rs | 8 +++++++- egui/src/widgets/text_edit.rs | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/egui/src/style.rs b/egui/src/style.rs index fcbd25f8..99fa3ada 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -57,9 +57,12 @@ pub struct Spacing { /// Anything clickable should be (at least) this size. pub interact_size: Vec2, // TODO: rename min_interact_size ? - /// Total width of a slider. + /// Default width of a `Slider`. pub slider_width: f32, // TODO: rename big_interact_size ? + /// Default width of a `TextEdit`. + pub text_edit_width: f32, + /// Checkboxes, radio button and collapsing headers have an icon at the start. /// This is the width/height of this icon. pub icon_width: f32, @@ -232,6 +235,7 @@ impl Default for Spacing { indent: 25.0, interact_size: vec2(40.0, 20.0), slider_width: 140.0, + text_edit_width: 280.0, icon_width: 16.0, icon_spacing: 1.0, tooltip_width: 400.0, @@ -350,6 +354,7 @@ impl Spacing { indent, interact_size, slider_width, + text_edit_width, icon_width, icon_spacing, tooltip_width, @@ -362,6 +367,7 @@ impl Spacing { .on_hover_text("Minimum size of an interactive widget"); ui.add(Slider::f32(indent, 0.0..=100.0).text("indent")); ui.add(Slider::f32(slider_width, 0.0..=1000.0).text("slider_width")); + ui.add(Slider::f32(text_edit_width, 0.0..=1000.0).text("text_edit_width")); ui.add(Slider::f32(icon_width, 0.0..=60.0).text("icon_width")); ui.add(Slider::f32(icon_spacing, 0.0..=10.0).text("icon_spacing")); ui.add(Slider::f32(tooltip_width, 0.0..=10.0).text("tooltip_width")); diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 512cd6ca..9292c3c3 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -18,7 +18,7 @@ pub struct TextEdit<'t> { text_color: Option, multiline: bool, enabled: bool, - desired_width: f32, + desired_width: Option, } impl<'t> TextEdit<'t> { @@ -31,7 +31,7 @@ impl<'t> TextEdit<'t> { text_color: None, multiline: true, enabled: true, - desired_width: f32::INFINITY, + desired_width: None, } } @@ -73,7 +73,7 @@ impl<'t> TextEdit<'t> { /// Set to 0.0 to keep as small as possible pub fn desired_width(mut self, desired_width: f32) -> Self { - self.desired_width = desired_width; + self.desired_width = Some(desired_width); self } } @@ -91,6 +91,8 @@ impl<'t> Widget for TextEdit<'t> { desired_width, } = self; + let desired_width = desired_width.unwrap_or_else(|| ui.style().spacing.text_edit_width); + let id = id.unwrap_or_else(|| ui.make_child_id(id_source)); let mut state = ui.memory().text_edit.get(&id).cloned().unwrap_or_default();