Hi, I was wondering if the state of the applicaiton can be accessed outside the context of it. I’m planning create some pop-ups that should return the value based on the user input see proof of concept bellow:
use iced::widget::{button, column, text, Column};
#[derive(Default)]
struct App {
last_pressed: String,
}
#[derive(Debug, Clone, Copy)]
enum Message {
Button1,
Button2,
Button3,
}
impl App {
pub fn update(&mut self, message: Message) {
self.last_pressed = match message {
Message::Button1 => "Button 1".to_string(),
Message::Button2 => "Button 2".to_string(),
Message::Button3 => "Button 3".to_string(),
};
}
pub fn view(&self) -> Column<Message> {
column![
button("Button 1").on_press(Message::Button1),
button("Button 2").on_press(Message::Button2),
button("Button 3").on_press(Message::Button3),
text(format!("Last pressed: {}", self.last_pressed)).size(30)
]
.spacing(20)
}
pub fn new() -> Self{
App { last_pressed: "".to_string() }
}
}
fn main() -> iced::Result {
let _window = iced::application("Three Button App",
//updater
App::update,
App::view)
.window_size(iced::Size::new(300.0, 400.0));
//.exit_on_close_request(false);
let result: Result<(), iced::Error> = _window.run(); //the window gets consumed by run and no state can be accessed
//accessing the state (in this case self.last_pressed) and returning it.
println!("User selected: {:?}", &result);
result
}
I need the main function to have the return value of the string which was a part of the state of the application that closed (self.last_pressed in this example). I’m fairly new to rust so maybe there is a solution that I’m not seeing? Thanks in advance!