Skip to content

Commit 9f5abd0

Browse files
committed
add radio button to set max rows to usize::MAX
dont reset max width points value if clicked when already selected
1 parent 27e0b2b commit 9f5abd0

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

examples/demo/src/apps/wrapping.rs

+36-15
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ use super::Show;
99

1010
pub struct WrappingExample {
1111
value: Value,
12-
state: JsonTreeWrapping,
12+
wrap: JsonTreeWrapping,
13+
use_maximum_max_rows: bool,
1314
}
1415

1516
impl WrappingExample {
1617
pub fn new(value: Value) -> Self {
1718
Self {
1819
value,
19-
state: JsonTreeWrapping {
20+
wrap: JsonTreeWrapping {
2021
max_rows: 1,
2122
max_width: JsonTreeMaxWidth::UiAvailableWidth,
2223
},
24+
use_maximum_max_rows: false,
2325
}
2426
}
2527
}
@@ -34,43 +36,62 @@ impl Show for WrappingExample {
3436
ui.add_space(10.0);
3537

3638
ui.label(egui::RichText::new("Max Rows:").monospace());
37-
ui.add(
38-
DragValue::new(&mut self.state.max_rows)
39-
.speed(0.1)
40-
.range(1..=5),
41-
);
39+
ui.horizontal(|ui| {
40+
if ui
41+
.radio_value(&mut self.use_maximum_max_rows, false, "Custom")
42+
.changed()
43+
{
44+
self.wrap.max_rows = 1;
45+
}
46+
47+
if !self.use_maximum_max_rows {
48+
ui.add(
49+
DragValue::new(&mut self.wrap.max_rows)
50+
.speed(0.1)
51+
.range(1..=10),
52+
);
53+
}
54+
});
55+
56+
if ui
57+
.radio_value(&mut self.use_maximum_max_rows, true, "usize::MAX")
58+
.clicked()
59+
{
60+
self.wrap.max_rows = usize::MAX;
61+
}
4262

4363
ui.label(egui::RichText::new("Max Width:").monospace());
4464
ui.horizontal(|ui| {
4565
if ui
4666
.radio(
47-
matches!(self.state.max_width, JsonTreeMaxWidth::Pt(_)),
67+
matches!(self.wrap.max_width, JsonTreeMaxWidth::Pt(_)),
4868
"Points",
4969
)
5070
.clicked()
71+
&& !matches!(self.wrap.max_width, JsonTreeMaxWidth::Pt(_))
5172
{
52-
self.state.max_width = JsonTreeMaxWidth::Pt(100.0);
73+
self.wrap.max_width = JsonTreeMaxWidth::Pt(100.0);
5374
}
54-
if let JsonTreeMaxWidth::Pt(ref mut pts) = &mut self.state.max_width {
75+
if let JsonTreeMaxWidth::Pt(ref mut pts) = &mut self.wrap.max_width {
5576
ui.add(DragValue::new(pts).speed(10.0).range(100.0..=10000.0));
5677
}
5778
});
5879

5980
if ui
6081
.radio(
61-
matches!(self.state.max_width, JsonTreeMaxWidth::UiAvailableWidth),
82+
matches!(self.wrap.max_width, JsonTreeMaxWidth::UiAvailableWidth),
6283
"Available Width",
6384
)
6485
.clicked()
6586
{
66-
self.state.max_width = JsonTreeMaxWidth::UiAvailableWidth;
87+
self.wrap.max_width = JsonTreeMaxWidth::UiAvailableWidth;
6788
}
6889

6990
JsonTree::new(self.title(), &self.value)
7091
.style(JsonTreeStyle::new().wrap(JsonTreeWrappingParams {
71-
value_no_parent: self.state,
72-
value_expanded_parent: self.state,
73-
value_collapsed_root: self.state,
92+
value_no_parent: self.wrap,
93+
value_expanded_parent: self.wrap,
94+
value_collapsed_root: self.wrap,
7495
}))
7596
.default_expand(DefaultExpand::All)
7697
.show(ui);

0 commit comments

Comments
 (0)