-
Hi. This might not be fully related to iced but figured this is the best place to ask this. I'm trying to make this MVC-based model with iced being the UI layer. I'm trying to call a controller method after a button press, but not sure how I'm able to pass the controller to the state. I have the following reduced example in more-or-less pseudo code.
So after a button press I need to call If you can find any more noob mistakes feel free to point them out. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can provide initial state by implementing the pub fn main() -> iced::Result {
let controller = Controller::new();
View::run(Settings::with_flags(Flags { controller }))
}
struct View {
controller: Controller,
}
struct Flags {
controller: Controller,
}
impl Application for View {
type Flags = Flags;
// ...
fn new(flags: Flags) -> (Self, Command<Message>) {
(Self { controller: flags.controller }, Command::none())
}
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::ButtonPressed => {
self.controller.do_something();
}
}
Command::none()
}
// ...
} |
Beta Was this translation helpful? Give feedback.
You can provide initial state by implementing the
Application
trait instead and leveraging theFlags
associated type: