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

Experimental style changes #110

Closed
wants to merge 9 commits into from
Closed
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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ rustc-hash = "1.1.0"
smallvec = "1.10.0"
educe = "0.4.20"
taffy = "0.3.13"
rfd = { version = "0.11.4", default-features = false, features = ["xdg-portal"] }
rfd = { version = "0.11.4", default-features = false, features = [
"xdg-portal",
] }
raw-window-handle = "0.5.1"
kurbo = { version = "0.9.5", features = ["serde"] }
unicode-segmentation = "1.10.0"
Expand All @@ -21,6 +23,7 @@ crossbeam-channel = "0.5.6"
once_cell = "1.17.1"
im = "15.1.0"
parking_lot = { version = "0.12.1" }
dyn-clone = "1.0.14"
floem_renderer = { path = "renderer" }
floem_vger = { path = "vger" }
floem_reactive = { path = "reactive" }
Expand Down
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
35 changes: 13 additions & 22 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use floem::{
peniko::Color,
reactive::create_signal,
style::{box_shadow, Style},
unit::Pct,
view::View,
views::{label, stack, text, Decorators},
};

fn app_view() -> impl View {
let button_style = |s: Style| {
s.p(10)
.border_radius(8)
.box_shadow(box_shadow(10, 10, 8, 2, Color::rgb(0.6, 0.6, 0.6)))
};

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.p(10)),
stack((
text("Increment")
.style(|s| {
s.border_radius(10.0)
.padding_px(10.0)
.background(Color::WHITE)
.box_shadow_blur(5.0)
})
.style(move |s| button_style(s).background(Color::WHITE))
.on_click({
move |_| {
set_counter.update(|value| *value += 1);
Expand All @@ -34,13 +37,7 @@ fn app_view() -> impl View {
true
}
})
.style(|s| {
s.box_shadow_blur(5.0)
.background(Color::WHITE)
.border_radius(10.0)
.padding_px(10.0)
.margin_left_px(10.0)
})
.style(move |s| button_style(s).background(Color::WHITE).ml(16.0))
.hover_style(|s| s.background(Color::rgb8(244, 67, 54)))
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
.keyboard_navigatable()
Expand All @@ -52,13 +49,7 @@ fn app_view() -> impl View {
true
})
.disabled(move || counter.get() == 0)
.style(|s| {
s.box_shadow_blur(5.0)
.border_radius(10.0)
.padding_px(10.0)
.margin_left_px(10.0)
.background(Color::LIGHT_BLUE)
})
.style(move |s| button_style(s).ml(16).background(Color::LIGHT_BLUE))
.disabled_style(|s| s.background(Color::LIGHT_GRAY))
.hover_style(|s| s.background(Color::LIGHT_YELLOW))
.active_style(|s| s.color(Color::WHITE).background(Color::YELLOW_GREEN))
Expand All @@ -67,7 +58,7 @@ fn app_view() -> impl View {
)),
))
.style(|s| {
s.size_pct(100.0, 100.0)
s.size(Pct(100.0), Pct(100.0))
.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::Pct,
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(Pct(90.0)).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(Pct(100.0), Pct(100.0))
.flex_col()
.justify_center()
.items_center()
Expand Down
10 changes: 5 additions & 5 deletions examples/virtual_list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use floem::{
view::View,
views::virtual_list,
views::Decorators,
views::{container, label, scroll, VirtualListDirection, VirtualListItemSize},
views::{container, label, scroll, VirtualListDirection, VirtualListItemSize}, unit::Pct,
};

fn app_view() -> impl View {
Expand All @@ -17,15 +17,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(Pct(100.0)).border(1.0)),
)
.style(|s| {
s.size_pct(100.0, 100.0)
.padding_vert_px(20.0)
s.size(Pct(100.0), Pct(100.0))
.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::Pct,
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(Pct(100.0))
})
}

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(Pct(100.0))
.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
Loading