Skip to content
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

Improved view ergonomics #2504

Merged
merged 7 commits into from
Jul 12, 2024
Merged

Improved view ergonomics #2504

merged 7 commits into from
Jul 12, 2024

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Jul 12, 2024

This PR improves some of the ergonomics of view code:

  • The Fill, FillPortion, and Shrink variants of Length are re-exported by the root crate. Effectively, this means we can now import these directly:
use iced::widget::container;
use iced::Fill;

container("Yay!").width(Fill)
  • The Center, Left, Right, Top, and Bottom variants of the different alignment enums are also re-exported. Thus, we can now write:
use iced::widget::text;
use iced::{Center, Fill};

text("I am centered!").width(Fill).align_x(Center)
  • align_items in Column and Row have been renamed to align_x and align_y respectively.
  • horizontal_alignment and vertical_alignment in Text have been renamed to align_x and align_y.
  • The padding module exposes free functions to build Padding values and the type has methods of the same name that work as setters. Thus, we can write:
use iced::widget::container;
use iced::padding;

container("I have a padding of 10 all around, except my right side!")
    .padding(padding::all(10).right(0))
  • The border module has received a similar treatment to padding:
use iced::widget::container;
use iced::border;

container("My top right corner isn't rounded!")
    .style(|theme: &Theme| container::Style {
        border: border::rounded(border::radius(10).top_right(0)).color(Color::BLACK).width(2),
        ..container::Style::default()
    })

Closes #2260.

@hecrj hecrj added improvement An internal improvement feature New feature or request developer experience change addition labels Jul 12, 2024
@hecrj hecrj added this to the 0.13 milestone Jul 12, 2024
@derezzedex
Copy link
Member

Can we do the same for ContentFit?

@hecrj
Copy link
Member Author

hecrj commented Jul 12, 2024

I don't think those are that common, since they are only used for images.

@hecrj hecrj merged commit 8cadd3b into master Jul 12, 2024
24 checks passed
@hecrj hecrj deleted the view-ergonomics branch July 12, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition change developer experience feature New feature or request improvement An internal improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants