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

Add function to request a repaint to WebRunner #4480

Open
AlexanderSchuetz97 opened this issue May 11, 2024 · 0 comments
Open

Add function to request a repaint to WebRunner #4480

AlexanderSchuetz97 opened this issue May 11, 2024 · 0 comments

Comments

@AlexanderSchuetz97
Copy link

AlexanderSchuetz97 commented May 11, 2024

Is your feature request related to a problem? Please describe.
I want to integrate egui into an existing large singlepage application written in javascript/typescript.
The javascript/typescript app may change the state of the application outside of what rust/egui is aware.
(I.e. for example I use egui to visualize some data and the js part changes the data)
Rust would have to be notified somehow that a repaint is required.

Describe the solution you'd like
It would be easiest to just be able to call WebRunner::request_repaint or something similar.
This would/should cause the Apps update routine to be called without any mouse/input events on the canvas
causing rust to become aware of any changes in state and updating the UI accordingly.
To call this from JS, I could then expose a fn to javascript that would call WebRunner::request_repaint.

Describe alternatives you've considered
A workaround exists as the egui::Context object has a repaint method and the WebRunner has the app.
First I added the egui::Context as a member to my App Struct (Thankfully its just an Arc to a Context delegate!)
Then on the WebRunner in the exposed fn I call

let runner : &WebRunner = ....... 
runner.app_mut::<MyAppStructNameHere>().map(|app| app.repaint())

In the impl of my App:

pub fn repaint(&self) {
    self.ctx.request_repaint();
}

As you can see this is not a very intuitive way to do this.

Additional context
There may be a more obvieus, easy/intended way of doing this, that I just haven't seen.
If that is the case then I am sorry for wasting your time.

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