Turn off text wrapping for DragValue:s
This commit is contained in:
parent
4b9db0cc55
commit
4ac5b37702
2 changed files with 18 additions and 2 deletions
|
@ -21,6 +21,7 @@ pub struct Button {
|
||||||
sense: Sense,
|
sense: Sense,
|
||||||
small: bool,
|
small: bool,
|
||||||
frame: bool,
|
frame: bool,
|
||||||
|
wrap: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
|
@ -33,6 +34,7 @@ impl Button {
|
||||||
sense: Sense::click(),
|
sense: Sense::click(),
|
||||||
small: false,
|
small: false,
|
||||||
frame: true,
|
frame: true,
|
||||||
|
wrap: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +88,17 @@ impl Button {
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If `true`, the text will wrap at the `max_width`.
|
||||||
|
/// By default [`Self::wrap`] will be true in vertical layouts
|
||||||
|
/// and horizontal layouts with wrapping,
|
||||||
|
/// and false on non-wrapping horizontal layouts.
|
||||||
|
///
|
||||||
|
/// Note that any `\n` in the button text will always produce a new line.
|
||||||
|
pub fn wrap(mut self, wrap: bool) -> Self {
|
||||||
|
self.wrap = Some(wrap);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
|
@ -98,6 +111,7 @@ impl Button {
|
||||||
sense,
|
sense,
|
||||||
small,
|
small,
|
||||||
frame,
|
frame,
|
||||||
|
wrap,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let mut button_padding = ui.spacing().button_padding;
|
let mut button_padding = ui.spacing().button_padding;
|
||||||
|
@ -106,7 +120,8 @@ impl Button {
|
||||||
}
|
}
|
||||||
let total_extra = button_padding + button_padding;
|
let total_extra = button_padding + button_padding;
|
||||||
|
|
||||||
let galley = if ui.wrap_text() {
|
let wrap = wrap.unwrap_or_else(|| ui.wrap_text());
|
||||||
|
let galley = if wrap {
|
||||||
ui.fonts()
|
ui.fonts()
|
||||||
.layout_multiline(text_style, text, ui.available_width() - total_extra.x)
|
.layout_multiline(text_style, text, ui.available_width() - total_extra.x)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -260,7 +260,8 @@ impl<'a> Widget for DragValue<'a> {
|
||||||
} else {
|
} else {
|
||||||
let button = Button::new(format!("{}{}{}", prefix, value_text, suffix))
|
let button = Button::new(format!("{}{}{}", prefix, value_text, suffix))
|
||||||
.sense(Sense::click_and_drag())
|
.sense(Sense::click_and_drag())
|
||||||
.text_style(TextStyle::Monospace);
|
.text_style(TextStyle::Monospace)
|
||||||
|
.wrap(false);
|
||||||
let response = ui.add_sized(ui.spacing().interact_size, button);
|
let response = ui.add_sized(ui.spacing().interact_size, button);
|
||||||
let response = response.on_hover_text(format!(
|
let response = response.on_hover_text(format!(
|
||||||
"{}{}{}\nDrag to edit or click to enter a value.",
|
"{}{}{}\nDrag to edit or click to enter a value.",
|
||||||
|
|
Loading…
Reference in a new issue