Skip to content

Commit

Permalink
egui demo: Fix space reserved for source code link (#3983)
Browse files Browse the repository at this point in the history
Clip the cell of the source code link to prevent the strip from growing
infinitely if the reserved size for the link is not sufficient.


![image](https://github.com/emilk/egui/assets/2380253/0cf214fc-addc-4212-90fc-d68834c1cfe7)

Closes <#3980>.
  • Loading branch information
njust authored and emilk committed Feb 10, 2024
1 parent 1fe0f24 commit 820a3ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crates/egui_demo_lib/src/demo/strip_demo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::Color32;
use egui::{Color32, TextStyle};
use egui_extras::{Size, StripBuilder};

/// Shows off a table with dynamic layout
Expand Down Expand Up @@ -33,11 +33,12 @@ impl super::View for StripDemo {
egui::lerp(Rgba::from(color)..=Rgba::from(faded_color), t).into()
};

let body_text_size = TextStyle::Body.resolve(ui.style()).size;
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))
.size(Size::exact(body_text_size))
.vertical(|mut strip| {
strip.cell(|ui| {
ui.painter().rect_filled(
Expand Down
5 changes: 4 additions & 1 deletion crates/egui_demo_lib/src/demo/table_demo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use egui::TextStyle;

#[derive(PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
enum DemoType {
Expand Down Expand Up @@ -105,10 +107,11 @@ impl super::View for TableDemo {
ui.separator();

// Leave room for the source code link after the table demo:
let body_text_size = TextStyle::Body.resolve(ui.style()).size;
use egui_extras::{Size, StripBuilder};
StripBuilder::new(ui)
.size(Size::remainder().at_least(100.0)) // for the table
.size(Size::exact(10.5)) // for the source code link
.size(Size::exact(body_text_size)) // for the source code link
.vertical(|mut strip| {
strip.cell(|ui| {
egui::ScrollArea::horizontal().show(ui, |ui| {
Expand Down

0 comments on commit 820a3ba

Please sign in to comment.