linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.53k stars 569 forks source link

Commands are not proccessed after update #1939

Open maan2003 opened 3 years ago

maan2003 commented 3 years ago

to reproduce: make sure after 1sec window receives no events (extend the time if needed). "send command in update" will be logged but "got command" will only be logged after next window event

use std::time::Duration;

use druid::widget::prelude::*;
use druid::{AppLauncher, Selector, WindowDesc};
use tracing::info;

struct CustomWidget;

const DOIT: Selector = Selector::new("druid-issue.commands-not-in-update");

impl Widget<()> for CustomWidget {
    fn event(&mut self, ctx: &mut EventCtx, event: &Event, _data: &mut (), _env: &Env) {
        match event {
            Event::WindowConnected => {
                ctx.request_timer(Duration::from_millis(1000));
            }
            Event::Timer(_) => {
                ctx.request_update();
            }
            Event::Command(cmd) if cmd.is(DOIT) => {
                info!("got command");
            }
            _ => {}
        }
    }

    fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle, _data: &(), _env: &Env) {}

    fn update(&mut self, ctx: &mut UpdateCtx, _old_data: &(), _data: &(), _env: &Env) {
        info!("send command in update");
        ctx.submit_command(DOIT);
    }

    fn layout(
        &mut self,
        _layout_ctx: &mut LayoutCtx,
        _bc: &BoxConstraints,
        _data: &(),
        _env: &Env,
    ) -> Size {
        Size::ZERO
    }

    fn paint(&mut self, _ctx: &mut PaintCtx, _data: &(), _env: &Env) {}
}

pub fn main() {
    AppLauncher::with_window(WindowDesc::new(CustomWidget))
        .log_to_console()
        .launch(())
        .expect("launch failed");
}
Alban-Boissard commented 2 years ago

Hi, I have to deal with this bug in a small App build on druid 0.7. Is it still present is the master branch ? And if yes, is there a not too ugly workaround ? thank for creating druid, it's a very pleasant Gui to work with.

maan2003 commented 2 years ago

yes this is present on master branch. and a workaround is used in nursery

Alban-Boissard commented 2 years ago

Thanks a lot for the workaround !