Permalink
Browse files

Add init_view() method in Widget trait

  • Loading branch information...
antoyo committed Apr 16, 2017
1 parent b71f61d commit 092ab0606020ae2b0349156e00d29af6b44d5546
Showing with 15 additions and 3 deletions.
  1. +1 −1 Cargo.toml
  2. +4 −0 examples/simple.rs
  3. +1 −1 relm-gen-widget/Cargo.toml
  4. +1 −1 relm-gen-widget/src/lib.rs
  5. +2 −0 src/lib.rs
  6. +6 −0 src/widget.rs
View
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/relm/"
license = "MIT"
name = "relm"
repository = "https://github.com/antoyo/relm"
version = "0.6.0"
version = "0.6.1"
[dependencies]
cairo-rs = "^0.1.2"
View
@@ -51,6 +51,10 @@ impl Widget for Label {
}
}
fn init_view(&self) {
self.label.set_text("Test");
}
fn update(&mut self, _event: LabelMsg, _model: &mut LabelModel) {
self.label.set_text("");
}
@@ -5,7 +5,7 @@ documentation = "https://docs.rs/relm-gen-widget/"
license = "MIT"
name = "relm-gen-widget"
repository = "https://github.com/antoyo/relm"
version = "0.6.2"
version = "0.6.3"
[dependencies]
lazy_static = "^0.2.4"
@@ -108,7 +108,7 @@ pub fn gen_widget(input: Tokens) -> Tokens {
state.widget_model_type = Some(get_return_type(sig));
new_items.push(i);
},
"subscriptions" | "update_command" => new_items.push(i),
"init_view" | "subscriptions" | "update_command" => new_items.push(i),
"update" => {
state.widget_msg_type = Some(get_second_param_type(&sig));
state.update_method = Some(i)
View
@@ -391,6 +391,7 @@ fn create_widget_test<WIDGET>(remote: &Remote) -> Component<WIDGET>
let model = WIDGET::model();
(WIDGET::view(relm, &model), model)
};
widget.init_view();
let model = Arc::new(Mutex::new(model));
@@ -430,6 +431,7 @@ fn create_widget<WIDGET>(remote: &Remote) -> Component<WIDGET>
let model = WIDGET::model();
(WIDGET::view(relm, &model), model)
};
widget.init_view();
let model = Arc::new(Mutex::new(model));
View
@@ -39,6 +39,12 @@ pub trait Widget
/// Get the containing widget, i.e. the parent widget of the view.
fn container(&self) -> &Self::Container;
/// Update the view after it is initially created.
/// This method is only useful when using the `#[widget]` attribute, because when not using it,
/// you can use the [`view()`](trait.Widget.html#tymethod.view) method instead.
fn init_view(&self) {
}
/// Create the initial model.
fn model() -> Self::Model;

0 comments on commit 092ab06

Please sign in to comment.