Skip to content

Commit a84f7d1

Browse files
examples: Clean up imports
Makes things consistent for the reader: - Use prelude from gtk as it re-exports glib's prelude - Stop using imports for stuff that is used only once. It doesn't make the code more readable - Sort & organize imports, this is done using a rustfmt nightly feature & took that opportunity to also use it for cleaning up the comments
1 parent 49fb9a8 commit a84f7d1

File tree

96 files changed

+378
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+378
-431
lines changed

examples/basics/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use gtk::glib;
2-
use gtk::prelude::*;
1+
use gtk::{glib, prelude::*};
32

43
fn main() -> glib::ExitCode {
54
let application = gtk::Application::builder()

examples/builder_pattern/main.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
use gtk::prelude::*;
2-
use gtk::{glib, Align, Application, ApplicationWindow, Button};
1+
use gtk::{glib, prelude::*};
32

43
fn main() -> glib::ExitCode {
5-
let application = Application::new(
6-
Some("com.github.gtk-rs.examples.builder_pattern"),
7-
Default::default(),
8-
);
4+
let application = gtk::Application::builder()
5+
.application_id("com.github.gtk-rs.examples.builder_pattern")
6+
.build();
97
application.connect_activate(build_ui);
108
application.run()
119
}
1210

13-
fn build_ui(application: &Application) {
14-
let window = ApplicationWindow::builder()
11+
fn build_ui(application: &gtk::Application) {
12+
let window = gtk::ApplicationWindow::builder()
1513
.application(application)
1614
.title("First GTK Program")
1715
.default_width(350)
1816
.default_height(70)
1917
.build();
2018

21-
let button = Button::builder()
19+
let button = gtk::Button::builder()
2220
.margin_top(10)
2321
.margin_bottom(10)
2422
.margin_start(10)
2523
.margin_end(10)
26-
.halign(Align::Center)
27-
.valign(Align::Center)
24+
.halign(gtk::Align::Center)
25+
.valign(gtk::Align::Center)
2826
.label("Click Me!")
2927
.build();
3028

examples/clipboard/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use glib::clone;
2-
use gtk::prelude::*;
3-
use gtk::{gdk, gio, glib};
1+
use gtk::{
2+
gdk, gio,
3+
glib::{self, clone},
4+
prelude::*,
5+
};
46

57
fn main() -> glib::ExitCode {
68
let application = gtk::Application::builder()

examples/clock/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
use chrono::Local;
2-
use gtk::glib;
3-
use gtk::prelude::*;
4-
use gtk::{Application, ApplicationWindow, Label};
2+
use gtk::{glib, prelude::*};
53

64
fn main() -> glib::ExitCode {
7-
let application =
8-
Application::new(Some("com.github.gtk-rs.examples.clock"), Default::default());
5+
let application = gtk::Application::builder()
6+
.application_id("com.github.gtk-rs.examples.clock")
7+
.build();
98
application.connect_activate(build_ui);
109
application.run()
1110
}
1211

13-
fn build_ui(application: &Application) {
14-
let window = ApplicationWindow::new(application);
12+
fn build_ui(application: &gtk::Application) {
13+
let window = gtk::ApplicationWindow::new(application);
1514

1615
window.set_title(Some("Clock Example"));
1716
window.set_default_size(260, 40);
1817

1918
let time = current_time();
20-
let label = Label::new(None);
19+
let label = gtk::Label::default();
2120
label.set_text(&time);
2221

2322
window.set_child(Some(&label));
2423

2524
window.present();
2625

27-
// we are using a closure to capture the label (else we could also use a normal function)
26+
// we are using a closure to capture the label (else we could also use a normal
27+
// function)
2828
let tick = move || {
2929
let time = current_time();
3030
label.set_text(&time);

examples/column_view_datagrid/grid_cell/imp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use gtk::glib;
2-
use gtk::subclass::prelude::*;
1+
use gtk::{glib, subclass::prelude::*};
32

43
#[derive(Debug, Default, gtk::CompositeTemplate)]
54
#[template(file = "grid_cell.ui")]
@@ -18,8 +17,9 @@ impl ObjectSubclass for GridCell {
1817
type ParentType = gtk::Widget;
1918

2019
fn class_init(klass: &mut Self::Class) {
21-
// When inheriting from GtkWidget directly, you have to either override the size_allocate/measure
22-
// functions of WidgetImpl trait or use a layout manager which provides those functions for your widgets like below.
20+
// When inheriting from GtkWidget directly, you have to either override the
21+
// size_allocate/measure functions of WidgetImpl trait or use a layout
22+
// manager which provides those functions for your widgets like below.
2323
klass.set_layout_manager_type::<gtk::BinLayout>();
2424
klass.bind_template();
2525
}

examples/column_view_datagrid/grid_cell/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod imp;
2-
use gtk::glib;
3-
use gtk::subclass::prelude::*;
2+
use gtk::{glib, subclass::prelude::*};
43

54
glib::wrapper! {
65
pub struct GridCell(ObjectSubclass<imp::GridCell>)

examples/column_view_datagrid/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
mod grid_cell;
22

3-
use crate::grid_cell::Entry;
4-
use crate::grid_cell::GridCell;
5-
use gtk::glib::BoxedAnyObject;
6-
use gtk::prelude::*;
7-
use gtk::{gio, glib};
3+
use gtk::{
4+
gio,
5+
glib::{self, BoxedAnyObject},
6+
prelude::*,
7+
};
8+
9+
use crate::grid_cell::{Entry, GridCell};
810

911
struct Row {
1012
col1: String,

examples/composite_template/ex_application_window/imp.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use gtk::prelude::*;
2-
use gtk::subclass::prelude::*;
3-
use gtk::{glib, CompositeTemplate};
1+
use gtk::{glib, prelude::*, subclass::prelude::*};
42

53
use crate::ex_menu_button::ExMenuButton;
64

75
/// The private struct, which can hold widgets and other data.
8-
#[derive(Debug, Default, CompositeTemplate)]
6+
#[derive(Debug, Default, gtk::CompositeTemplate)]
97
#[template(file = "ex_application_window.ui")]
108
pub struct ExApplicationWindow {
119
// The #[template_child] attribute tells the CompositeTemplate macro

examples/composite_template/ex_application_window/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod imp;
22

3-
use gtk::subclass::prelude::*;
4-
use gtk::{gio, glib};
3+
use gtk::{gio, glib, subclass::prelude::*};
54

65
glib::wrapper! {
76
pub struct ExApplicationWindow(ObjectSubclass<imp::ExApplicationWindow>)

examples/composite_template/ex_menu_button/imp.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use gtk::prelude::*;
2-
use gtk::subclass::prelude::*;
3-
use gtk::{glib, CompositeTemplate};
1+
use gtk::{glib, prelude::*, subclass::prelude::*};
42

5-
#[derive(Debug, Default, CompositeTemplate)]
3+
#[derive(Debug, Default, gtk::CompositeTemplate)]
64
#[template(file = "ex_menu_button.ui")]
75
pub struct ExMenuButton {
86
#[template_child]

0 commit comments

Comments
 (0)