diff --git a/egui/src/widgets/button.rs b/egui/src/widgets/button.rs index 24a1743e..187e518a 100644 --- a/egui/src/widgets/button.rs +++ b/egui/src/widgets/button.rs @@ -21,6 +21,7 @@ pub struct Button { sense: Sense, small: bool, frame: bool, + wrap: Option, } impl Button { @@ -33,6 +34,7 @@ impl Button { sense: Sense::click(), small: false, frame: true, + wrap: None, } } @@ -86,6 +88,17 @@ impl Button { } 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 { @@ -98,6 +111,7 @@ impl Button { sense, small, frame, + wrap, } = self; let mut button_padding = ui.spacing().button_padding; @@ -106,7 +120,8 @@ impl Button { } 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() .layout_multiline(text_style, text, ui.available_width() - total_extra.x) } else { diff --git a/egui/src/widgets/drag_value.rs b/egui/src/widgets/drag_value.rs index dbf55d6c..cd0eb495 100644 --- a/egui/src/widgets/drag_value.rs +++ b/egui/src/widgets/drag_value.rs @@ -260,7 +260,8 @@ impl<'a> Widget for DragValue<'a> { } else { let button = Button::new(format!("{}{}{}", prefix, value_text, suffix)) .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 = response.on_hover_text(format!( "{}{}{}\nDrag to edit or click to enter a value.",