conrod icon indicating copy to clipboard operation
conrod copied to clipboard

Button.enabled(false) seems doesn't work.

Open aurexav opened this issue 6 years ago • 5 comments

Button.enabled(false) seems doesn't work.

if widget::Button::new()
    .label("Export")
    .w_h(widget_width, widget_height)
    .label_font_size(font_size)
    .mid_top_with_margin_on(ids.export_button, 40.)
    .border(0.)
    .color(button_color)
    .label_color(label_color)
    .press_color(button_press_color)
    .enabled(false)
    .set(ids.download_album_button, ui)
    .was_clicked() {
    export();
}

I still can click the button and do export().

aurexav avatar Dec 21 '18 16:12 aurexav

Ah yes I think enabled was removed for the most part a while ago in favour of trying to work out a more general approach, however it looks like the Button method is still there despite not doing anything.

I think it was removed as, if you already have access to a bool for toggling the enabled method, in most cases you can probably just use that bool in the if scope? e.g.

if widget::Button::new()
    .label("Export")
    .w_h(widget_width, widget_height)
    .label_font_size(font_size)
    .mid_top_with_margin_on(ids.export_button, 40.)
    .border(0.)
    .color(button_color)
    .label_color(label_color)
    .press_color(button_press_color)
    .set(ids.download_album_button, ui)
    .was_clicked() {
    if enabled {
        export();
    }
}

I'm open to ideas on this though. I could understand if someone wanted to re-implement the method so that it e.g. also disabled color-change feedback when hovering over or pressing the button.

mitchmindtree avatar Dec 26 '18 05:12 mitchmindtree

Yep, I want to disable the feedback. User need to know the button is disabled in that situation.

aurexav avatar Dec 26 '18 06:12 aurexav

One way to disable feedback in the meantime might be to do something like this:

if widget::Button::new()
    .label("Export")
    .w_h(widget_width, widget_height)
    .label_font_size(font_size)
    .mid_top_with_margin_on(ids.export_button, 40.)
    .border(0.)
    .color(if enabled { button_color } else { disabled_color })
    .label_color(label_color)
    .hover_color(if enabled { hover_color } else { disabled_color })
    .press_color(if enabled { button_press_color } else { disabled_color })
    .set(ids.download_album_button, ui)
    .was_clicked() {
    if enabled {
        export();
    }
}

Not the nicest solution, but perhaps easier than re-implementing enabled and doing a PR for now.

mitchmindtree avatar Dec 26 '18 06:12 mitchmindtree

Aha. To avoid duplicated condition:

fn new_export_button(color, ...) -> Button { ... }

let export_button = if enabled { 
    new_export_button(color, ...) 
} else {
    new_export_button(color, ...) 
};

aurexav avatar Dec 26 '18 06:12 aurexav

FWIW, I just spent a bunch of time trying to figure out why the publicly documented enabled API wasn't working in my app. If y'all are hesitant to remove it outright, a #[doc(hidden)] might be a reasonable compromise.

cbiffle avatar Sep 26 '19 15:09 cbiffle