iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
22.96k stars 1.06k forks source link

`Stack` widget #2405

Closed hecrj closed 3 weeks ago

hecrj commented 3 weeks ago

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 the Stack, so the elements on top can easily position themselves using other existing widgets (e.g. container).

Like column and row, 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 the Canvas:

container(stack![
    self.bezier.view(&self.curves).map(Message::AddCurve),
    container(
        button("Clear")
            .style(button::danger)
            .on_press(Message::Clear)
    )
    .padding(10)
    .width(Length::Fill)
    .align_x(alignment::Horizontal::Right),
])
.padding(20)
.into()

This produces (amazing art not included!):

image