You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Changes
### Masonry
- Added new padding attribute to sized_box Masonry widget.
- 3 unit tests demonstrating how padding is used.
### Xilem
- Added `Padding` struct with convenience methods for working with
paddings.
- Updated `http_cats` example to use padding when more convenient and
fixed hack.
## Examples
```rs
sized_box(label("hello world")).padding(10.) // Equal padding on all edges
sized_box(label("hello world")).padding(Padding::top(10.)) // Padding only on top edge
sized_box(label("hello world")).padding((10., 20., 30., 40.)) // Different padding for each edge
```
## HTTP Cats
Added padding on the left in the `http_cats` example, to make it more
balanced with the right side.
<img width="912" alt="Screenshot 2024-11-10 at 16 22 52"
src="https://github.com/user-attachments/assets/ce5fd4e6-412b-46c1-9387-6886ef97e653">
## Discussion
### Rename `sized_box` to `frame`?
In swiftUI the view modifier
[`.frame()`](https://developer.apple.com/documentation/swiftui/view/frame(width:height:alignment:))
is used to change the size of a view. I think the name `frame` better
describes the purpose of `sized_box`, since it also does backgrounds,
borders (and now padding). So I wanted to suggest that `sized_box` be
renamed to `frame`.
### Add `SizedBoxExt` for better ergonomics?
Similar to
[`FlexExt`](https://github.com/linebender/xilem/blob/62588565692584e16197fb6d19cd3b41c104b675/xilem/src/view/flex.rs#L340C11-L340C18)
and
[`GridExt`](https://github.com/linebender/xilem/blob/62588565692584e16197fb6d19cd3b41c104b675/xilem/src/view/grid.rs#L248),
I was thinking that a new `SizedBoxExt` could be introduced to easily
wrap any view in a `sized_box`, something like the following.
```rust
pub trait SizedBoxExt<State, Action>: WidgetView<State, Action> {
fn sized_box(self) -> SizedBox<Self, State, Action> {
sized_box(self)
}
}
```
This would allow for chaining modifiers like this:
```rust
label("Hello world")
.text_size(20.)
.sized_box() // After this padding, background, width, height can be added
.padding(20.)
```
Or even somthing more advanced like this:
```rust
label("Hello world")
.sized_box()
.padding(20.)
.background(Color::Teal)
.border(Color::Blue, 4.)
.sized_box() // By wrapping in another sized box we add another border rather than overwriting the previous one
.border(Color::Magenta, 4.)
```
0 commit comments