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

Use newtypes for units Px, Pct, and Auto #112

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/animations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ fn app_view() -> impl View {
s.border(1.0)
.background(Color::RED)
.color(Color::BLACK)
.padding_px(10.0)
.margin_px(20.0)
.size_px(120.0, 120.0)
.padding(10.0)
.margin(20.0)
.size(120.0, 120.0)
})
.active_style(|s| s.color(Color::BLACK))
.animation(
Expand All @@ -56,8 +56,8 @@ fn app_view() -> impl View {
.style(|s| {
s.border(5.0)
.background(Color::BLUE)
.padding_px(10.0)
.size_px(400.0, 400.0)
.padding(10.0)
.size(400.0, 400.0)
.color(Color::BLACK)
})
.animation(
Expand Down
15 changes: 8 additions & 7 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use floem::{
peniko::Color,
reactive::create_signal,
unit::UnitExt,
view::View,
views::{label, stack, text, Decorators},
};

fn app_view() -> impl View {
let (counter, set_counter) = create_signal(0);
stack((
label(move || format!("Value: {}", counter.get())).style(|s| s.padding_px(10.0)),
label(move || format!("Value: {}", counter.get())).style(|s| s.padding(10.0)),
stack((
text("Increment")
.style(|s| {
s.border_radius(10.0)
.padding_px(10.0)
.padding(10.0)
.background(Color::WHITE)
.box_shadow_blur(5.0)
})
Expand All @@ -38,8 +39,8 @@ fn app_view() -> impl View {
s.box_shadow_blur(5.0)
.background(Color::WHITE)
.border_radius(10.0)
.padding_px(10.0)
.margin_left_px(10.0)
.padding(10.0)
.margin_left(10.0)
})
.hover_style(|s| s.background(Color::rgb8(244, 67, 54)))
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
Expand All @@ -55,8 +56,8 @@ fn app_view() -> impl View {
.style(|s| {
s.box_shadow_blur(5.0)
.border_radius(10.0)
.padding_px(10.0)
.margin_left_px(10.0)
.padding(10.0)
.margin_left(10.0)
.background(Color::LIGHT_BLUE)
})
.disabled_style(|s| s.background(Color::LIGHT_GRAY))
Expand All @@ -67,7 +68,7 @@ fn app_view() -> impl View {
)),
))
.style(|s| {
s.size_pct(100.0, 100.0)
s.size(100.pct(), 100.pct())
.flex_col()
.items_center()
.justify_center()
Expand Down
4 changes: 2 additions & 2 deletions examples/draggable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fn app_view() -> impl View {
.style(|s| {
s.border(1.0)
.border_radius(2.0)
.padding_px(10.0)
.margin_left_px(10.0)
.padding(10.0)
.margin_left(10.0)
})
.hover_style(|s| {
s.background(Color::rgb8(244, 67, 54))
Expand Down
11 changes: 6 additions & 5 deletions examples/responsive/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use floem::{
peniko::Color,
responsive::{range, ScreenSize},
unit::UnitExt,
view::View,
views::{label, stack, Decorators},
};
Expand All @@ -11,8 +12,8 @@ fn app_view() -> impl View {
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding_px(10.0)
.margin_horiz_px(10.0)
.padding(10.0)
.margin_horiz(10.0)
})
.responsive_style(ScreenSize::XS, |s| s.background(Color::CYAN))
.responsive_style(ScreenSize::SM, |s| s.background(Color::PURPLE))
Expand All @@ -21,16 +22,16 @@ fn app_view() -> impl View {
.responsive_style(ScreenSize::XL, |s| s.background(Color::PINK))
.responsive_style(ScreenSize::XXL, |s| s.background(Color::RED))
.responsive_style(range(ScreenSize::XS..ScreenSize::LG), |s| {
s.width_pct(90.0).max_width_px(500.0)
s.width(90.0.pct()).max_width(500.0)
})
.responsive_style(
// equivalent to: range(ScreenSize::LG..)
ScreenSize::LG | ScreenSize::XL | ScreenSize::XXL,
|s| s.width_px(300.0),
|s| s.width(300.0),
),)
})
.style(|s| {
s.size_pct(100.0, 100.0)
s.size(100.pct(), 100.pct())
.flex_col()
.justify_center()
.items_center()
Expand Down
9 changes: 5 additions & 4 deletions examples/virtual_list/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use floem::{
reactive::create_signal,
unit::UnitExt,
view::View,
views::virtual_list,
views::Decorators,
Expand All @@ -17,15 +18,15 @@ fn app_view() -> impl View {
VirtualListItemSize::Fixed(Box::new(|| 20.0)),
move || long_list.get(),
move |item| *item,
move |item| label(move || item.to_string()).style(|s| s.height_px(20.0)),
move |item| label(move || item.to_string()).style(|s| s.height(20.0)),
)
.style(|s| s.flex_col()),
)
.style(|s| s.width_px(100.0).height_pct(100.0).border(1.0)),
.style(|s| s.width(100.0).height(100.pct()).border(1.0)),
)
.style(|s| {
s.size_pct(100.0, 100.0)
.padding_vert_px(20.0)
s.size(100.pct(), 100.pct())
.padding_vert(20.0)
.flex_col()
.items_center()
})
Expand Down
10 changes: 5 additions & 5 deletions examples/widget-gallery/src/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn button_view() -> impl View {
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(|s| s.border(1.0).border_radius(10.0).padding_px(10.0))
.style(|s| s.border(1.0).border_radius(10.0).padding(10.0))
}),
form_item("Styled Button:".to_string(), 120.0, || {
label(|| "Click me")
Expand All @@ -31,8 +31,8 @@ pub fn button_view() -> impl View {
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding_px(10.0)
.margin_left_px(10.0)
.padding(10.0)
.margin_left(10.0)
.background(Color::YELLOW_GREEN)
.color(Color::DARK_GREEN)
.cursor(CursorStyle::Pointer)
Expand All @@ -52,7 +52,7 @@ pub fn button_view() -> impl View {
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding_px(10.0)
.padding(10.0)
.color(Color::GRAY)
})
.hover_style(|s| s.background(Color::rgb8(224, 224, 224)))
Expand All @@ -65,7 +65,7 @@ pub fn button_view() -> impl View {
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(|s| s.border(1.0).border_radius(10.0).padding_px(10.0))
.style(|s| s.border(1.0).border_radius(10.0).padding(10.0))
}),
)
})
Expand Down
4 changes: 2 additions & 2 deletions examples/widget-gallery/src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ pub fn menu_view() -> impl View {
stack({
(
label(|| "Click me (Popout menu)")
.base_style(|s| s.padding_px(10.0).margin_bottom_px(10.0).border(1.0))
.base_style(|s| s.padding(10.0).margin_bottom(10.0).border(1.0))
.popout_menu(|| {
Menu::new("")
.entry(MenuItem::new("I am a menu item!"))
.separator()
.entry(MenuItem::new("I am another menu item"))
}),
label(|| "Right click me (Context menu)")
.base_style(|s| s.padding_px(10.0).border(1.0))
.base_style(|s| s.padding(10.0).border(1.0))
.context_menu(|| {
Menu::new("")
.entry(MenuItem::new("Menu item"))
Expand Down
17 changes: 9 additions & 8 deletions examples/widget-gallery/src/form.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use floem::{
cosmic_text::Weight,
unit::UnitExt,
view::View,
view_tuple::ViewTuple,
views::{container, label, stack, Decorators},
Expand All @@ -9,9 +10,9 @@ pub fn form<VT: ViewTuple + 'static>(children: VT) -> impl View {
stack(children).style(|s| {
s.flex_col()
.items_start()
.margin_px(10.0)
.padding_px(10.0)
.width_pct(100.0)
.margin(10.0)
.padding(10.0)
.width(100.pct())
})
}

Expand All @@ -23,17 +24,17 @@ pub fn form_item<V: View + 'static>(
container(
stack((
container(label(move || item_label.clone()).style(|s| s.font_weight(Weight::BOLD)))
.style(move |s| s.width_px(label_width).justify_end().margin_right_px(10.0)),
.style(move |s| s.width(label_width).justify_end().margin_right(10.0)),
view_fn(),
))
.style(|s| s.flex_row().items_start()),
)
.style(|s| {
s.flex_row()
.items_center()
.margin_bottom_px(10.0)
.padding_px(10.0)
.width_pct(100.0)
.min_height_px(32.0)
.margin_bottom(10.0)
.padding(10.0)
.width(100.pct())
.min_height(32.0)
})
}
6 changes: 3 additions & 3 deletions examples/widget-gallery/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn text_input_view() -> impl View {
(
form_item("Simple Input:".to_string(), 120.0, move || {
text_input(text)
.style(|s| s.border(1.0).height_px(32.0))
.style(|s| s.border(1.0).height(32.0))
.keyboard_navigatable()
}),
form_item("Styled Input:".to_string(), 120.0, move || {
Expand All @@ -25,7 +25,7 @@ pub fn text_input_view() -> impl View {
.background(Color::rgb8(224, 224, 224))
.border_radius(15.0)
.border_color(Color::rgb8(189, 189, 189))
.padding_px(10.0)
.padding(10.0)
.cursor(CursorStyle::Text)
})
.hover_style(|s| s.border_color(Color::rgb8(66, 66, 66)))
Expand All @@ -39,7 +39,7 @@ pub fn text_input_view() -> impl View {
.background(Color::rgb8(224, 224, 224))
.border_radius(15.0)
.border_color(Color::rgb8(189, 189, 189))
.padding_px(10.0)
.padding(10.0)
.cursor(CursorStyle::Text)
})
.hover_style(|s| s.border_color(Color::rgb8(66, 66, 66)))
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn label_view() -> impl View {
form_item("Styled Label:".to_string(), 120.0, || {
label(move || "This is a styled label".to_owned()).style(|s| {
s.background(Color::YELLOW)
.padding_px(10.0)
.padding(10.0)
.color(Color::GREEN)
.font_weight(Weight::BOLD)
.font_style(FontStyle::Italic)
Expand Down
25 changes: 13 additions & 12 deletions examples/widget-gallery/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use floem::{
keyboard::Key,
peniko::Color,
reactive::create_signal,
style::{CursorStyle, Dimension, JustifyContent},
style::{CursorStyle, JustifyContent},
unit::UnitExt,
view::View,
views::{
checkbox, container, label, scroll, stack, virtual_list, Decorators, VirtualListDirection,
Expand Down Expand Up @@ -32,11 +33,11 @@ fn simple_list() -> impl View {
VirtualListItemSize::Fixed(Box::new(|| 20.0)),
move || long_list.get(),
move |item| *item,
move |item| label(move || item.to_string()).style(|s| s.height_px(24.0)),
move |item| label(move || item.to_string()).style(|s| s.height(24.0)),
)
.style(|s| s.flex_col()),
)
.style(|s| s.width_px(100.0).height_px(300.0).border(1.0))
.style(|s| s.width(100.0).height(300.0).border(1.0))
}

fn enhanced_list() -> impl View {
Expand Down Expand Up @@ -67,7 +68,7 @@ fn enhanced_list() -> impl View {
true
}),
label(move || item.to_string())
.style(|s| s.height_px(32.0).font_size(32.0)),
.style(|s| s.height(32.0).font_size(32.0)),
container({
label(move || " X ")
.on_click(move |_| {
Expand All @@ -78,24 +79,24 @@ fn enhanced_list() -> impl View {
true
})
.style(|s| {
s.height_px(18.0)
s.height(18.0)
.font_weight(Weight::BOLD)
.color(Color::RED)
.border(1.0)
.border_color(Color::RED)
.border_radius(16.0)
.margin_right_px(5.0)
.margin_right(5.0)
})
.hover_style(|s| s.color(Color::WHITE).background(Color::RED))
})
.style(|s| {
s.flex_basis(Dimension::Points(0.0))
s.flex_basis(0)
.flex_grow(1.0)
.justify_content(Some(JustifyContent::FlexEnd))
}),
)
})
.style(move |s| s.height_px(item_height).width_px(list_width).items_center())
.style(move |s| s.height(item_height).width(list_width).items_center())
})
.on_click(move |_| {
set_selected.update(|v: &mut usize| {
Expand Down Expand Up @@ -129,8 +130,8 @@ fn enhanced_list() -> impl View {
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(move |s| {
s.flex_row()
.width_pct(list_width)
.height_px(item_height)
.width(list_width.pct())
.height(item_height)
.apply_if(index == selected.get(), |s| s.background(Color::GRAY))
.apply_if(index != 0, |s| {
s.border_top(1.0).border_color(Color::LIGHT_GRAY)
Expand All @@ -139,7 +140,7 @@ fn enhanced_list() -> impl View {
.hover_style(|s| s.background(Color::LIGHT_GRAY).cursor(CursorStyle::Pointer))
},
)
.style(move |s| s.flex_col().width_px(list_width)),
.style(move |s| s.flex_col().width(list_width)),
)
.style(move |s| s.width_px(list_width).height_px(300.0).border(1.0))
.style(move |s| s.width(list_width).height(300.0).border(1.0))
}
Loading
Loading