Skip to content

Commit

Permalink
Fix doc test and remove to_string from examples (#102)
Browse files Browse the repository at this point in the history
* Fix doc test and remove to_string from examples

* Remove to_string from README
  • Loading branch information
jrmoulton authored Sep 3, 2023
1 parent db24ff7 commit 7dc55d3
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 75 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ fn app_view() -> impl View {
label(move || format!("Value: {}", counter.get())),
stack(|| {
(
label(|| "Increment".to_string())
label(|| "Increment")
.on_click(move |_| {
set_counter.update(|value| *value += 1);
true
}),
label(|| "Decrement".to_string())
label(|| "Decrement")
.on_click(move |_| {
set_counter.update(|value| *value -= 1);
true
Expand Down
2 changes: 1 addition & 1 deletion examples/animations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn app_view() -> impl View {
let (is_hovered, set_is_hovered) = create_signal(false);

stack(|| {
(label(|| "Hover or click me!".to_string())
(label(|| "Hover or click me!")
.on_click(move |_| {
set_counter.update(|value| *value += 1.0);
true
Expand Down
6 changes: 3 additions & 3 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn app_view() -> impl View {
label(move || format!("Value: {}", counter.get())).style(|s| s.padding_px(10.0)),
stack(|| {
(
label(|| "Increment".to_string())
label(|| "Increment")
.style(|s| {
s.border_radius(10.0)
.padding_px(10.0)
Expand All @@ -29,7 +29,7 @@ fn app_view() -> impl View {
.active_style(|s| s.color(Color::WHITE).background(Color::DARK_GREEN))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
label(|| "Decrement".to_string())
label(|| "Decrement")
.on_click({
move |_| {
set_counter.update(|value| *value -= 1);
Expand All @@ -47,7 +47,7 @@ fn app_view() -> impl View {
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
label(|| "Reset to 0".to_string())
label(|| "Reset to 0")
.on_click(move |_| {
println!("Reset counter pressed"); // will not fire if button is disabled
set_counter.update(|value| *value = 0);
Expand Down
2 changes: 1 addition & 1 deletion examples/draggable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use floem::{
};

fn app_view() -> impl View {
label(|| "Drag me!".to_string())
label(|| "Drag me!")
.style(|s| {
s.border(1.0)
.border_radius(2.0)
Expand Down
2 changes: 1 addition & 1 deletion examples/responsive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use floem::{

fn app_view() -> impl View {
stack(|| {
(label(|| "Resize the window to see the magic".to_string())
(label(|| "Resize the window to see the magic")
.style(|s| {
s.border(1.0)
.border_radius(10.0)
Expand Down
8 changes: 4 additions & 4 deletions examples/widget-gallery/src/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn button_view() -> impl View {
form(|| {
(
form_item("Basic Button:".to_string(), 120.0, || {
label(|| "Click me".to_string())
label(|| "Click me")
.on_click(|_| {
println!("Button clicked");
true
Expand All @@ -21,7 +21,7 @@ pub fn button_view() -> impl View {
.style(|s| s.border(1.0).border_radius(10.0).padding_px(10.0))
}),
form_item("Styled Button:".to_string(), 120.0, || {
label(|| "Click me".to_string())
label(|| "Click me")
.on_click(|_| {
println!("Button clicked");
true
Expand All @@ -41,7 +41,7 @@ pub fn button_view() -> impl View {
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
}),
form_item("Distabled Button:".to_string(), 120.0, || {
label(|| "Click me".to_string())
label(|| "Click me")
.disabled(|| true)
.on_click(|_| {
println!("Button clicked");
Expand All @@ -58,7 +58,7 @@ pub fn button_view() -> impl View {
.hover_style(|s| s.background(Color::rgb8(224, 224, 224)))
}),
form_item("Secondary click button:".to_string(), 120.0, || {
label(|| "Right click me".to_string())
label(|| "Right click me")
.on_secondary_click(|_| {
println!("Secondary mouse button click.");
true
Expand Down
4 changes: 2 additions & 2 deletions examples/widget-gallery/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn checkbox_view() -> impl View {
(
checkbox(is_checked)
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
label(|| "Check me!".to_string()),
label(|| "Check me!"),
)
})
.on_click(move |_| {
Expand All @@ -37,7 +37,7 @@ pub fn checkbox_view() -> impl View {
(
checkbox(is_checked)
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
label(|| "Check me!".to_string()),
label(|| "Check me!"),
)
})
.style(|s| s.color(Color::GRAY))
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 @@ -7,15 +7,15 @@ use floem::{
pub fn menu_view() -> impl View {
stack(move || {
(
label(|| "Click me (Popout menu)".to_string())
label(|| "Click me (Popout menu)")
.base_style(|s| s.padding_px(10.0).margin_bottom_px(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)".to_string())
label(|| "Right click me (Context menu)")
.base_style(|s| s.padding_px(10.0).border(1.0))
.context_menu(|| {
Menu::new("")
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn form_item<V: View + 'static>(
stack(|| {
(
container(|| {
label(move || item_label.to_string()).style(|s| s.font_weight(Weight::BOLD))
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)),
view_fn(),
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn enhanced_list() -> impl View {
label(move || item.to_string())
.style(|s| s.height_px(32.0).font_size(32.0)),
container(move || {
label(move || " X ".to_string())
label(move || " X ")
.on_click(move |_| {
print!("Item Removed");
set_long_list.update(|x| {
Expand Down
92 changes: 45 additions & 47 deletions examples/widget-gallery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,57 +44,55 @@ fn app_view() -> impl View {
.iter()
.position(|it| *it == item)
.unwrap();
stack(
|| (label(move || item.to_string()).style(|s| s.font_size(24.0)),),
)
.on_click(move |_| {
set_active_tab.update(|v: &mut usize| {
*v = tabs
.get_untracked()
.iter()
.position(|it| *it == item)
.unwrap();
});
true
})
.on_event(EventListener::KeyDown, move |e| {
if let Event::KeyDown(key_event) = e {
let active = active_tab.get();
match key_event.key.logical_key {
Key::ArrowUp => {
if active > 0 {
set_active_tab.update(|v| *v -= 1)
stack(|| (label(move || item).style(|s| s.font_size(24.0)),))
.on_click(move |_| {
set_active_tab.update(|v: &mut usize| {
*v = tabs
.get_untracked()
.iter()
.position(|it| *it == item)
.unwrap();
});
true
})
.on_event(EventListener::KeyDown, move |e| {
if let Event::KeyDown(key_event) = e {
let active = active_tab.get();
match key_event.key.logical_key {
Key::ArrowUp => {
if active > 0 {
set_active_tab.update(|v| *v -= 1)
}
true
}
true
}
Key::ArrowDown => {
if active < tabs.get().len() - 1 {
set_active_tab.update(|v| *v += 1)
Key::ArrowDown => {
if active < tabs.get().len() - 1 {
set_active_tab.update(|v| *v += 1)
}
true
}
true
_ => false,
}
_ => false,
} else {
false
}
} else {
false
}
})
.keyboard_navigatable()
.draggable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(move |s| {
s.flex_row()
.width_pct(100.0)
.height_px(32.0)
.border_bottom(1.0)
.border_color(Color::LIGHT_GRAY)
.apply_if(index == active_tab.get(), |s| {
s.background(Color::GRAY)
})
})
.hover_style(|s| {
s.background(Color::LIGHT_GRAY).cursor(CursorStyle::Pointer)
})
})
.keyboard_navigatable()
.draggable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(move |s| {
s.flex_row()
.width_pct(100.0)
.height_px(32.0)
.border_bottom(1.0)
.border_color(Color::LIGHT_GRAY)
.apply_if(index == active_tab.get(), |s| {
s.background(Color::GRAY)
})
})
.hover_style(|s| {
s.background(Color::LIGHT_GRAY).cursor(CursorStyle::Pointer)
})
},
)
.style(|s| s.flex_col().width_px(140.0))
Expand Down
12 changes: 6 additions & 6 deletions examples/window-scale/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn app_view() -> impl View {
label(move || format!("Value: {}", counter.get())).style(|s| s.padding_px(10.0)),
stack(|| {
(
label(|| "Increment".to_string())
label(|| "Increment")
.style(|s| s.border(1.0).border_radius(10.0).padding_px(10.0))
.on_click(move |_| {
set_counter.update(|value| *value += 1);
Expand All @@ -23,7 +23,7 @@ fn app_view() -> impl View {
.active_style(|s| s.color(Color::WHITE).background(Color::DARK_GREEN))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
label(|| "Decrement".to_string())
label(|| "Decrement")
.on_click(move |_| {
set_counter.update(|value| *value -= 1);
true
Expand All @@ -38,7 +38,7 @@ fn app_view() -> impl View {
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
label(|| "Reset to 0".to_string())
label(|| "Reset to 0")
.on_click(move |_| {
println!("Reset counter pressed"); // will not fire if button is disabled
set_counter.update(|value| *value = 0);
Expand All @@ -61,7 +61,7 @@ fn app_view() -> impl View {
}),
stack(|| {
(
label(|| "Zoom In".to_string())
label(|| "Zoom In")
.on_click(move |_| {
window_scale.update(|scale| *scale *= 1.2);
true
Expand All @@ -74,7 +74,7 @@ fn app_view() -> impl View {
.padding_px(10.0)
})
.hover_style(|s| s.background(Color::LIGHT_GREEN)),
label(|| "Zoom Out".to_string())
label(|| "Zoom Out")
.on_click(move |_| {
window_scale.update(|scale| *scale /= 1.2);
true
Expand All @@ -87,7 +87,7 @@ fn app_view() -> impl View {
.padding_px(10.0)
})
.hover_style(|s| s.background(Color::LIGHT_GREEN)),
label(|| "Zoom Reset".to_string())
label(|| "Zoom Reset")
.disabled(move || window_scale.get() == 1.0)
.on_click(move |_| {
window_scale.set(1.0);
Expand Down
8 changes: 4 additions & 4 deletions src/views/decorator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ pub trait Decorators: View + Sized {
/// # use floem::{peniko::Color, view::View, views::{Decorators, label, stack}};
/// fn view() -> impl View {
/// label(|| "Hello".to_string())
/// .style(|| Style::default().font_size(20.0).color(Color::RED))
/// .style(|s| s.font_size(20.0).color(Color::RED))
/// }
///
/// fn other() -> impl View {
/// stack(|| (
/// view(), // will be red and size 20
/// // will be green and default size due to the previous style being overwritten
/// view().style(|| Style::BASE.color(Color::GREEN)),
/// view().style(|s| s.color(Color::GREEN)),
/// ))
/// }
/// ```
Expand All @@ -49,14 +49,14 @@ pub trait Decorators: View + Sized {
/// # use floem::{peniko::Color, view::View, views::{Decorators, label, stack}};
/// fn view() -> impl View {
/// label(|| "Hello".to_string())
/// .base_style(|| Style::default().font_size(20.0).color(Color::RED))
/// .base_style(|s| s.font_size(20.0).color(Color::RED))
/// }
///
/// fn other() -> impl View {
/// stack(|| (
/// view(), // will be red and size 20
/// // will be green and size 20
/// view().style(|| Style::BASE.color(Color::GREEN)),
/// view().style(|s| s.color(Color::GREEN)),
/// ))
/// }
/// ```
Expand Down

0 comments on commit 7dc55d3

Please sign in to comment.