-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack
widget
#2405
Stack
widget
#2405
Conversation
It can be used to stack elements on top of each other!
5acda41
to
9492da1
Compare
let limits = layout::Limits::new(Size::ZERO, size); | ||
|
||
let nodes = std::iter::once(base) | ||
.chain(self.children[1..].iter().zip(&mut tree.children[1..]).map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible index error? We only check is_empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll just return an empty slice, which is what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did I not know this? I guess the spread operator here protects it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's a range equivalent to 1..self.children.len()
. Thus, empty with a single child.
This PR implements a simple
Stack
widget that can be used to display elements on top of each other.The
Stack
uses the first element as its base layer and every consecutive element is displayed on top of the previous one. The base element defines the intrinsic size of theStack
, so the elements on top can easily position themselves using other existing widgets (e.g.container
).Like
column
androw
, it comes with both its function and macro helpers.The
bezier_tool
example showcases how we can use this new widget to show the "Clear" button at the top right corner of theCanvas
:This produces (amazing art not included!):