Skip to content

Commit 092ab06

Browse files
committed
Add init_view() method in Widget trait
1 parent b71f61d commit 092ab06

6 files changed

Lines changed: 15 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/relm/"
66
license = "MIT"
77
name = "relm"
88
repository = "https://github.com/antoyo/relm"
9-
version = "0.6.0"
9+
version = "0.6.1"
1010

1111
[dependencies]
1212
cairo-rs = "^0.1.2"

examples/simple.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ impl Widget for Label {
5151
}
5252
}
5353

54+
fn init_view(&self) {
55+
self.label.set_text("Test");
56+
}
57+
5458
fn update(&mut self, _event: LabelMsg, _model: &mut LabelModel) {
5559
self.label.set_text("");
5660
}

relm-gen-widget/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ documentation = "https://docs.rs/relm-gen-widget/"
55
license = "MIT"
66
name = "relm-gen-widget"
77
repository = "https://github.com/antoyo/relm"
8-
version = "0.6.2"
8+
version = "0.6.3"
99

1010
[dependencies]
1111
lazy_static = "^0.2.4"

relm-gen-widget/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn gen_widget(input: Tokens) -> Tokens {
108108
state.widget_model_type = Some(get_return_type(sig));
109109
new_items.push(i);
110110
},
111-
"subscriptions" | "update_command" => new_items.push(i),
111+
"init_view" | "subscriptions" | "update_command" => new_items.push(i),
112112
"update" => {
113113
state.widget_msg_type = Some(get_second_param_type(&sig));
114114
state.update_method = Some(i)

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ fn create_widget_test<WIDGET>(remote: &Remote) -> Component<WIDGET>
391391
let model = WIDGET::model();
392392
(WIDGET::view(relm, &model), model)
393393
};
394+
widget.init_view();
394395

395396
let model = Arc::new(Mutex::new(model));
396397

@@ -430,6 +431,7 @@ fn create_widget<WIDGET>(remote: &Remote) -> Component<WIDGET>
430431
let model = WIDGET::model();
431432
(WIDGET::view(relm, &model), model)
432433
};
434+
widget.init_view();
433435

434436
let model = Arc::new(Mutex::new(model));
435437

src/widget.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ pub trait Widget
3939
/// Get the containing widget, i.e. the parent widget of the view.
4040
fn container(&self) -> &Self::Container;
4141

42+
/// Update the view after it is initially created.
43+
/// This method is only useful when using the `#[widget]` attribute, because when not using it,
44+
/// you can use the [`view()`](trait.Widget.html#tymethod.view) method instead.
45+
fn init_view(&self) {
46+
}
47+
4248
/// Create the initial model.
4349
fn model() -> Self::Model;
4450

0 commit comments

Comments
 (0)