Give TextEdit a default width
This commit is contained in:
parent
4b549a773e
commit
ba7f3572a0
2 changed files with 12 additions and 4 deletions
|
@ -57,9 +57,12 @@ pub struct Spacing {
|
||||||
/// Anything clickable should be (at least) this size.
|
/// Anything clickable should be (at least) this size.
|
||||||
pub interact_size: Vec2, // TODO: rename min_interact_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 ?
|
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.
|
/// Checkboxes, radio button and collapsing headers have an icon at the start.
|
||||||
/// This is the width/height of this icon.
|
/// This is the width/height of this icon.
|
||||||
pub icon_width: f32,
|
pub icon_width: f32,
|
||||||
|
@ -232,6 +235,7 @@ impl Default for Spacing {
|
||||||
indent: 25.0,
|
indent: 25.0,
|
||||||
interact_size: vec2(40.0, 20.0),
|
interact_size: vec2(40.0, 20.0),
|
||||||
slider_width: 140.0,
|
slider_width: 140.0,
|
||||||
|
text_edit_width: 280.0,
|
||||||
icon_width: 16.0,
|
icon_width: 16.0,
|
||||||
icon_spacing: 1.0,
|
icon_spacing: 1.0,
|
||||||
tooltip_width: 400.0,
|
tooltip_width: 400.0,
|
||||||
|
@ -350,6 +354,7 @@ impl Spacing {
|
||||||
indent,
|
indent,
|
||||||
interact_size,
|
interact_size,
|
||||||
slider_width,
|
slider_width,
|
||||||
|
text_edit_width,
|
||||||
icon_width,
|
icon_width,
|
||||||
icon_spacing,
|
icon_spacing,
|
||||||
tooltip_width,
|
tooltip_width,
|
||||||
|
@ -362,6 +367,7 @@ impl Spacing {
|
||||||
.on_hover_text("Minimum size of an interactive widget");
|
.on_hover_text("Minimum size of an interactive widget");
|
||||||
ui.add(Slider::f32(indent, 0.0..=100.0).text("indent"));
|
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(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_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(icon_spacing, 0.0..=10.0).text("icon_spacing"));
|
||||||
ui.add(Slider::f32(tooltip_width, 0.0..=10.0).text("tooltip_width"));
|
ui.add(Slider::f32(tooltip_width, 0.0..=10.0).text("tooltip_width"));
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub struct TextEdit<'t> {
|
||||||
text_color: Option<Srgba>,
|
text_color: Option<Srgba>,
|
||||||
multiline: bool,
|
multiline: bool,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
desired_width: f32,
|
desired_width: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> TextEdit<'t> {
|
impl<'t> TextEdit<'t> {
|
||||||
|
@ -31,7 +31,7 @@ impl<'t> TextEdit<'t> {
|
||||||
text_color: None,
|
text_color: None,
|
||||||
multiline: true,
|
multiline: true,
|
||||||
enabled: 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
|
/// Set to 0.0 to keep as small as possible
|
||||||
pub fn desired_width(mut self, desired_width: f32) -> Self {
|
pub fn desired_width(mut self, desired_width: f32) -> Self {
|
||||||
self.desired_width = desired_width;
|
self.desired_width = Some(desired_width);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,8 @@ impl<'t> Widget for TextEdit<'t> {
|
||||||
desired_width,
|
desired_width,
|
||||||
} = self;
|
} = 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 id = id.unwrap_or_else(|| ui.make_child_id(id_source));
|
||||||
|
|
||||||
let mut state = ui.memory().text_edit.get(&id).cloned().unwrap_or_default();
|
let mut state = ui.memory().text_edit.get(&id).cloned().unwrap_or_default();
|
||||||
|
|
Loading…
Reference in a new issue