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

Commit 5b9c4b2

Browse files
Merge pull request #231 from gtk-rs/pending
[release] merging pending into master
2 parents f802d64 + e8e82bb commit 5b9c4b2

33 files changed

+1531
-739
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: xenial
12
language: rust
23
rust:
34
- nightly
@@ -7,9 +8,11 @@ addons:
78
apt:
89
packages:
910
- libgtk-3-dev
11+
- libmount-dev
1012
env:
11-
- GTK=3.4
13+
- GTK=3.14
1214
- GTK=3.18
1315
- GTK=3.22.30
16+
- GTK=3.24
1417
script:
1518
- ./build_travis.sh

Cargo.toml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
name = "gtk-rs-examples"
33
version = "0.0.1"
44
authors = ["The Gtk-rs Project Developers"]
5+
autobins = false
56

67
[dependencies]
78
chrono = "0.4"
89
url = "1.4"
910
futures-preview = { version = "0.2", optional = true }
11+
atk = "^0"
1012
gobject-subclass = "^0"
1113
glib-sys = "^0"
1214
gobject-sys = "^0"
@@ -19,14 +21,15 @@ pango = "^0"
1921
cairo-rs = { version = "^0", features = ["png"] }
2022

2123
[features]
22-
#default = ["gtk_3_22_30", "futures-stable"]
23-
gtk_3_10 = ["gtk/v3_10"]
24-
gtk_3_16 = ["gtk_3_10", "gtk/v3_16"]
25-
gtk_3_18 = ["gtk_3_16", "gtk/v3_18"] #for CI tools
26-
gtk_3_20 = ["gtk_3_18", "gtk/v3_20"] #for CI tools
27-
gtk_3_22 = ["gtk_3_20", "gtk/v3_22"] #for CI tools
28-
gtk_3_22_30 = ["gtk_3_22", "gtk/v3_22_30"] #for CI tools
24+
#default = ["gtk_3_22_30", "futures-stable", "subclassing"]
25+
gtk_3_18 = ["gtk/v3_18", "gdk-pixbuf/v2_32", "gdk/v3_18", "gio/v2_46", "glib/v2_46", "pango/v1_38"] #for CI tools
26+
gtk_3_22_30 = ["gtk_3_18", "gtk/v3_22_30", "gdk-pixbuf/v2_36", "gdk/v3_22", "gio/v2_56", "glib/v2_56", "pango/v1_42"] #for CI tools
27+
gtk_3_24 = ["gtk_3_22_30", "gtk/v3_24", "atk/v2_30", "gdk-pixbuf/v2_36_8", "gdk/v3_24", "gio/v2_58", "glib/v2_58"] #for CI tools
2928
futures-stable = ["futures-preview", "glib/futures", "gio/futures"]
29+
subclassing = ["glib/subclassing"]
30+
31+
[[bin]]
32+
name = "accessibility"
3033

3134
[[bin]]
3235
name = "basic"
@@ -49,6 +52,9 @@ name = "child-properties"
4952
[[bin]]
5053
name = "clock"
5154

55+
[[bin]]
56+
name = "css"
57+
5258
[[bin]]
5359
name = "drag_and_drop"
5460

@@ -71,14 +77,13 @@ name = "gtktest"
7177

7278
[[bin]]
7379
name = "listbox_model"
74-
required-features = ["gtk/v3_16", "gio/v2_44"]
80+
required-features = ["gtk/v3_16", "gio/v2_44", "subclassing"]
7581

7682
[[bin]]
7783
name = "menu_bar"
7884

7985
[[bin]]
8086
name = "menu_bar_system"
81-
required-features = ["gtk/v3_12"]
8287

8388
[[bin]]
8489
name = "multi_windows"
@@ -89,9 +94,16 @@ name = "multithreading_context"
8994
[[bin]]
9095
name = "notebook"
9196

97+
[[bin]]
98+
name = "overlay"
99+
92100
[[bin]]
93101
name = "pango_attributes"
94102

103+
[[bin]]
104+
name = "progress_tracker"
105+
path = "src/bin/progress_tracker.rs"
106+
95107
[[bin]]
96108
name = "simple_treeview"
97109

@@ -104,5 +116,11 @@ name = "text_viewer"
104116
[[bin]]
105117
name = "transparent_main_window"
106118

119+
[[bin]]
120+
name = "tree_model_sort"
121+
107122
[[bin]]
108123
name = "treeview"
124+
125+
[[bin]]
126+
name = "list_store"

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ install:
1717

1818
build_script:
1919
- cargo build
20-
- cargo build --features gtk_3_20
20+
- cargo build --features gtk_3_24
2121

2222
test: false

build_travis.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
set -x
44
set -e
55

6-
if [ "$GTK" = latest -o "$GTK" = "3.22.30" ]; then
6+
if [ "$GTK" = latest -o "$GTK" = "3.24" ]; then
7+
BUNDLE="gtk-3.24.0-1"
8+
if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
9+
FEATURES=gtk_3_24,futures-stable,gio/v2_44,subclassing
10+
else
11+
FEATURES=gtk_3_24,futures-stable,gio/v2_44,subclassing
12+
fi
13+
elif [ "$GTK" = "3.22.30" ]; then
714
BUNDLE="gtk-3.22.30-1"
815
if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
9-
FEATURES=gtk_3_22_30,futures-stable
16+
FEATURES=gtk_3_22_30,futures-stable,gio/v2_44,subclassing
1017
else
11-
FEATURES=gtk_3_22_30,futures-stable
18+
FEATURES=gtk_3_22_30,futures-stable,gio/v2_44,subclassing
1219
fi
1320
elif [ "$GTK" = "3.18" ]; then
1421
BUNDLE="gtk-3.18.1-2"
1522
if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
16-
FEATURES=gtk_3_18,futures-stable
23+
FEATURES=gtk_3_18,futures-stable,gio/v2_44,subclassing
1724
else
18-
FEATURES=gtk_3_18,futures-stable
25+
FEATURES=gtk_3_18,futures-stable,gio/v2_44,subclassing
1926
fi
2027
fi
2128

@@ -28,4 +35,4 @@ if [ -n "$BUNDLE" ]; then
2835
export PKG_CONFIG_PATH="$HOME/local/lib/pkgconfig"
2936
fi
3037

31-
cargo build --features "$FEATURES" --jobs 1 "$@"
38+
PKG_CONFIG_ALLOW_CROSS=1 cargo check $OTHER_TARGET --features "$FEATURES" --jobs 1 "$@"

resources/menu.png

2.01 KB
Loading

src/bin/accessibility.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! # Accessibility example
2+
//!
3+
//! This sample demonstrates how to make an application more accessible.
4+
5+
extern crate atk;
6+
extern crate gdk;
7+
extern crate gio;
8+
extern crate glib;
9+
extern crate gtk;
10+
11+
use atk::prelude::*;
12+
use gio::prelude::*;
13+
use gtk::prelude::*;
14+
15+
use std::env::args;
16+
17+
fn build_ui(application: &gtk::Application) {
18+
let window = gtk::ApplicationWindow::new(application);
19+
20+
window.set_title("Accessibility");
21+
window.set_position(gtk::WindowPosition::Center);
22+
23+
let button = gtk::Button::new_with_label("Click me!");
24+
let label = gtk::Label::new("0");
25+
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
26+
27+
if let (Some(button_obj), Some(label_obj)) = (button.get_accessible(), label.get_accessible()) {
28+
// We set the description
29+
button_obj.set_description("Button to increase label value");
30+
31+
// Then we setup the relation saying that the label is linked to the button.
32+
let relation_set = label_obj.ref_relation_set().expect("Failed to get relation for label");
33+
let relation = atk::Relation::new(&[button_obj], atk::RelationType::LabelFor);
34+
35+
relation_set.add(&relation);
36+
}
37+
38+
vbox.add(&button);
39+
vbox.add(&label);
40+
41+
window.add(&vbox);
42+
43+
button.connect_clicked(move |_| {
44+
let value = label.get_text()
45+
.and_then(|s| u32::from_str_radix(&s, 10).ok())
46+
.unwrap_or(0) + 1;
47+
label.set_text(&value.to_string());
48+
});
49+
50+
window.show_all();
51+
}
52+
53+
fn main() {
54+
let application = gtk::Application::new("com.github.accessibility",
55+
gio::ApplicationFlags::empty())
56+
.expect("Initialization failed...");
57+
58+
application.connect_activate(|app| {
59+
// We build the application UI.
60+
build_ui(app);
61+
});
62+
63+
application.run(&args().collect::<Vec<_>>());
64+
}

src/bin/basic.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ fn build_ui(application: &gtk::Application) {
2020
window.set_position(gtk::WindowPosition::Center);
2121
window.set_default_size(350, 70);
2222

23-
window.connect_delete_event(move |win, _| {
24-
win.destroy();
25-
Inhibit(false)
26-
});
27-
2823
let button = gtk::Button::new_with_label("Click me!");
2924

3025
window.add(&button);
@@ -33,14 +28,13 @@ fn build_ui(application: &gtk::Application) {
3328
}
3429

3530
fn main() {
36-
let application = gtk::Application::new("com.github.basic",
37-
gio::ApplicationFlags::empty())
31+
let application = gtk::Application::new("com.github.gtk-rs.examples.basic",
32+
Default::default())
3833
.expect("Initialization failed...");
3934

40-
application.connect_startup(|app| {
35+
application.connect_activate(|app| {
4136
build_ui(app);
4237
});
43-
application.connect_activate(|_| {});
4438

4539
application.run(&args().collect::<Vec<_>>());
4640
}

src/bin/builder_basics.rs

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

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

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

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

18-
use std::env::args;
1915

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);
2019

21-
pub fn build_ui(application: &gtk::Application) {
22-
let glade_src = include_str!("builder_basics.glade");
23-
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");
2425

25-
let window: ApplicationWindow = builder.get_object("window1").expect("Couldn't get window1");
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-
window.set_application(application);
31-
window.connect_delete_event(move |win, _| {
32-
win.destroy();
33-
Inhibit(false)
34-
});
35-
36-
bigbutton.connect_clicked(move |_| {
37-
dialog.run();
38-
dialog.hide();
39-
});
40-
41-
window.show_all();
42-
}
43-
44-
pub fn main() {
45-
let application = gtk::Application::new("com.github.builder_basics",
46-
gio::ApplicationFlags::empty())
47-
.expect("Initialization failed...");
48-
49-
application.connect_startup(move |app| {
50-
build_ui(app);
51-
});
52-
application.connect_activate(|_| {});
53-
54-
application.run(&args().collect::<Vec<_>>());
55-
}
31+
window.show_all();
5632
}
5733

58-
#[cfg(feature = "gtk_3_10")]
5934
fn main() {
60-
example::main()
61-
}
35+
let application = gtk::Application::new("com.github.gtk-rs.examples.builder_basics",
36+
Default::default())
37+
.expect("Initialization failed...");
6238

63-
#[cfg(not(feature = "gtk_3_10"))]
64-
fn main() {
65-
println!("This example requires GTK 3.10 or later");
66-
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<_>>());
6744
}

0 commit comments

Comments
 (0)