mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -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:
@@ -46,7 +46,9 @@ pub(crate) struct Region {
|
|||||||
/// The cursor can thus be `style.spacing.item_spacing` pixels outside of the `min_rect`.
|
/// The cursor can thus be `style.spacing.item_spacing` pixels outside of the `min_rect`.
|
||||||
pub(crate) cursor: 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 {
|
impl Region {
|
||||||
@@ -429,6 +431,8 @@ impl Layout {
|
|||||||
max_rect,
|
max_rect,
|
||||||
cursor: self.initial_cursor(max_rect),
|
cursor: self.initial_cursor(max_rect),
|
||||||
intrinsic_size: Vec2::default(),
|
intrinsic_size: Vec2::default(),
|
||||||
|
max_intrinsic_width: None,
|
||||||
|
max_intrinsic_height: None,
|
||||||
};
|
};
|
||||||
let seed = self.next_widget_position(®ion);
|
let seed = self.next_widget_position(®ion);
|
||||||
region.min_rect = Rect::from_center_size(seed, Vec2::ZERO);
|
region.min_rect = Rect::from_center_size(seed, Vec2::ZERO);
|
||||||
@@ -533,6 +537,8 @@ impl Layout {
|
|||||||
mut max_rect,
|
mut max_rect,
|
||||||
min_rect,
|
min_rect,
|
||||||
intrinsic_size: min_item_size,
|
intrinsic_size: min_item_size,
|
||||||
|
max_intrinsic_width,
|
||||||
|
max_intrinsic_height,
|
||||||
} = *region;
|
} = *region;
|
||||||
|
|
||||||
match self.main_dir {
|
match self.main_dir {
|
||||||
@@ -595,6 +601,8 @@ impl Layout {
|
|||||||
max_rect,
|
max_rect,
|
||||||
cursor,
|
cursor,
|
||||||
intrinsic_size: min_item_size,
|
intrinsic_size: min_item_size,
|
||||||
|
max_intrinsic_width,
|
||||||
|
max_intrinsic_height,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.next_frame_ignore_wrap(®ion, child_size)
|
self.next_frame_ignore_wrap(®ion, child_size)
|
||||||
|
|||||||
@@ -200,7 +200,15 @@ impl Placer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn intrinsic_size(&self) -> Vec2 {
|
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.
|
/// 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.cursor.max.x = region.max_rect.max.x;
|
||||||
|
|
||||||
region.sanity_check();
|
region.sanity_check();
|
||||||
|
|
||||||
|
region.max_intrinsic_width = Some(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the maximum height of the ui.
|
/// Set the maximum height of the ui.
|
||||||
@@ -268,6 +278,8 @@ impl Placer {
|
|||||||
region.cursor.max.y = region.max_rect.max.y;
|
region.cursor.max.y = region.max_rect.max.y;
|
||||||
|
|
||||||
region.sanity_check();
|
region.sanity_check();
|
||||||
|
|
||||||
|
region.max_intrinsic_height = Some(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the minimum width of the ui.
|
/// Set the minimum width of the ui.
|
||||||
|
|||||||
@@ -89,12 +89,13 @@ fn main() -> eframe::Result {
|
|||||||
MenuButton::new("Menu")
|
MenuButton::new("Menu")
|
||||||
.config(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClickOutside))
|
.config(MenuConfig::new().close_behavior(PopupCloseBehavior::CloseOnClickOutside))
|
||||||
.ui(ui, |ui| {
|
.ui(ui, |ui| {
|
||||||
// ui.set_max_width(180.0);
|
ui.set_max_width(180.0);
|
||||||
if ui.button("Close menu").clicked() {
|
if ui.button("Close menu").clicked() {
|
||||||
ui.close_menu();
|
ui.close_menu();
|
||||||
}
|
}
|
||||||
ui.collapsing("Collapsing", |ui| {
|
ui.collapsing("Collapsing", |ui| {
|
||||||
egui::ScrollArea::both().show(ui, |ui| {
|
egui::ScrollArea::both().show(ui, |ui| {
|
||||||
|
// ui.set_width(ui.available_width());
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
ui.label(
|
ui.label(
|
||||||
"This is a long text label containing \
|
"This is a long text label containing \
|
||||||
|
|||||||
Reference in New Issue
Block a user