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

Add disabled, active, focus and focus_visible style selectors #129

Merged
merged 2 commits into from
Oct 31, 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
2 changes: 1 addition & 1 deletion examples/animations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ fn app_view() -> impl View {
.padding(10.0)
.margin(20.0)
.size(120.0, 120.0)
.active(|s| s.color(Color::BLACK))
})
.active_style(|s| s.color(Color::BLACK))
.animation(
animation()
.border_radius(move || if is_hovered.get() { 1.0 } else { 40.0 })
Expand Down
26 changes: 13 additions & 13 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ fn app_view() -> impl View {
.padding(10.0)
.background(Color::WHITE)
.box_shadow_blur(5.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| s.background(Color::LIGHT_GREEN))
.active(|s| s.color(Color::WHITE).background(Color::DARK_GREEN))
})
.on_click({
move |_| {
set_counter.update(|value| *value += 1);
true
}
})
.hover_style(|s| s.background(Color::LIGHT_GREEN))
.active_style(|s| s.color(Color::WHITE).background(Color::DARK_GREEN))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.keyboard_navigatable(),
text("Decrement")
.on_click({
move |_| {
Expand All @@ -41,11 +41,11 @@ fn app_view() -> impl View {
.border_radius(10.0)
.padding(10.0)
.margin_left(10.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| s.background(Color::rgb8(244, 67, 54)))
.active(|s| s.color(Color::WHITE).background(Color::RED))
})
.hover_style(|s| s.background(Color::rgb8(244, 67, 54)))
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.keyboard_navigatable(),
text("Reset to 0")
.on_click(move |_| {
println!("Reset counter pressed"); // will not fire if button is disabled
Expand All @@ -59,12 +59,12 @@ fn app_view() -> impl View {
.padding(10.0)
.margin_left(10.0)
.background(Color::LIGHT_BLUE)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.disabled(|s| s.background(Color::LIGHT_GRAY))
.hover(|s| s.background(Color::LIGHT_YELLOW))
.active(|s| s.color(Color::WHITE).background(Color::YELLOW_GREEN))
})
.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))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.keyboard_navigatable(),
)),
))
.style(|s| {
Expand Down
20 changes: 10 additions & 10 deletions examples/draggable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ fn app_view() -> impl View {
.border_radius(2.0)
.padding(10.0)
.margin_left(10.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| {
s.background(Color::rgb8(244, 67, 54))
.border_radius(0.)
.border(2.)
.border_color(Color::BLUE)
.outline(2.)
.outline_color(Color::PALE_GREEN)
})
.active(|s| s.color(Color::WHITE).background(Color::RED))
})
.hover_style(|s| {
s.background(Color::rgb8(244, 67, 54))
.border_radius(0.)
.border(2.)
.border_color(Color::BLUE)
.outline(2.)
.outline_color(Color::PALE_GREEN)
})
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.))
.draggable()
.dragging_style(|s| {
s.border(2.)
Expand Down
26 changes: 17 additions & 9 deletions examples/widget-gallery/src/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ pub fn button_view() -> impl View {
true
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(|s| s.border(1.0).border_radius(10.0).padding(10.0))
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding(10.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
})
}),
form_item("Styled Button:".to_string(), 120.0, || {
label(|| "Click me")
Expand All @@ -27,7 +31,6 @@ pub fn button_view() -> impl View {
true
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(|s| {
s.border(1.0)
.border_radius(10.0)
Expand All @@ -36,9 +39,10 @@ pub fn button_view() -> impl View {
.background(Color::YELLOW_GREEN)
.color(Color::DARK_GREEN)
.cursor(CursorStyle::Pointer)
.active(|s| s.color(Color::WHITE).background(Color::RED))
.hover(|s| s.background(Color::rgb8(244, 67, 54)))
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
})
.hover_style(|s| s.background(Color::rgb8(244, 67, 54)))
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
}),
form_item("Distabled Button:".to_string(), 120.0, || {
label(|| "Click me")
Expand All @@ -48,14 +52,14 @@ pub fn button_view() -> impl View {
true
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding(10.0)
.color(Color::GRAY)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| s.background(Color::rgb8(224, 224, 224)))
})
.hover_style(|s| s.background(Color::rgb8(224, 224, 224)))
}),
form_item("Secondary click button:".to_string(), 120.0, || {
label(|| "Right click me")
Expand All @@ -64,8 +68,12 @@ pub fn button_view() -> impl View {
true
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(|s| s.border(1.0).border_radius(10.0).padding(10.0))
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding(10.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
})
}),
)
})
Expand Down
6 changes: 3 additions & 3 deletions examples/widget-gallery/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn checkbox_view() -> impl View {
(
form_item("Basic Checkbox:".to_string(), 120.0, move || {
checkbox(is_checked)
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.))
.style(|s| s.focus_visible(|s| s.border(2.).border_color(Color::BLUE)))
.on_click(move |_| {
set_is_checked.update(|checked| *checked = !*checked);
true
Expand All @@ -23,7 +23,7 @@ pub fn checkbox_view() -> impl View {
stack({
(
checkbox(is_checked)
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.style(|s| s.focus_visible(|s| s.border(2.).border_color(Color::BLUE))),
label(|| "Check me!"),
)
})
Expand All @@ -36,7 +36,7 @@ pub fn checkbox_view() -> impl View {
stack({
(
checkbox(is_checked)
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.style(|s| s.focus_visible(|s| s.border(2.).border_color(Color::BLUE))),
label(|| "Check me!"),
)
})
Expand Down
18 changes: 12 additions & 6 deletions examples/widget-gallery/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,34 @@ pub fn text_input_view() -> impl View {
text_input(text)
.style(|s| {
s.border(1.5)
.background(Color::rgb8(224, 224, 224))
.background(Color::rgb8(224, 224, 224).with_alpha_factor(0.1))
.border_radius(15.0)
.border_color(Color::rgb8(189, 189, 189))
.padding(10.0)
.cursor(CursorStyle::Text)
.hover(|s| {
s.background(Color::rgb8(224, 224, 224).with_alpha_factor(0.2))
.border_color(Color::rgb8(66, 66, 66))
})
.focus(|s| {
s.border_color(Color::LIGHT_SKY_BLUE.with_alpha_factor(0.8))
.hover(|s| s.border_color(Color::LIGHT_SKY_BLUE))
})
})
.hover_style(|s| s.border_color(Color::rgb8(66, 66, 66)))
.focus_style(|s| s.border_color(Color::LIGHT_SKY_BLUE))
.keyboard_navigatable()
}),
form_item("Disabled Input:".to_string(), 120.0, move || {
text_input(text)
.style(|s| {
s.border(1.5)
.background(Color::rgb8(224, 224, 224))
.border_radius(15.0)
.border_color(Color::rgb8(189, 189, 189))
.padding(10.0)
.cursor(CursorStyle::Text)
.disabled(|s| s.background(Color::rgb8(224, 224, 224)))
.hover(|s| s.border_color(Color::rgb8(66, 66, 66)))
.focus(|s| s.border_color(Color::LIGHT_SKY_BLUE))
})
.hover_style(|s| s.border_color(Color::rgb8(66, 66, 66)))
.focus_style(|s| s.border_color(Color::LIGHT_SKY_BLUE))
.keyboard_navigatable()
.disabled(|| true)
}),
Expand Down
6 changes: 3 additions & 3 deletions examples/widget-gallery/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ fn enhanced_list() -> impl View {
.border_color(Color::RED)
.border_radius(16.0)
.margin_right(5.0)
.hover(|s| s.color(Color::WHITE).background(Color::RED))
})
.hover_style(|s| s.color(Color::WHITE).background(Color::RED))
})
.style(|s| {
s.flex_basis(0)
Expand Down Expand Up @@ -127,7 +127,6 @@ fn enhanced_list() -> impl View {
}
})
.keyboard_navigatable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(move |s| {
s.flex_row()
.width(list_width.pct())
Expand All @@ -136,8 +135,9 @@ fn enhanced_list() -> impl View {
.apply_if(index != 0, |s| {
s.border_top(1.0).border_color(Color::LIGHT_GRAY)
})
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| s.background(Color::LIGHT_GRAY).cursor(CursorStyle::Pointer))
})
.hover_style(|s| s.background(Color::LIGHT_GRAY).cursor(CursorStyle::Pointer))
},
)
.style(move |s| s.flex_col().width(list_width)),
Expand Down
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ fn app_view() -> impl View {
})
.keyboard_navigatable()
.draggable()
.focus_visible_style(|s| s.border(2.).border_color(Color::BLUE))
.style(move |s| {
s.flex_row()
.width(100.pct())
Expand All @@ -91,6 +90,7 @@ fn app_view() -> impl View {
.apply_if(index == active_tab.get(), |s| {
s.background(Color::GRAY)
})
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
})
.hover_style(|s| {
s.background(Color::LIGHT_GRAY).cursor(CursorStyle::Pointer)
Expand Down
46 changes: 25 additions & 21 deletions examples/window-scale/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ fn app_view() -> impl View {
stack({
(
label(|| "Increment")
.style(|s| s.border(1.0).border_radius(10.0).padding(10.0))
.style(|s| {
s.border(1.0)
.border_radius(10.0)
.padding(10.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| s.background(Color::LIGHT_GREEN))
.active(|s| s.color(Color::WHITE).background(Color::DARK_GREEN))
})
.on_click(move |_| {
set_counter.update(|value| *value += 1);
true
})
.hover_style(|s| s.background(Color::LIGHT_GREEN))
.active_style(|s| s.color(Color::WHITE).background(Color::DARK_GREEN))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.keyboard_navigatable(),
label(|| "Decrement")
.on_click(move |_| {
set_counter.update(|value| *value -= 1);
Expand All @@ -33,11 +37,11 @@ fn app_view() -> impl View {
.border_radius(10.0)
.padding(10.0)
.margin_left(10.0)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.hover(|s| s.background(Color::rgb8(244, 67, 54)))
.active(|s| s.color(Color::WHITE).background(Color::RED))
})
.hover_style(|s| s.background(Color::rgb8(244, 67, 54)))
.active_style(|s| s.color(Color::WHITE).background(Color::RED))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.keyboard_navigatable(),
label(|| "Reset to 0")
.on_click(move |_| {
println!("Reset counter pressed"); // will not fire if button is disabled
Expand All @@ -51,12 +55,12 @@ fn app_view() -> impl View {
.padding(10.0)
.margin_left(10.0)
.background(Color::LIGHT_BLUE)
.focus_visible(|s| s.border(2.).border_color(Color::BLUE))
.disabled(|s| s.background(Color::LIGHT_GRAY))
.hover(|s| s.background(Color::LIGHT_YELLOW))
.active(|s| s.color(Color::WHITE).background(Color::YELLOW_GREEN))
})
.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))
.keyboard_navigatable()
.focus_visible_style(|s| s.border_color(Color::BLUE).border(2.)),
.keyboard_navigatable(),
)
}),
stack({
Expand All @@ -72,8 +76,8 @@ fn app_view() -> impl View {
.margin_top(10.0)
.margin_right(10.0)
.padding(10.0)
})
.hover_style(|s| s.background(Color::LIGHT_GREEN)),
.hover(|s| s.background(Color::LIGHT_GREEN))
}),
label(|| "Zoom Out")
.on_click(move |_| {
window_scale.update(|scale| *scale /= 1.2);
Expand All @@ -85,8 +89,8 @@ fn app_view() -> impl View {
.margin_top(10.0)
.margin_right(10.0)
.padding(10.0)
})
.hover_style(|s| s.background(Color::LIGHT_GREEN)),
.hover(|s| s.background(Color::LIGHT_GREEN))
}),
label(|| "Zoom Reset")
.disabled(move || window_scale.get() == 1.0)
.on_click(move |_| {
Expand All @@ -99,9 +103,9 @@ fn app_view() -> impl View {
.margin_top(10.0)
.margin_right(10.0)
.padding(10.0)
})
.hover_style(|s| s.background(Color::LIGHT_GREEN))
.disabled_style(|s| s.background(Color::LIGHT_GRAY)),
.hover(|s| s.background(Color::LIGHT_GREEN))
.disabled(|s| s.background(Color::LIGHT_GRAY))
}),
)
})
.style(|s| {
Expand Down
Loading