Skip to content

Commit 8ef856f

Browse files
viridiamockersf
authored andcommitted
Updated feathers example to permit toggling of disable state. (#21160)
Reproduces: #21110
1 parent bd7fa36 commit 8ef856f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

examples/ui/feathers.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ enum SwatchType {
3535
Hsl,
3636
}
3737

38+
#[derive(Component, Clone, Copy)]
39+
struct DemoDisabledButton;
40+
3841
fn main() {
3942
App::new()
4043
.add_plugins((DefaultPlugins, FeathersPlugins))
@@ -168,7 +171,7 @@ fn demo_root(commands: &mut Commands) -> impl Bundle {
168171
)),
169172
..default()
170173
},
171-
InteractionDisabled,
174+
(InteractionDisabled, DemoDisabledButton),
172175
Spawn((Text::new("Disabled"), ThemedText))
173176
),
174177
button(
@@ -249,7 +252,25 @@ fn demo_root(commands: &mut Commands) -> impl Bundle {
249252
),
250253
checkbox(
251254
CheckboxProps {
252-
on_change: Callback::Ignore,
255+
on_change: Callback::System(commands.register_system(
256+
|change: In<ValueChange<bool>>,
257+
query: Query<Entity, With<DemoDisabledButton>>,
258+
mut commands: Commands| {
259+
info!("Checkbox clicked!");
260+
let mut button = commands.entity(query.single().unwrap());
261+
if change.value {
262+
button.insert(InteractionDisabled);
263+
} else {
264+
button.remove::<InteractionDisabled>();
265+
}
266+
let mut checkbox = commands.entity(change.source);
267+
if change.value {
268+
checkbox.insert(Checked);
269+
} else {
270+
checkbox.remove::<Checked>();
271+
}
272+
}
273+
)),
253274
},
254275
Checked,
255276
Spawn((Text::new("Checkbox"), ThemedText))

0 commit comments

Comments
 (0)