Skip to content

Commit

Permalink
Add init_view() method in Widget trait
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Apr 16, 2017
1 parent b71f61d commit 092ab06
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
Expand Down
2 changes: 1 addition & 1 deletion relm-gen-widget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion relm-gen-widget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down
6 changes: 6 additions & 0 deletions src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 092ab06

Please sign in to comment.