mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Let DragValue set a min_size, and honor TextEdit::min_size height
This commit is contained in:
@@ -65,6 +65,7 @@ pub struct DragValue<'a> {
|
|||||||
custom_parser: Option<NumParser<'a>>,
|
custom_parser: Option<NumParser<'a>>,
|
||||||
update_while_editing: bool,
|
update_while_editing: bool,
|
||||||
classes: Classes,
|
classes: Classes,
|
||||||
|
min_size: Option<Vec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DragValue<'a> {
|
impl<'a> DragValue<'a> {
|
||||||
@@ -100,9 +101,19 @@ impl<'a> DragValue<'a> {
|
|||||||
custom_parser: None,
|
custom_parser: None,
|
||||||
update_while_editing: true,
|
update_while_editing: true,
|
||||||
classes: Classes::default(),
|
classes: Classes::default(),
|
||||||
|
min_size: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The minimum size of the drag value, in both its dragged and its text-edited state.
|
||||||
|
///
|
||||||
|
/// Defaults to [`crate::style::Spacing::interact_size`].
|
||||||
|
#[inline]
|
||||||
|
pub fn min_size(mut self, min_size: Vec2) -> Self {
|
||||||
|
self.min_size = Some(min_size);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// How much the value changes when dragged one point (logical pixel).
|
/// How much the value changes when dragged one point (logical pixel).
|
||||||
///
|
///
|
||||||
/// Should be finite and greater than zero.
|
/// Should be finite and greater than zero.
|
||||||
@@ -453,6 +464,7 @@ impl Widget for DragValue<'_> {
|
|||||||
custom_parser,
|
custom_parser,
|
||||||
update_while_editing,
|
update_while_editing,
|
||||||
classes,
|
classes,
|
||||||
|
min_size,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let mut prefix_text = String::new();
|
let mut prefix_text = String::new();
|
||||||
@@ -591,8 +603,7 @@ impl Widget for DragValue<'_> {
|
|||||||
.clip_text(false)
|
.clip_text(false)
|
||||||
.horizontal_align(ui.layout().horizontal_align())
|
.horizontal_align(ui.layout().horizontal_align())
|
||||||
.vertical_align(ui.layout().vertical_align())
|
.vertical_align(ui.layout().vertical_align())
|
||||||
.margin(ui.spacing().button_padding)
|
.min_size(min_size.unwrap_or(ui.spacing().interact_size))
|
||||||
.min_size(ui.spacing().interact_size)
|
|
||||||
.id(id)
|
.id(id)
|
||||||
.desired_width(
|
.desired_width(
|
||||||
ui.spacing().interact_size.x - 2.0 * ui.spacing().button_padding.x,
|
ui.spacing().interact_size.x - 2.0 * ui.spacing().button_padding.x,
|
||||||
@@ -643,7 +654,7 @@ impl Widget for DragValue<'_> {
|
|||||||
.wrap_mode(TextWrapMode::Extend)
|
.wrap_mode(TextWrapMode::Extend)
|
||||||
.sense(Sense::click_and_drag())
|
.sense(Sense::click_and_drag())
|
||||||
.gap(0.0)
|
.gap(0.0)
|
||||||
.min_size(ui.spacing().interact_size); // TODO(emilk): find some more generic solution to `min_size`
|
.min_size(min_size.unwrap_or(ui.spacing().interact_size)); // TODO(emilk): find some more generic solution to `min_size`
|
||||||
|
|
||||||
let cursor_icon = if value <= *range.start() {
|
let cursor_icon = if value <= *range.start() {
|
||||||
CursorIcon::ResizeEast
|
CursorIcon::ResizeEast
|
||||||
|
|||||||
@@ -736,7 +736,7 @@ impl TextEdit<'_> {
|
|||||||
|
|
||||||
let allocated = AtomLayout::new(atoms)
|
let allocated = AtomLayout::new(atoms)
|
||||||
.id(id)
|
.id(id)
|
||||||
.min_size(Vec2::new(allocate_width, min_height))
|
.min_size(Vec2::new(allocate_width, min_height.at_least(min_size.y)))
|
||||||
.max_width(allocate_width)
|
.max_width(allocate_width)
|
||||||
.sense(sense)
|
.sense(sense)
|
||||||
.frame(frame)
|
.frame(frame)
|
||||||
|
|||||||
Reference in New Issue
Block a user