Permalink
Browse files

Add a shortcut method to emit a message on a component

  • Loading branch information...
antoyo committed Jun 9, 2017
1 parent a1fc2c6 commit c5461e8233b76db7f2b5e20f0cee67f0ded66027
Showing with 15 additions and 5 deletions.
  1. +4 −4 examples/checkboxes.rs
  2. +5 −0 src/component.rs
  3. +6 −1 src/container.rs
View
@@ -139,18 +139,18 @@ impl Update for Win {
Quit => gtk::main_quit(),
MinusToggle => {
if self.minus_button.widget().get_active() {
self.plus_button.stream().emit(Uncheck);
self.plus_button.emit(Uncheck);
}
else {
self.plus_button.stream().emit(Check);
self.plus_button.emit(Check);
}
},
PlusToggle => {
if self.plus_button.widget().get_active() {
self.minus_button.stream().emit(Uncheck);
self.minus_button.emit(Uncheck);
}
else {
self.minus_button.stream().emit(Check);
self.minus_button.emit(Check);
}
},
}
View
@@ -51,6 +51,11 @@ impl<WIDGET: Widget> Component<WIDGET> {
}
}
/// Emit a message of the widget stream.
pub fn emit(&self, msg: WIDGET::Msg) {
self.stream.emit(msg);
}
/// Get the event stream of the component.
/// This is used internally by the library.
pub fn stream(&self) -> &EventStream<WIDGET::Msg> {
View
@@ -62,10 +62,15 @@ impl<WIDGET: Container + Widget> ContainerComponent<WIDGET> {
component
}
/// Emit a message of the widget stream.
pub fn emit(&self, msg: WIDGET::Msg) {
self.stream().emit(msg);
}
/// Get the event stream of the component.
/// This is used internally by the library.
pub fn stream(&self) -> &EventStream<WIDGET::Msg> {
&self.component.stream()
self.component.stream()
}
// TODO: add delete methods?

0 comments on commit c5461e8

Please sign in to comment.