1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 15:20:05 -04:00
Files
egui/crates/egui_demo_lib/src/demo/strip_demo.rs
Valeriy V. Vorotyntsev 4c3b380889 Fix the "ever-growing height" problem of Strip and Table demos (#3122)
* Fix the "ever-growing height" problem of Strip and Table Demos

Problem
-------

The height of "Table Demo" or "Strip Demo" floating window grows
when the demo app is interacted with. If 'Continuous' mode is enabled
in 'Backend' settings, the window grows irrespectively of user interaction.

Observations
------------

I noticed that [`area_content_ui.min_rect().max.y`][1] is increasing
monotonically with speed 0.5 px/frame.

I also noticed that commenting out `ui.add(crate::egui_github_link_file!());`
[statement][2] in `table_demo.rs` makes the problem disappear.

The "Fix"
---------

I added 0.5 to the height of the row with GitHub link.
This solved the problem.

Closes #3029.

Warning
-------

I failed to find the root cause of the problem.
I don't understand why this change makes the problem disappear.

[1]: 9478e50d01/crates/egui/src/containers/window.rs (L403)
[2]: 9478e50d01/crates/egui_demo_lib/src/demo/table_demo.rs (L114)

* Document `Rect::size`

Other changes:

- `area.rs`: Use existing API.
- `table_demo.rs`: Remove unnecessary call.
2023-08-10 12:35:40 +02:00

120 lines
4.9 KiB
Rust

use egui::Color32;
use egui_extras::{Size, StripBuilder};
/// Shows off a table with dynamic layout
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Default)]
pub struct StripDemo {}
impl super::Demo for StripDemo {
fn name(&self) -> &'static str {
"▣ Strip Demo"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
egui::Window::new(self.name())
.open(open)
.resizable(true)
.default_width(400.0)
.show(ctx, |ui| {
use super::View as _;
self.ui(ui);
});
}
}
impl super::View for StripDemo {
fn ui(&mut self, ui: &mut egui::Ui) {
let dark_mode = ui.visuals().dark_mode;
let faded_color = ui.visuals().window_fill();
let faded_color = |color: Color32| -> Color32 {
use egui::Rgba;
let t = if dark_mode { 0.95 } else { 0.8 };
egui::lerp(Rgba::from(color)..=Rgba::from(faded_color), t).into()
};
StripBuilder::new(ui)
.size(Size::exact(50.0))
.size(Size::remainder())
.size(Size::relative(0.5).at_least(60.0))
.size(Size::exact(10.5))
.vertical(|mut strip| {
strip.cell(|ui| {
ui.painter().rect_filled(
ui.available_rect_before_wrap(),
0.0,
faded_color(Color32::BLUE),
);
ui.label("width: 100%\nheight: 50px");
});
strip.strip(|builder| {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| {
ui.painter().rect_filled(
ui.available_rect_before_wrap(),
0.0,
faded_color(Color32::RED),
);
ui.label("width: 50%\nheight: remaining");
});
strip.strip(|builder| {
builder.sizes(Size::remainder(), 3).vertical(|mut strip| {
strip.empty();
strip.cell(|ui| {
ui.painter().rect_filled(
ui.available_rect_before_wrap(),
0.0,
faded_color(Color32::YELLOW),
);
ui.label("width: 50%\nheight: 1/3 of the red region");
});
strip.empty();
});
});
});
});
strip.strip(|builder| {
builder
.size(Size::remainder())
.size(Size::exact(120.0))
.size(Size::remainder())
.size(Size::exact(70.0))
.horizontal(|mut strip| {
strip.empty();
strip.strip(|builder| {
builder
.size(Size::remainder())
.size(Size::exact(60.0))
.size(Size::remainder())
.vertical(|mut strip| {
strip.empty();
strip.cell(|ui| {
ui.painter().rect_filled(
ui.available_rect_before_wrap(),
0.0,
faded_color(Color32::GOLD),
);
ui.label("width: 120px\nheight: 60px");
});
});
});
strip.empty();
strip.cell(|ui| {
ui.painter().rect_filled(
ui.available_rect_before_wrap(),
0.0,
faded_color(Color32::GREEN),
);
ui.label("width: 70px\n\nheight: 50%, but at least 60px.");
});
});
});
strip.cell(|ui| {
ui.vertical_centered(|ui| {
ui.add(crate::egui_github_link_file!());
});
});
});
}
}