Skip to content

Commit

Permalink
Give TextEdit a default width
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Oct 24, 2020
1 parent 4b549a7 commit ba7f357
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -350,6 +354,7 @@ impl Spacing {
indent,
interact_size,
slider_width,
text_edit_width,
icon_width,
icon_spacing,
tooltip_width,
Expand All @@ -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"));
Expand Down
8 changes: 5 additions & 3 deletions egui/src/widgets/text_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct TextEdit<'t> {
text_color: Option<Srgba>,
multiline: bool,
enabled: bool,
desired_width: f32,
desired_width: Option<f32>,
}

impl<'t> TextEdit<'t> {
Expand All @@ -31,7 +31,7 @@ impl<'t> TextEdit<'t> {
text_color: None,
multiline: true,
enabled: true,
desired_width: f32::INFINITY,
desired_width: None,
}
}

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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();
Expand Down

0 comments on commit ba7f357

Please sign in to comment.