Permalink
Browse files

Separate the Widget trait into a new Update trait

  • Loading branch information...
antoyo committed May 21, 2017
1 parent a370729 commit 9b83e1ec9f92bd514edcd92b79fa529e3ab120a1
View
@@ -39,6 +39,10 @@ git = "https://github.com/antoyo/futures-glib-rs"
path = "relm-core"
version = "^0.1.1"
[dependencies.relm-state]
path = "relm-state"
version = "^0.1.0"
[dev-dependencies]
base64 = "^0.4.0"
blake2 = "^0.4.0"
View
@@ -40,7 +40,7 @@ use gtk::{
WindowType,
};
use gtk::Orientation::Vertical;
use relm::{Relm, Resolver, Widget};
use relm::{Relm, Resolver, Update, Widget};
use Msg::*;
@@ -62,27 +62,20 @@ struct Win {
window: Window,
}
impl Widget for Win {
impl Update for Win {
// Specify the model used for this widget.
type Model = Model;
// Specify the model parameter used to init the model.
type ModelParam = ();
// Specify the type of the messages sent to the update function.
type Msg = Msg;
// Specify the type of the root widget.
type Root = Window;
fn model(_: &Relm<Self>, _: ()) -> Model {
Model {
counter: 0,
}
}
// Return the root widget.
fn root(&self) -> Self::Root {
self.window.clone()
}
fn update(&mut self, event: Msg) {
let label = &self.counter_label;
@@ -99,6 +92,16 @@ impl Widget for Win {
},
}
}
}
impl Widget for Win {
// Specify the type of the root widget.
type Root = Window;
// Return the root widget.
fn root(&self) -> Self::Root {
self.window.clone()
}
fn view(relm: &Relm<Self>, model: Self::Model) -> Rc<RefCell<Self>> {
// Create the view using the normal GTK+ method calls.
View
@@ -39,7 +39,7 @@ use gtk::{
WindowType,
};
use gtk::Orientation::Vertical;
use relm::{Relm, Widget};
use relm::{Relm, Update, Widget};
struct Model {
counter: i32,
@@ -59,27 +59,20 @@ struct Win {
window: Window,
}
impl Widget for Win {
impl Update for Win {
// Specify the model used for this widget.
type Model = Model;
// Specify the model parameter used to init the model.
type ModelParam = ();
// Specify the type of the messages sent to the update function.
type Msg = Msg;
// Specify the type of the root widget.
type Root = Window;
fn model(_: &Relm<Self>, _: ()) -> Model {
Model {
counter: 0,
}
}
// Return the root widget.
fn root(&self) -> Self::Root {
self.window.clone()
}
fn update(&mut self, event: Msg) {
let label = &self.counter_label;
@@ -96,6 +89,16 @@ impl Widget for Win {
Msg::Quit => gtk::main_quit(),
}
}
}
impl Widget for Win {
// Specify the type of the root widget.
type Root = Window;
// Return the root widget.
fn root(&self) -> Self::Root {
self.window.clone()
}
fn view(relm: &Relm<Self>, model: Self::Model) -> Rc<RefCell<Self>> {
// Create the view using the normal GTK+ method calls.
View
@@ -38,7 +38,7 @@ use gtk::{
WindowType,
};
use gtk::Orientation::Vertical;
use relm::{Component, ContainerWidget, Relm, Widget};
use relm::{Component, ContainerWidget, Relm, Update, Widget};
use self::CheckMsg::*;
use self::Msg::*;
@@ -61,11 +61,10 @@ struct CheckButton {
relm: Relm<CheckButton>,
}
impl Widget for CheckButton {
impl Update for CheckButton {
type Model = CheckModel;
type ModelParam = &'static str;
type Msg = CheckMsg;
type Root = gtk::CheckButton;
fn model(_: &Relm<Self>, label: &'static str) -> CheckModel {
CheckModel {
@@ -74,10 +73,6 @@ impl Widget for CheckButton {
}
}
fn root(&self) -> Self::Root {
self.button.clone()
}
fn update(&mut self, event: CheckMsg) {
match event {
Check => {
@@ -99,6 +94,14 @@ impl Widget for CheckButton {
},
}
}
}
impl Widget for CheckButton {
type Root = gtk::CheckButton;
fn root(&self) -> Self::Root {
self.button.clone()
}
fn view(relm: &Relm<Self>, model: Self::Model) -> Rc<RefCell<Self>> {
let button = gtk::CheckButton::new_with_label(model.label);
@@ -126,19 +129,14 @@ struct Win {
window: Window,
}
impl Widget for Win {
impl Update for Win {
type Model = ();
type ModelParam = ();
type Msg = Msg;
type Root = Window;
fn model(_: &Relm<Self>, _: ()) -> () {
}
fn root(&self) -> Self::Root {
self.window.clone()
}
fn update(&mut self, event: Msg) {
match event {
Quit => gtk::main_quit(),
@@ -160,6 +158,14 @@ impl Widget for Win {
},
}
}
}
impl Widget for Win {
type Root = Window;
fn root(&self) -> Self::Root {
self.window.clone()
}
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
let vbox = gtk::Box::new(Vertical, 0);
View
@@ -42,7 +42,7 @@ use gtk::{
};
use gtk::Orientation::Vertical;
use gtk::WindowType::Toplevel;
use relm::{Component, ContainerWidget, Relm, Widget};
use relm::{Component, ContainerWidget, Relm, Update, Widget};
use self::Msg::*;
@@ -54,15 +54,21 @@ struct Button {
button: gtk::Button,
}
impl Widget for Button {
impl Update for Button {
type Model = ();
type ModelParam = ();
type Msg = ButtonMsg;
type Root = gtk::Button;
fn model(_: &Relm<Self>, _: ()) -> () {
}
fn update(&mut self, _msg: ButtonMsg) {
}
}
impl Widget for Button {
type Root = gtk::Button;
fn root(&self) -> Self::Root {
self.button.clone()
}
@@ -79,9 +85,6 @@ impl Widget for Button {
parent.set_child_position(&self.button, 0);
}
fn update(&mut self, _msg: ButtonMsg) {
}
fn view(_relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
let button = gtk::Button::new_with_label("+");
@@ -101,24 +104,27 @@ struct Win {
window: gtk::Window,
}
impl Widget for Win {
impl Update for Win {
type Model = ();
type ModelParam = ();
type Msg = Msg;
type Root = gtk::Window;
fn model(_: &Relm<Self>, _: ()) -> () {
}
fn root(&self) -> Self::Root {
self.window.clone()
}
fn update(&mut self, event: Msg) {
match event {
Quit => gtk::main_quit(),
}
}
}
impl Widget for Win {
type Root = gtk::Window;
fn root(&self) -> Self::Root {
self.window.clone()
}
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
let window = gtk::Window::new(Toplevel);
View
@@ -36,7 +36,7 @@ use std::time::Duration;
use chrono::Local;
use futures_glib::Interval;
use gtk::{ContainerExt, Inhibit, Label, WidgetExt, Window, WindowType};
use relm::{Relm, Widget};
use relm::{Relm, Update, Widget};
use self::Msg::*;
@@ -51,21 +51,16 @@ struct Win {
window: Window,
}
impl Widget for Win {
impl Update for Win {
type Model = ();
type ModelParam = ();
type Msg = Msg;
type Root = Window;
fn model(_: &Relm<Self>, _: ()) -> () {
()
}
fn root(&self) -> Self::Root {
self.window.clone()
}
fn subscriptions(relm: &Relm<Msg>) {
fn subscriptions(relm: &Relm<Self>) {
let stream = Interval::new(Duration::from_secs(1));
relm.connect_exec_ignore_err(stream, Tick);
}
@@ -79,6 +74,14 @@ impl Widget for Win {
Quit => gtk::main_quit(),
}
}
}
impl Widget for Win {
type Root = Window;
fn root(&self) -> Self::Root {
self.window.clone()
}
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
let label = Label::new(None);
View
@@ -34,7 +34,7 @@ use std::time::Duration;
use chrono::Local;
use futures_glib::Interval;
use gtk::{ContainerExt, Inhibit, Label, WidgetExt, Window, WindowType};
use relm::{Relm, Widget};
use relm::{Relm, Update, Widget};
use self::Msg::*;
@@ -49,21 +49,16 @@ struct Win {
window: Window,
}
impl Widget for Win {
impl Update for Win {
type Model = ();
type ModelParam = ();
type Msg = Msg;
type Root = Window;
fn model(_: &Relm<Self>, _: ()) -> () {
()
}
fn root(&self) -> Self::Root {
self.window.clone()
}
fn subscriptions(relm: &Relm<Msg>) {
fn subscriptions(relm: &Relm<Self>) {
let stream = Interval::new(Duration::from_secs(1));
relm.connect_exec_ignore_err(stream, Tick);
}
@@ -77,6 +72,14 @@ impl Widget for Win {
Quit => gtk::main_quit(),
}
}
}
impl Widget for Win {
type Root = Window;
fn root(&self) -> Self::Root {
self.window.clone()
}
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
let label = Label::new(None);
Oops, something went wrong.

0 comments on commit 9b83e1e

Please sign in to comment.