1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Add egui::Sides shrink_left / shrink_right (#7295)

This allows contents (on one of the sides) in egui::Sides to shrink. 

* related https://github.com/rerun-io/rerun/issues/10494
This commit is contained in:
Lucas Meurer
2025-07-03 14:31:35 +02:00
committed by GitHub
parent 77df407f50
commit 2b62c68598
22 changed files with 308 additions and 40 deletions

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b7ceaa95512c67dcbf1c8ba5a8f33bf4833c2e863d09903fb71b5aa2822cc086
size 7889

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:931af33f4548924b3bb75a2e513b9e689bce94436b10a9f811140eb11e9d6442
size 8552

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6448d44c1c9bed08cd6a4af39b141f3a4ca203ca5f7b967cbc0e0d0c2b4fb73f
size 1647

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:44622002ebe287208d26359a06804b1f8737f86eb482322bdf3881a1fe53941f
size 1276

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:88e1557dffa7295e7e7e37ed175fcec40aab939f9b67137a1ce33811e8ae4722
size 7148

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:931af33f4548924b3bb75a2e513b9e689bce94436b10a9f811140eb11e9d6442
size 8552

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6448d44c1c9bed08cd6a4af39b141f3a4ca203ca5f7b967cbc0e0d0c2b4fb73f
size 1647

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:44622002ebe287208d26359a06804b1f8737f86eb482322bdf3881a1fe53941f
size 1276

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:508209ca303751ef323301b25bb3878410742ea79339b75363d2681b98d2712b
size 7068

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:931af33f4548924b3bb75a2e513b9e689bce94436b10a9f811140eb11e9d6442
size 8552

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6448d44c1c9bed08cd6a4af39b141f3a4ca203ca5f7b967cbc0e0d0c2b4fb73f
size 1647

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:44622002ebe287208d26359a06804b1f8737f86eb482322bdf3881a1fe53941f
size 1276

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a0c9e39c18fc5bb1fc02a86dbf02e3ffca5537dbe8986d5c5b50cb4984c97466
size 9085

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:931af33f4548924b3bb75a2e513b9e689bce94436b10a9f811140eb11e9d6442
size 8552

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6448d44c1c9bed08cd6a4af39b141f3a4ca203ca5f7b967cbc0e0d0c2b4fb73f
size 1647

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:44622002ebe287208d26359a06804b1f8737f86eb482322bdf3881a1fe53941f
size 1276

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a6e9ba0acb573853ef5b3dedb1156d99cdf80338ccb160093960e8aaa41bd5df
size 9048

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:931af33f4548924b3bb75a2e513b9e689bce94436b10a9f811140eb11e9d6442
size 8552

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6448d44c1c9bed08cd6a4af39b141f3a4ca203ca5f7b967cbc0e0d0c2b4fb73f
size 1647

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:44622002ebe287208d26359a06804b1f8737f86eb482322bdf3881a1fe53941f
size 1276

View File

@@ -0,0 +1,76 @@
use egui::{TextWrapMode, Vec2, containers::Sides};
use egui_kittest::{Harness, SnapshotResults};
#[test]
fn sides_container_tests() {
let mut results = SnapshotResults::new();
test_variants("default", |sides| sides, &mut results);
test_variants(
"shrink_left",
|sides| sides.shrink_left().truncate(),
&mut results,
);
test_variants(
"shrink_right",
|sides| sides.shrink_right().truncate(),
&mut results,
);
test_variants(
"wrap_left",
|sides| sides.shrink_left().wrap_mode(TextWrapMode::Wrap),
&mut results,
);
test_variants(
"wrap_right",
|sides| sides.shrink_right().wrap_mode(TextWrapMode::Wrap),
&mut results,
);
}
fn test_variants(
name: &str,
mut create_sides: impl FnMut(Sides) -> Sides,
results: &mut SnapshotResults,
) {
for (variant_name, left_text, right_text, fit_contents) in [
("short", "Left", "Right", false),
(
"long",
"Very long left content that should not fit.",
"Very long right text that should also not fit.",
false,
),
("short_fit_contents", "Left", "Right", true),
(
"long_fit_contents",
"Very long left content that should not fit.",
"Very long right text that should also not fit.",
true,
),
] {
let mut harness = Harness::builder()
.with_size(Vec2::new(400.0, 50.0))
.build_ui(|ui| {
create_sides(Sides::new()).show(
ui,
|left| {
left.label(left_text);
},
|right| {
right.label(right_text);
},
);
});
if fit_contents {
harness.fit_contents();
}
results.add(harness.try_snapshot(&format!("sides/{name}_{variant_name}")));
}
}