Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Externalize checkbox click handler
Browse files Browse the repository at this point in the history
When possible, let the caller decide how to respond to events.
  • Loading branch information
pieterdd committed Jan 10, 2024
1 parent 054893b commit c313691
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 8 additions & 5 deletions examples/showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ fn app_view() -> impl View {
theme.simple_header("Header"),
theme.padded_container(
v_stack((
theme.labeled_checkbox(inputs_enabled, set_inputs_enabled, || {
"Enable all inputs"
}),
theme
.labeled_checkbox(inputs_enabled, || "Enable all inputs")
.on_click_stop(move |_| {
set_inputs_enabled.set(!inputs_enabled.get());
}),
h_stack((
v_stack((
theme.label(move || "Enable all inputs", LabelVariant::Dimmed),
Expand Down Expand Up @@ -77,8 +79,9 @@ fn app_view() -> impl View {
.integer_input(rw_counter, 1, Some(-2), Some(9000))
.disabled(move || !inputs_enabled.get()),
theme
.labeled_checkbox(boolean_signal, set_boolean_signal, || {
"Ordinary checkbox"
.labeled_checkbox(boolean_signal, || "Ordinary checkbox")
.on_click_stop(move |_| {
set_boolean_signal.set(!boolean_signal.get());
})
.disabled(move || !inputs_enabled.get()),
theme
Expand Down
7 changes: 1 addition & 6 deletions src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use floem::{
event::EventListener,
peniko::Color,
reactive::{create_signal, ReadSignal, WriteSignal},
reactive::{create_signal, ReadSignal},
style::AlignItems,
view::View,
views::{container, h_stack, label, svg, Decorators},
Expand Down Expand Up @@ -31,7 +31,6 @@ impl Theme {
pub fn labeled_checkbox<S: Display + 'static>(
self,
read_signal: ReadSignal<bool>,
write_signal: WriteSignal<bool>,
label_render_func: impl Fn() -> S + 'static,
) -> impl View {
let (is_hovering, set_is_hovering) = create_signal(false);
Expand Down Expand Up @@ -111,10 +110,6 @@ impl Theme {
})
.gap(10.0, 0.0)
})
.on_click(move |_| {
write_signal.set(!read_signal.get());
floem::EventPropagation::Stop
})
.on_event_stop(EventListener::PointerEnter, move |_| {
set_is_hovering.set(true);
})
Expand Down

0 comments on commit c313691

Please sign in to comment.