How to have a reference to the model within the draw function of a DrawArea #676
Answered
by
LevitatingBusinessMan
LevitatingBusinessMan
asked this question in
Q&A
-
Let's say I want to modify the counter example by drawing the counter in a DrawingArea instead of a label. What would be the most appropriate way to ensure that the draw function has a (read) reference to the model? #[relm4::component]
impl SimpleComponent for App {
type Init = u8;
type Input = Msg;
type Output = ();
view! {
gtk::Window {
set_title: Some("Simple app"),
set_default_size: (300, 100),
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
set_margin_all: 5,
gtk::Button {
set_label: "Increment",
connect_clicked => Msg::Increment,
},
gtk::Button {
set_label: "Decrement",
connect_clicked => Msg::Decrement,
},
gtk::DrawingArea {
set_draw_func: |area, ctx, height, width| {
cairo_show_text(model.counter);
},
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
LevitatingBusinessMan
Aug 15, 2024
Replies: 1 comment
-
I think this is can be solved with abstractions::drawing as shown in https://github.com/Relm4/Relm4/blob/main/examples/drawing.rs |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
LevitatingBusinessMan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is can be solved with abstractions::drawing as shown in https://github.com/Relm4/Relm4/blob/main/examples/drawing.rs