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

Descendants of a disabled View apply disabled behavior, but not disabled styling #230

Closed
pieterdd opened this issue Dec 25, 2023 · 1 comment

Comments

@pieterdd
Copy link
Contributor

pieterdd commented Dec 25, 2023

I observed the following when putting a View into a disabled state:

  • Its descendants exhibit disabled behavior, i.e. the buttons in my test no longer respond to clicks (makes sense)
  • Its descendants don't look disabled, i.e. they don't apply disabled styling

Here's a live demo:

tmp.mp4

Source code for the demo:

use floem::kurbo::Size;
use floem::peniko::Color;
use floem::reactive::{create_signal, ReadSignal, WriteSignal};
use floem::style::AlignItems;
use floem::view::View;
use floem::views::{h_stack, label, v_stack, Decorators};
use floem::widgets::{button, checkbox};
use floem::window::WindowConfig;
use floem::EventPropagation;

fn my_button(label: &'static str) -> impl View {
    button(move || label).style(|s| {
        s.background(Color::GREEN)
            .color(Color::WHITE)
            .disabled(|s| s.background(Color::DARK_GRAY))
            .font_size(18.0)
            .padding(5.0)
    })
}

fn spinbox(counter: ReadSignal<i32>, set_counter: WriteSignal<i32>) -> impl View {
    h_stack((
        my_button("-").on_click(move |_| {
            set_counter.update(|value| *value -= 1);
            EventPropagation::Stop
        }),
        label(move || counter.get()),
        my_button("+").on_click(move |_| {
            set_counter.update(|value| *value += 1);
            EventPropagation::Stop
        }),
    ))
    .style(|s| {
        s.align_items(AlignItems::Center)
            .disabled(|s| s.background(Color::DIM_GRAY))
            .gap(10.0, 0.0)
    })
}

fn app_view() -> impl View {
    let (spinbox_enabled, set_spinbox_enabled) = create_signal(true);
    let (counter, set_counter) = create_signal(0);

    v_stack((
        checkbox(spinbox_enabled)
            .on_click_stop(move |_| set_spinbox_enabled.set(!spinbox_enabled.get())),
        spinbox(counter, set_counter).disabled(move || !spinbox_enabled.get()),
    ))
}

fn main() {
    let window_config = WindowConfig::default().size(Size {
        width: 200.0,
        height: 100.0,
    });

    floem::Application::new()
        .window(move |_| app_view(), Some(window_config))
        .run()
}

To be consistent, I think disabled styling should apply whenever disabled behavior is into effect.

I'll see if I can write a fix and submit a PR, but I'm still pretty new to Floem. Fix ready at #231.

@pieterdd
Copy link
Contributor Author

Addressed by e795021.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant