Fix bug with the layout of wide DragValue:s

This commit is contained in:
Emil Ernerfeldt 2021-04-18 23:10:12 +02:00
parent c07f439b28
commit 0351662763
3 changed files with 13 additions and 2 deletions

View file

@ -17,6 +17,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
### Fixed 🐛
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288).
* Fix bug with the layout of wide `DragValue`:s.
## 0.11.0 - 2021-04-05 - Optimization, screen reader & new layout logic

View file

@ -22,6 +22,7 @@ pub struct Button {
small: bool,
frame: bool,
wrap: Option<bool>,
min_size: Vec2,
}
impl Button {
@ -35,6 +36,7 @@ impl Button {
small: false,
frame: true,
wrap: None,
min_size: Vec2::ZERO,
}
}
@ -99,6 +101,11 @@ impl Button {
self.wrap = Some(wrap);
self
}
pub(crate) fn min_size(mut self, min_size: Vec2) -> Self {
self.min_size = min_size;
self
}
}
impl Button {
@ -112,6 +119,7 @@ impl Button {
small,
frame,
wrap,
min_size,
} = self;
let mut button_padding = ui.spacing().button_padding;
@ -132,6 +140,7 @@ impl Button {
if !small {
desired_size.y = desired_size.y.at_least(ui.spacing().interact_size.y);
}
desired_size = desired_size.at_least(min_size);
let (rect, response) = ui.allocate_at_least(desired_size, sense);
response.widget_info(|| WidgetInfo::labeled(WidgetType::Button, &galley.text));

View file

@ -266,9 +266,10 @@ impl<'a> Widget for DragValue<'a> {
let button = Button::new(format!("{}{}{}", prefix, value_text, suffix))
.sense(Sense::click_and_drag())
.text_style(TextStyle::Monospace)
.wrap(false);
.wrap(false)
.min_size(ui.spacing().interact_size); // TODO: find some more generic solution to this
let response = ui.add_sized(ui.spacing().interact_size, button);
let response = ui.add(button);
let response = response
.on_hover_cursor(CursorIcon::ResizeHorizontal)
.on_hover_text(format!(