Skip to content

Commit 9b83e1e

Browse files
committed
Separate the Widget trait into a new Update trait
1 parent a370729 commit 9b83e1e

27 files changed

+630
-426
lines changed

Diff for: Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ git = "https://github.com/antoyo/futures-glib-rs"
3939
path = "relm-core"
4040
version = "^0.1.1"
4141

42+
[dependencies.relm-state]
43+
path = "relm-state"
44+
version = "^0.1.0"
45+
4246
[dev-dependencies]
4347
base64 = "^0.4.0"
4448
blake2 = "^0.4.0"

Diff for: examples/async-callback.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use gtk::{
4040
WindowType,
4141
};
4242
use gtk::Orientation::Vertical;
43-
use relm::{Relm, Resolver, Widget};
43+
use relm::{Relm, Resolver, Update, Widget};
4444

4545
use Msg::*;
4646

@@ -62,27 +62,20 @@ struct Win {
6262
window: Window,
6363
}
6464

65-
impl Widget for Win {
65+
impl Update for Win {
6666
// Specify the model used for this widget.
6767
type Model = Model;
6868
// Specify the model parameter used to init the model.
6969
type ModelParam = ();
7070
// Specify the type of the messages sent to the update function.
7171
type Msg = Msg;
72-
// Specify the type of the root widget.
73-
type Root = Window;
7472

7573
fn model(_: &Relm<Self>, _: ()) -> Model {
7674
Model {
7775
counter: 0,
7876
}
7977
}
8078

81-
// Return the root widget.
82-
fn root(&self) -> Self::Root {
83-
self.window.clone()
84-
}
85-
8679
fn update(&mut self, event: Msg) {
8780
let label = &self.counter_label;
8881

@@ -99,6 +92,16 @@ impl Widget for Win {
9992
},
10093
}
10194
}
95+
}
96+
97+
impl Widget for Win {
98+
// Specify the type of the root widget.
99+
type Root = Window;
100+
101+
// Return the root widget.
102+
fn root(&self) -> Self::Root {
103+
self.window.clone()
104+
}
102105

103106
fn view(relm: &Relm<Self>, model: Self::Model) -> Rc<RefCell<Self>> {
104107
// Create the view using the normal GTK+ method calls.

Diff for: examples/buttons.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use gtk::{
3939
WindowType,
4040
};
4141
use gtk::Orientation::Vertical;
42-
use relm::{Relm, Widget};
42+
use relm::{Relm, Update, Widget};
4343

4444
struct Model {
4545
counter: i32,
@@ -59,27 +59,20 @@ struct Win {
5959
window: Window,
6060
}
6161

62-
impl Widget for Win {
62+
impl Update for Win {
6363
// Specify the model used for this widget.
6464
type Model = Model;
6565
// Specify the model parameter used to init the model.
6666
type ModelParam = ();
6767
// Specify the type of the messages sent to the update function.
6868
type Msg = Msg;
69-
// Specify the type of the root widget.
70-
type Root = Window;
7169

7270
fn model(_: &Relm<Self>, _: ()) -> Model {
7371
Model {
7472
counter: 0,
7573
}
7674
}
7775

78-
// Return the root widget.
79-
fn root(&self) -> Self::Root {
80-
self.window.clone()
81-
}
82-
8376
fn update(&mut self, event: Msg) {
8477
let label = &self.counter_label;
8578

@@ -96,6 +89,16 @@ impl Widget for Win {
9689
Msg::Quit => gtk::main_quit(),
9790
}
9891
}
92+
}
93+
94+
impl Widget for Win {
95+
// Specify the type of the root widget.
96+
type Root = Window;
97+
98+
// Return the root widget.
99+
fn root(&self) -> Self::Root {
100+
self.window.clone()
101+
}
99102

100103
fn view(relm: &Relm<Self>, model: Self::Model) -> Rc<RefCell<Self>> {
101104
// Create the view using the normal GTK+ method calls.

Diff for: examples/checkboxes.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use gtk::{
3838
WindowType,
3939
};
4040
use gtk::Orientation::Vertical;
41-
use relm::{Component, ContainerWidget, Relm, Widget};
41+
use relm::{Component, ContainerWidget, Relm, Update, Widget};
4242

4343
use self::CheckMsg::*;
4444
use self::Msg::*;
@@ -61,11 +61,10 @@ struct CheckButton {
6161
relm: Relm<CheckButton>,
6262
}
6363

64-
impl Widget for CheckButton {
64+
impl Update for CheckButton {
6565
type Model = CheckModel;
6666
type ModelParam = &'static str;
6767
type Msg = CheckMsg;
68-
type Root = gtk::CheckButton;
6968

7069
fn model(_: &Relm<Self>, label: &'static str) -> CheckModel {
7170
CheckModel {
@@ -74,10 +73,6 @@ impl Widget for CheckButton {
7473
}
7574
}
7675

77-
fn root(&self) -> Self::Root {
78-
self.button.clone()
79-
}
80-
8176
fn update(&mut self, event: CheckMsg) {
8277
match event {
8378
Check => {
@@ -99,6 +94,14 @@ impl Widget for CheckButton {
9994
},
10095
}
10196
}
97+
}
98+
99+
impl Widget for CheckButton {
100+
type Root = gtk::CheckButton;
101+
102+
fn root(&self) -> Self::Root {
103+
self.button.clone()
104+
}
102105

103106
fn view(relm: &Relm<Self>, model: Self::Model) -> Rc<RefCell<Self>> {
104107
let button = gtk::CheckButton::new_with_label(model.label);
@@ -126,19 +129,14 @@ struct Win {
126129
window: Window,
127130
}
128131

129-
impl Widget for Win {
132+
impl Update for Win {
130133
type Model = ();
131134
type ModelParam = ();
132135
type Msg = Msg;
133-
type Root = Window;
134136

135137
fn model(_: &Relm<Self>, _: ()) -> () {
136138
}
137139

138-
fn root(&self) -> Self::Root {
139-
self.window.clone()
140-
}
141-
142140
fn update(&mut self, event: Msg) {
143141
match event {
144142
Quit => gtk::main_quit(),
@@ -160,6 +158,14 @@ impl Widget for Win {
160158
},
161159
}
162160
}
161+
}
162+
163+
impl Widget for Win {
164+
type Root = Window;
165+
166+
fn root(&self) -> Self::Root {
167+
self.window.clone()
168+
}
163169

164170
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
165171
let vbox = gtk::Box::new(Vertical, 0);

Diff for: examples/child-prop.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use gtk::{
4242
};
4343
use gtk::Orientation::Vertical;
4444
use gtk::WindowType::Toplevel;
45-
use relm::{Component, ContainerWidget, Relm, Widget};
45+
use relm::{Component, ContainerWidget, Relm, Update, Widget};
4646

4747
use self::Msg::*;
4848

@@ -54,15 +54,21 @@ struct Button {
5454
button: gtk::Button,
5555
}
5656

57-
impl Widget for Button {
57+
impl Update for Button {
5858
type Model = ();
5959
type ModelParam = ();
6060
type Msg = ButtonMsg;
61-
type Root = gtk::Button;
6261

6362
fn model(_: &Relm<Self>, _: ()) -> () {
6463
}
6564

65+
fn update(&mut self, _msg: ButtonMsg) {
66+
}
67+
}
68+
69+
impl Widget for Button {
70+
type Root = gtk::Button;
71+
6672
fn root(&self) -> Self::Root {
6773
self.button.clone()
6874
}
@@ -79,9 +85,6 @@ impl Widget for Button {
7985
parent.set_child_position(&self.button, 0);
8086
}
8187

82-
fn update(&mut self, _msg: ButtonMsg) {
83-
}
84-
8588
fn view(_relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
8689
let button = gtk::Button::new_with_label("+");
8790

@@ -101,24 +104,27 @@ struct Win {
101104
window: gtk::Window,
102105
}
103106

104-
impl Widget for Win {
107+
impl Update for Win {
105108
type Model = ();
106109
type ModelParam = ();
107110
type Msg = Msg;
108-
type Root = gtk::Window;
109111

110112
fn model(_: &Relm<Self>, _: ()) -> () {
111113
}
112114

113-
fn root(&self) -> Self::Root {
114-
self.window.clone()
115-
}
116-
117115
fn update(&mut self, event: Msg) {
118116
match event {
119117
Quit => gtk::main_quit(),
120118
}
121119
}
120+
}
121+
122+
impl Widget for Win {
123+
type Root = gtk::Window;
124+
125+
fn root(&self) -> Self::Root {
126+
self.window.clone()
127+
}
122128

123129
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
124130
let window = gtk::Window::new(Toplevel);

Diff for: examples/clock-nightly.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::time::Duration;
3636
use chrono::Local;
3737
use futures_glib::Interval;
3838
use gtk::{ContainerExt, Inhibit, Label, WidgetExt, Window, WindowType};
39-
use relm::{Relm, Widget};
39+
use relm::{Relm, Update, Widget};
4040

4141
use self::Msg::*;
4242

@@ -51,21 +51,16 @@ struct Win {
5151
window: Window,
5252
}
5353

54-
impl Widget for Win {
54+
impl Update for Win {
5555
type Model = ();
5656
type ModelParam = ();
5757
type Msg = Msg;
58-
type Root = Window;
5958

6059
fn model(_: &Relm<Self>, _: ()) -> () {
6160
()
6261
}
6362

64-
fn root(&self) -> Self::Root {
65-
self.window.clone()
66-
}
67-
68-
fn subscriptions(relm: &Relm<Msg>) {
63+
fn subscriptions(relm: &Relm<Self>) {
6964
let stream = Interval::new(Duration::from_secs(1));
7065
relm.connect_exec_ignore_err(stream, Tick);
7166
}
@@ -79,6 +74,14 @@ impl Widget for Win {
7974
Quit => gtk::main_quit(),
8075
}
8176
}
77+
}
78+
79+
impl Widget for Win {
80+
type Root = Window;
81+
82+
fn root(&self) -> Self::Root {
83+
self.window.clone()
84+
}
8285

8386
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
8487
let label = Label::new(None);

Diff for: examples/clock.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use std::time::Duration;
3434
use chrono::Local;
3535
use futures_glib::Interval;
3636
use gtk::{ContainerExt, Inhibit, Label, WidgetExt, Window, WindowType};
37-
use relm::{Relm, Widget};
37+
use relm::{Relm, Update, Widget};
3838

3939
use self::Msg::*;
4040

@@ -49,21 +49,16 @@ struct Win {
4949
window: Window,
5050
}
5151

52-
impl Widget for Win {
52+
impl Update for Win {
5353
type Model = ();
5454
type ModelParam = ();
5555
type Msg = Msg;
56-
type Root = Window;
5756

5857
fn model(_: &Relm<Self>, _: ()) -> () {
5958
()
6059
}
6160

62-
fn root(&self) -> Self::Root {
63-
self.window.clone()
64-
}
65-
66-
fn subscriptions(relm: &Relm<Msg>) {
61+
fn subscriptions(relm: &Relm<Self>) {
6762
let stream = Interval::new(Duration::from_secs(1));
6863
relm.connect_exec_ignore_err(stream, Tick);
6964
}
@@ -77,6 +72,14 @@ impl Widget for Win {
7772
Quit => gtk::main_quit(),
7873
}
7974
}
75+
}
76+
77+
impl Widget for Win {
78+
type Root = Window;
79+
80+
fn root(&self) -> Self::Root {
81+
self.window.clone()
82+
}
8083

8184
fn view(relm: &Relm<Self>, _model: Self::Model) -> Rc<RefCell<Self>> {
8285
let label = Label::new(None);

0 commit comments

Comments
 (0)