Skip to content

Commit c5461e8

Browse files
committed
Add a shortcut method to emit a message on a component
1 parent a1fc2c6 commit c5461e8

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

examples/checkboxes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,18 @@ impl Update for Win {
139139
Quit => gtk::main_quit(),
140140
MinusToggle => {
141141
if self.minus_button.widget().get_active() {
142-
self.plus_button.stream().emit(Uncheck);
142+
self.plus_button.emit(Uncheck);
143143
}
144144
else {
145-
self.plus_button.stream().emit(Check);
145+
self.plus_button.emit(Check);
146146
}
147147
},
148148
PlusToggle => {
149149
if self.plus_button.widget().get_active() {
150-
self.minus_button.stream().emit(Uncheck);
150+
self.minus_button.emit(Uncheck);
151151
}
152152
else {
153-
self.minus_button.stream().emit(Check);
153+
self.minus_button.emit(Check);
154154
}
155155
},
156156
}

src/component.rs

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ impl<WIDGET: Widget> Component<WIDGET> {
5151
}
5252
}
5353

54+
/// Emit a message of the widget stream.
55+
pub fn emit(&self, msg: WIDGET::Msg) {
56+
self.stream.emit(msg);
57+
}
58+
5459
/// Get the event stream of the component.
5560
/// This is used internally by the library.
5661
pub fn stream(&self) -> &EventStream<WIDGET::Msg> {

src/container.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@ impl<WIDGET: Container + Widget> ContainerComponent<WIDGET> {
6262
component
6363
}
6464

65+
/// Emit a message of the widget stream.
66+
pub fn emit(&self, msg: WIDGET::Msg) {
67+
self.stream().emit(msg);
68+
}
69+
6570
/// Get the event stream of the component.
6671
/// This is used internally by the library.
6772
pub fn stream(&self) -> &EventStream<WIDGET::Msg> {
68-
&self.component.stream()
73+
self.component.stream()
6974
}
7075

7176
// TODO: add delete methods?

0 commit comments

Comments
 (0)