1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Add workaround for max_width

set_max_width and set_max_height will limit intrinsic size but not max_rect itself
This commit is contained in:
lucasmerlin
2025-03-19 11:51:03 +01:00
parent ceb78780de
commit d72e85b6b4
3 changed files with 24 additions and 3 deletions

View File

@@ -46,7 +46,9 @@ pub(crate) struct Region {
/// The cursor can thus be `style.spacing.item_spacing` pixels outside of the `min_rect`.
pub(crate) cursor: Rect,
pub intrinsic_size: Vec2,
pub(crate) intrinsic_size: Vec2,
pub max_intrinsic_width: Option<f32>,
pub max_intrinsic_height: Option<f32>,
}
impl Region {
@@ -429,6 +431,8 @@ impl Layout {
max_rect,
cursor: self.initial_cursor(max_rect),
intrinsic_size: Vec2::default(),
max_intrinsic_width: None,
max_intrinsic_height: None,
};
let seed = self.next_widget_position(&region);
region.min_rect = Rect::from_center_size(seed, Vec2::ZERO);
@@ -533,6 +537,8 @@ impl Layout {
mut max_rect,
min_rect,
intrinsic_size: min_item_size,
max_intrinsic_width,
max_intrinsic_height,
} = *region;
match self.main_dir {
@@ -595,6 +601,8 @@ impl Layout {
max_rect,
cursor,
intrinsic_size: min_item_size,
max_intrinsic_width,
max_intrinsic_height,
};
self.next_frame_ignore_wrap(&region, child_size)

View File

@@ -200,7 +200,15 @@ impl Placer {
}
pub(crate) fn intrinsic_size(&self) -> Vec2 {
self.region.intrinsic_size
//self.region.intrinsic_size.min(self.max_rect().size())
let mut intrinsic = self.region.intrinsic_size;
if let Some(max_x) = self.region.max_intrinsic_width {
intrinsic.x = intrinsic.x.min(max_x);
}
if let Some(max_y) = self.region.max_intrinsic_height {
intrinsic.y = intrinsic.y.min(max_y);
}
intrinsic
}
/// Move to the next row in a grid layout or wrapping layout.
@@ -253,6 +261,8 @@ impl Placer {
region.cursor.max.x = region.max_rect.max.x;
region.sanity_check();
region.max_intrinsic_width = Some(width);
}
/// Set the maximum height of the ui.
@@ -268,6 +278,8 @@ impl Placer {
region.cursor.max.y = region.max_rect.max.y;
region.sanity_check();
region.max_intrinsic_height = Some(height);
}
/// Set the minimum width of the ui.