Skip to content

Commit 3e985aa

Browse files
committed
Add Stack view
1 parent 6a88683 commit 3e985aa

File tree

4 files changed

+492
-8
lines changed

4 files changed

+492
-8
lines changed

masonry/src/widgets/stack.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ impl Stack {
222222
pub fn child_mut<'t>(
223223
this: &'t mut WidgetMut<'_, Self>,
224224
idx: usize,
225-
) -> Option<WidgetMut<'t, dyn Widget>> {
225+
) -> WidgetMut<'t, dyn Widget> {
226226
let child = &mut this.widget.children[idx];
227-
Some(this.ctx.get_mut(&mut child.widget))
227+
this.ctx.get_mut(&mut child.widget)
228228
}
229229

230230
/// Updates the alignment for the child at `idx`,
@@ -629,7 +629,7 @@ mod tests {
629629
let mut harness =
630630
TestHarness::create_with_size(default_property_set(), widget, window_size);
631631
harness.edit_root_widget(|mut stack| {
632-
let mut child = Stack::child_mut(&mut stack, 1).unwrap();
632+
let mut child = Stack::child_mut(&mut stack, 1);
633633
assert_eq!(
634634
child
635635
.try_downcast::<Label>()
@@ -639,9 +639,6 @@ mod tests {
639639
.to_string(),
640640
"world"
641641
);
642-
std::mem::drop(child);
643-
644-
assert!(Stack::child_mut(&mut stack, 2).is_none());
645642
});
646643

647644
// TODO - test out-of-bounds access?

xilem/examples/to_do_mvc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use winit::error::EventLoopError;
1010
use xilem::style::Style as _;
11-
use xilem::view::{Axis, button, checkbox, flex, flex_row, text_input};
11+
use xilem::view::{Axis, button, checkbox, flex, flex_row, stack, text_input};
1212
use xilem::{EventLoop, EventLoopBuilder, InsertNewline, WidgetView, WindowOptions, Xilem};
1313

1414
struct Task {
@@ -71,7 +71,7 @@ fn app_logic(task_list: &mut TaskList) -> impl WidgetView<TaskList> + use<> {
7171
})
7272
.collect::<Vec<_>>();
7373

74-
flex((first_line, tasks)).padding(50.)
74+
stack((first_line, tasks)).padding(50.)
7575
}
7676

7777
fn run(event_loop: EventLoopBuilder) -> Result<(), EventLoopError> {

xilem/src/view/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub use sized_box::*;
3232
mod spinner;
3333
pub use spinner::*;
3434

35+
mod stack;
36+
pub use stack::*;
37+
3538
mod image;
3639
pub use image::*;
3740

0 commit comments

Comments
 (0)