hecrj / coffee

An opinionated 2D game engine for Rust
https://docs.rs/coffee
MIT License
1.08k stars 55 forks source link

Padding around a widget #109

Closed dlight closed 4 years ago

dlight commented 4 years ago

Is there a way to set padding around a widget like ui::Image or ui::Text? I see that examples/image.rs, Text::height is used to set the height in pixels (and, since this was in a column, this results in some padding if the height is larger than the computed height of the text). In the same example, Column::spacing is used to set a constant amount of spacing between the itens of the column (but not before the first and after the last).

Both aren't what I'm looking for; there's also ui::core::Style::padding but I'm unsure how to use this with the current widgets (is it necessary to add a padding method to the widgets, like they have a height method? Shouldn't those methods be added to a trait?).

(ps: since the ui code is being moved to iced perhaps this issue belongs there, but coffee doesn't used iced yet)

dlight commented 4 years ago

It would be useful if ui::core::Style::padding could optionally add different amounts of padding to each side, like css - and have it exposed to each widget (letting the user either set the same amount for all 4 sides, or different amounts)

hecrj commented 4 years ago

You can wrap your widget in a Column and use Column::padding.

A different amount of padding per side is simply not supported yet. Styling in Iced will get reworked soon.

hecrj commented 4 years ago

For instance, the ui example uses it here: https://github.com/hecrj/coffee/blob/8e2da7b229afb641b9bc99c13863d764dd461f9f/examples/ui.rs#L101

dlight commented 4 years ago

Thanks!