mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Improve size negotiation code.
Better enfocred minimum sizes. You can now have windows that expand to fit their content.
This commit is contained in:
@@ -98,6 +98,20 @@ impl Resize {
|
||||
self
|
||||
}
|
||||
|
||||
/// true: prevent from resizing to smaller than contents.
|
||||
/// false: allow shrinking to smaller than contents.
|
||||
pub fn auto_expand_width(mut self, auto_expand: bool) -> Self {
|
||||
self.expand_width_to_fit_content = auto_expand;
|
||||
self
|
||||
}
|
||||
|
||||
/// true: prevent from resizing to smaller than contents.
|
||||
/// false: allow shrinking to smaller than contents.
|
||||
pub fn auto_expand_height(mut self, auto_expand: bool) -> Self {
|
||||
self.expand_height_to_fit_content = auto_expand;
|
||||
self
|
||||
}
|
||||
|
||||
/// Offset the position of the resize handle by this much
|
||||
pub fn handle_offset(mut self, handle_offset: Vec2) -> Self {
|
||||
self.handle_offset = handle_offset;
|
||||
@@ -200,7 +214,7 @@ impl Resize {
|
||||
// state.size = state.size.clamp(self.min_size..=self.max_size);
|
||||
state.size = state.size.round(); // TODO: round to pixels
|
||||
|
||||
region.reserve_space_without_padding(state.size);
|
||||
region.reserve_space(state.size, None);
|
||||
|
||||
// ------------------------------
|
||||
|
||||
|
||||
@@ -165,8 +165,12 @@ impl ScrollArea {
|
||||
});
|
||||
}
|
||||
|
||||
let size = content_size.min(inner_rect.size());
|
||||
outer_region.reserve_space_without_padding(size);
|
||||
// let size = content_size.min(inner_rect.size());
|
||||
let size = vec2(
|
||||
content_size.x, // ignore inner_rect, i.e. try to expand horizontally if necessary
|
||||
content_size.y.min(inner_rect.size().y), // respect vertical height.
|
||||
);
|
||||
outer_region.reserve_space(size, None);
|
||||
|
||||
state.offset.y = state.offset.y.min(content_size.y - inner_rect.height());
|
||||
state.offset.y = state.offset.y.max(0.0);
|
||||
|
||||
@@ -7,11 +7,11 @@ use super::*;
|
||||
/// A wrapper around other containers for things you often want in a window
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Window {
|
||||
title: String,
|
||||
floating: Floating,
|
||||
frame: Frame,
|
||||
resize: Resize,
|
||||
scroll: ScrollArea,
|
||||
pub title: String,
|
||||
pub floating: Floating,
|
||||
pub frame: Frame,
|
||||
pub resize: Resize,
|
||||
pub scroll: ScrollArea,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
@@ -23,14 +23,30 @@ impl Window {
|
||||
frame: Frame::default(),
|
||||
resize: Resize::default()
|
||||
.handle_offset(Vec2::splat(4.0))
|
||||
.auto_shrink_width(true)
|
||||
.auto_expand_width(true)
|
||||
.auto_shrink_height(false)
|
||||
.auto_expand(false),
|
||||
.auto_expand_height(false),
|
||||
scroll: ScrollArea::default()
|
||||
.always_show_scroll(false)
|
||||
.max_height(f32::INFINITY), // As large as we can be
|
||||
}
|
||||
}
|
||||
|
||||
/// This is quite a crap idea
|
||||
/// Usage: `Winmdow::new(...).mutate(|w| w.resize = w.resize.auto_expand_width(true))`
|
||||
pub fn mutate(mut self, mutate: impl Fn(&mut Self)) -> Self {
|
||||
mutate(&mut self);
|
||||
self
|
||||
}
|
||||
|
||||
/// This is quite a crap idea
|
||||
/// Usage: `Winmdow::new(...).resize(|r| r.auto_expand_width(true))`
|
||||
pub fn resize(mut self, mutate: impl Fn(Resize) -> Resize) -> Self {
|
||||
self.resize = mutate(self.resize);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn default_pos(mut self, default_pos: Pos2) -> Self {
|
||||
self.floating = self.floating.default_pos(default_pos);
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user