slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.31k stars 583 forks source link

triggering `changed` from a global and from code not working. #6599

Open TheColorRed opened 1 day ago

TheColorRed commented 1 day ago

Note: I am not sure where the point of failure is here, whether I am doing something wrong, or I am attempting something that isn't supported.

I would like changed to be triggered from the rust code where the callback is within a global. I have tried also calling this from another slint file, but that too doesn't do anything.

What I was expecting is for the event to trigger but it doesn't whether I call it from a .rs file or from another .slint file.

export global AppState {
    callback active-project-changed(int);
    in property <int> active-project: 0;
    changed active-project => {
        debug(active-project);
        active-project-changed(active-project);
    }
}

export component AppWindow inherits Window {
  Button  {
    clicked => { AppState.active-project: 0 }
  }
}
slint::slint! {
  export { AppWindow } from "packages/app/ui/main.slint";
  export { AppState } from "packages/app/ui/app-state.slint";
}
let app = AppWindow::new()?;

let app_state = app.global::<AppState>();

app_state.set_active_project(1);
JoeySoprano420 commented 2 hours ago

Unscribr

On Sun, Oct 20, 2024 at 8:22 PM Ryan Naddy @.***> wrote:

Note: I am not sure where the point of failure is here, whether I am doing something wrong, or I am attempting something that isn't supported.

I would like changed to be triggered from the rust code where the callback is within a global. I have tried also calling this from another slint file, but that too doesn't do anything.

What I was expecting is for the event to trigger but it doesn't whether I call it from a .rs file or from another .slint file.

export global AppState { callback active-project-changed(int); in property active-project: 0; changed active-project => { debug(active-project); active-project-changed(active-project); } } export component AppWindow inherits Window { Button { clicked => { AppState.active-project: 0 } } }

let app = AppWindow::new()?; let app_state = app.global::();

app_state.set_active_project(1);

— Reply to this email directly, view it on GitHub https://github.com/slint-ui/slint/issues/6599, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2D3MPZBGZY2H25E52CHGO3Z4RCK5AVCNFSM6AAAAABQJAK2NOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGYYDCMBQGIZTCNI . You are receiving this because you are subscribed to this thread.Message ID: @.***>