Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit dd61411

Browse files
Merge pull request #232 from EPashkin/remove_gtk_3_10
Remove checking for gtk_3_10
2 parents 0327ad5 + 6e7b338 commit dd61411

File tree

3 files changed

+254
-300
lines changed

3 files changed

+254
-300
lines changed

src/bin/builder_basics.rs

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,40 @@
55
extern crate gio;
66
extern crate gtk;
77

8-
#[cfg(feature = "gtk_3_10")]
9-
mod example {
10-
use gtk;
8+
use gio::prelude::*;
9+
use gtk::prelude::*;
1110

12-
use gio::prelude::*;
13-
use gtk::prelude::*;
11+
use gtk::{ApplicationWindow, Builder, Button, MessageDialog};
1412

15-
use gtk::{ApplicationWindow, Builder, Button, MessageDialog};
13+
use std::env::args;
1614

17-
use std::env::args;
1815

16+
fn build_ui(application: &gtk::Application) {
17+
let glade_src = include_str!("builder_basics.glade");
18+
let builder = Builder::new_from_string(glade_src);
1919

20-
pub fn build_ui(application: &gtk::Application) {
21-
let glade_src = include_str!("builder_basics.glade");
22-
let builder = Builder::new_from_string(glade_src);
20+
let window: ApplicationWindow = builder.get_object("window1").expect("Couldn't get window1");
21+
window.set_application(application);
22+
let bigbutton: Button = builder.get_object("button1").expect("Couldn't get button1");
23+
let dialog: MessageDialog = builder.get_object("messagedialog1")
24+
.expect("Couldn't get messagedialog1");
2325

24-
let window: ApplicationWindow = builder.get_object("window1").expect("Couldn't get window1");
25-
window.set_application(application);
26-
let bigbutton: Button = builder.get_object("button1").expect("Couldn't get button1");
27-
let dialog: MessageDialog = builder.get_object("messagedialog1")
28-
.expect("Couldn't get messagedialog1");
26+
bigbutton.connect_clicked(move |_| {
27+
dialog.run();
28+
dialog.hide();
29+
});
2930

30-
bigbutton.connect_clicked(move |_| {
31-
dialog.run();
32-
dialog.hide();
33-
});
34-
35-
window.show_all();
36-
}
37-
38-
pub fn main() {
39-
let application = gtk::Application::new("com.github.gtk-rs.examples.builder_basics",
40-
Default::default())
41-
.expect("Initialization failed...");
42-
43-
application.connect_activate(|app| {
44-
build_ui(app);
45-
});
46-
47-
application.run(&args().collect::<Vec<_>>());
48-
}
31+
window.show_all();
4932
}
5033

51-
#[cfg(feature = "gtk_3_10")]
5234
fn main() {
53-
example::main()
54-
}
35+
let application = gtk::Application::new("com.github.gtk-rs.examples.builder_basics",
36+
Default::default())
37+
.expect("Initialization failed...");
5538

56-
#[cfg(not(feature = "gtk_3_10"))]
57-
fn main() {
58-
println!("This example requires GTK 3.10 or later");
59-
println!("Did you forget to build with `--features gtk_3_10`?");
39+
application.connect_activate(|app| {
40+
build_ui(app);
41+
});
42+
43+
application.run(&args().collect::<Vec<_>>());
6044
}

src/bin/grid.rs

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,63 @@
33
extern crate gio;
44
extern crate gtk;
55

6-
#[cfg(feature = "gtk_3_10")]
7-
mod example {
8-
use gtk;
9-
use gio::prelude::*;
10-
use gtk::prelude::*;
11-
use gtk::{
12-
ApplicationWindow, Builder, Button, Grid,
13-
};
14-
15-
use std::env::args;
16-
17-
// upgrade weak reference or return
18-
#[macro_export]
19-
macro_rules! upgrade_weak {
20-
($x:ident, $r:expr) => {{
21-
match $x.upgrade() {
22-
Some(o) => o,
23-
None => return $r,
24-
}
25-
}};
26-
($x:ident) => {
27-
upgrade_weak!($x, ())
28-
};
29-
}
6+
use gio::prelude::*;
7+
use gtk::prelude::*;
8+
use gtk::{
9+
ApplicationWindow, Builder, Button, Grid,
10+
};
3011

31-
pub fn build_ui(application: &gtk::Application) {
32-
let glade_src = include_str!("grid.glade");
33-
let builder = Builder::new_from_string(glade_src);
12+
use std::env::args;
3413

35-
let window: ApplicationWindow = builder.get_object("window").expect("Couldn't get window");
36-
window.set_application(application);
37-
let grid: Grid = builder.get_object("grid").expect("Couldn't get grid");
38-
let button6: Button = builder.get_object("button6").expect("Couldn't get button6");
39-
let weak_grid = grid.downgrade();
40-
button6.connect_clicked(move |button| {
41-
let grid = upgrade_weak!(weak_grid);
42-
let height = grid.get_cell_height(button);
43-
let new_height = if height == 2 { 1 } else { 2 };
44-
grid.set_cell_height(button, new_height);
45-
});
46-
let button7: Button = builder.get_object("button7").expect("Couldn't get button7");
47-
let weak_grid = grid.downgrade();
48-
button7.connect_clicked(move |button| {
49-
let grid = upgrade_weak!(weak_grid);
50-
let left_attach = grid.get_cell_left_attach(button);
51-
let new_left_attach = if left_attach == 2 { 0 } else { left_attach + 1 };
52-
grid.set_cell_left_attach(button, new_left_attach);
53-
});
54-
55-
window.show_all();
56-
}
14+
// upgrade weak reference or return
15+
#[macro_export]
16+
macro_rules! upgrade_weak {
17+
($x:ident, $r:expr) => {{
18+
match $x.upgrade() {
19+
Some(o) => o,
20+
None => return $r,
21+
}
22+
}};
23+
($x:ident) => {
24+
upgrade_weak!($x, ())
25+
};
26+
}
5727

58-
pub fn main() {
59-
let application = gtk::Application::new("com.github.gtk-rs.examples.grid",
60-
Default::default())
61-
.expect("Initialization failed...");
28+
fn build_ui(application: &gtk::Application) {
29+
let glade_src = include_str!("grid.glade");
30+
let builder = Builder::new_from_string(glade_src);
6231

63-
application.connect_activate(|app| {
64-
build_ui(app);
65-
});
32+
let window: ApplicationWindow = builder.get_object("window").expect("Couldn't get window");
33+
window.set_application(application);
34+
let grid: Grid = builder.get_object("grid").expect("Couldn't get grid");
35+
let button6: Button = builder.get_object("button6").expect("Couldn't get button6");
36+
let weak_grid = grid.downgrade();
37+
button6.connect_clicked(move |button| {
38+
let grid = upgrade_weak!(weak_grid);
39+
let height = grid.get_cell_height(button);
40+
let new_height = if height == 2 { 1 } else { 2 };
41+
grid.set_cell_height(button, new_height);
42+
});
43+
let button7: Button = builder.get_object("button7").expect("Couldn't get button7");
44+
let weak_grid = grid.downgrade();
45+
button7.connect_clicked(move |button| {
46+
let grid = upgrade_weak!(weak_grid);
47+
let left_attach = grid.get_cell_left_attach(button);
48+
let new_left_attach = if left_attach == 2 { 0 } else { left_attach + 1 };
49+
grid.set_cell_left_attach(button, new_left_attach);
50+
});
6651

67-
application.run(&args().collect::<Vec<_>>());
68-
}
52+
window.show_all();
6953
}
7054

71-
#[cfg(feature = "gtk_3_10")]
7255
fn main() {
73-
example::main()
74-
}
56+
let application = gtk::Application::new("com.github.gtk-rs.examples.grid",
57+
Default::default())
58+
.expect("Initialization failed...");
7559

76-
#[cfg(not(feature = "gtk_3_10"))]
77-
fn main() {
78-
println!("This example requires GTK 3.10 or later");
79-
println!("Did you forget to build with `--features gtk_3_10`?");
60+
application.connect_activate(|app| {
61+
build_ui(app);
62+
});
63+
64+
application.run(&args().collect::<Vec<_>>());
8065
}

0 commit comments

Comments
 (0)