Skip to content

Commit e262bd9

Browse files
examples: Prefer using Default trait when possible
Otherwise clippy complains and we have to have a separate constructor for nothing useful
1 parent 20ea8ad commit e262bd9

File tree

40 files changed

+47
-146
lines changed

40 files changed

+47
-146
lines changed

examples/column_view_datagrid/grid_cell/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
mod imp;
22
use gtk::{glib, subclass::prelude::*};
33

4+
pub struct Entry {
5+
pub name: String,
6+
}
7+
48
glib::wrapper! {
59
pub struct GridCell(ObjectSubclass<imp::GridCell>)
610
@extends gtk::Widget;
711
}
812

913
impl Default for GridCell {
1014
fn default() -> Self {
11-
Self::new()
15+
glib::Object::new()
1216
}
1317
}
1418

15-
pub struct Entry {
16-
pub name: String,
17-
}
18-
1919
impl GridCell {
20-
pub fn new() -> Self {
21-
glib::Object::new()
22-
}
23-
2420
pub fn set_entry(&self, entry: &Entry) {
2521
self.imp().name.set_text(Some(&entry.name));
2622
}

examples/column_view_datagrid/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn build_ui(application: &gtk::Application) {
4646
let col2factory = gtk::SignalListItemFactory::new();
4747
col1factory.connect_setup(move |_factory, item| {
4848
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
49-
let row = GridCell::new();
49+
let row = GridCell::default();
5050
item.set_child(Some(&row));
5151
});
5252

@@ -62,7 +62,7 @@ fn build_ui(application: &gtk::Application) {
6262
});
6363
col2factory.connect_setup(move |_factory, item| {
6464
let item = item.downcast_ref::<gtk::ListItem>().unwrap();
65-
let row = GridCell::new();
65+
let row = GridCell::default();
6666
item.set_child(Some(&row));
6767
});
6868

examples/confetti_snapshot_animation/confetti_widget/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ glib::wrapper! {
1414

1515
impl Default for ConfettiWidget {
1616
fn default() -> Self {
17-
Self::new()
17+
glib::Object::new()
1818
}
1919
}
2020

2121
impl ConfettiWidget {
22-
pub fn new() -> Self {
23-
glib::Object::new()
24-
}
2522
pub fn explode(&self, params: ExplosionParameters, duration: f64) -> AnimatedExplosion {
2623
let exp = AnimatedExplosion::new(params);
2724

examples/confetti_snapshot_animation/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn build_ui(application: &gtk::Application) {
2222
window.set_title(Some("Confetti"));
2323
window.set_default_size(640, 360);
2424

25-
let confetti = ConfettiWidget::new();
25+
let confetti = ConfettiWidget::default();
2626
window.set_child(Some(&confetti));
2727

2828
// To listen to click events, we need to add a `GestureClick` controller to our

examples/content_provider/content_provider/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ glib::wrapper! {
77
@extends gdk::ContentProvider;
88
}
99

10-
impl ContentProvider {
11-
pub fn new() -> Self {
12-
glib::Object::new()
13-
}
14-
}
15-
1610
impl Default for ContentProvider {
1711
fn default() -> Self {
18-
Self::new()
12+
glib::Object::new()
1913
}
2014
}

examples/content_provider/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn on_activate(application: &gtk::Application) {
1818
let display = WidgetExt::display(&window);
1919

2020
window.connect_realize(glib::clone!(@weak display, @weak application => move |_| {
21-
let provider = ContentProvider::new();
21+
let provider = ContentProvider::default();
2222
display.clipboard().set_content(Some(&provider)).unwrap();
2323
glib::MainContext::default().spawn_local(glib::clone!(@weak display, @weak application => async move {
2424
let text = display.clipboard().read_text_future().await.unwrap().unwrap();

examples/custom_application/ex_application/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ glib::wrapper! {
1010

1111
impl Default for ExApplication {
1212
fn default() -> Self {
13-
Self::new()
14-
}
15-
}
16-
17-
impl ExApplication {
18-
pub fn new() -> Self {
1913
glib::Object::builder()
2014
.property("application-id", "org.gtk_rs.application-subclass")
2115
.build()

examples/custom_application/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ use ex_application::ExApplication;
44
use gtk::{glib, prelude::*};
55

66
fn main() -> glib::ExitCode {
7-
let app = ExApplication::new();
7+
let app = ExApplication::default();
88
app.run()
99
}

examples/custom_editable/custom_editable/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ glib::wrapper! {
1212

1313
impl Default for CustomEditable {
1414
fn default() -> Self {
15-
Self::new()
15+
glib::Object::new()
1616
}
1717
}
1818

1919
impl CustomEditable {
20-
pub fn new() -> Self {
21-
glib::Object::new()
22-
}
23-
2420
pub fn add_tag(&self, tag: &CustomTag) {
2521
tag.set_parent(self);
2622
}

examples/custom_editable/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn build_ui(application: &gtk::Application) {
3838
container.set_valign(gtk::Align::Center);
3939
container.set_halign(gtk::Align::Center);
4040

41-
let editable = CustomEditable::new();
41+
let editable = CustomEditable::default();
4242
editable.set_halign(gtk::Align::Fill);
4343

4444
container.append(&editable);

0 commit comments

Comments
 (0)