Skip to content

Commit f0e1d9e

Browse files
authored
Merge pull request #1773 from sdroege/clone-new
Update to new clone! macro syntax
2 parents f7ff7a0 + bc99862 commit f0e1d9e

File tree

27 files changed

+542
-300
lines changed

27 files changed

+542
-300
lines changed

.github/workflows/windows-msvc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: Install pkgconfig-lite
4747
run: |
48-
Invoke-WebRequest -Uri https://deac-fra.dl.sourceforge.net/project/pkgconfiglite/0.28-1/pkg-config-lite-0.28-1_bin-win32.zip -OutFile /pkg_config_lite.zip -MaximumRetryCount 5
48+
Invoke-WebRequest -UserAgent "Wget" -Uri https://downloads.sourceforge.net/project/pkgconfiglite/0.28-1/pkg-config-lite-0.28-1_bin-win32.zip -OutFile /pkg_config_lite.zip -MaximumRetryCount 5
4949
Expand-Archive /pkg_config_lite.zip -DestinationPath C:\
5050
ls C:\
5151
ls C:\pkg-config-lite-0.28-1

Cargo.lock

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/about_dialog/main.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,24 @@ fn main() {
2727
let bytes = glib::Bytes::from_static(LOGO_SVG);
2828
let logo = gdk::Texture::from_bytes(&bytes).expect("gtk-rs.svg to load");
2929

30-
button.connect_clicked(glib::clone!(@weak window => move |_| {
31-
let dialog = gtk::AboutDialog::builder()
32-
.transient_for(&window)
33-
.modal(true)
34-
.program_name("About Dialog Example")
35-
.version("0.1.0")
36-
.website("https://gtk-rs.org")
37-
.license_type(gtk::License::MitX11)
38-
.authors(["Author 1", "Author 2"])
39-
.logo(&logo)
40-
.build();
41-
42-
dialog.present();
43-
}));
30+
button.connect_clicked(glib::clone!(
31+
#[weak]
32+
window,
33+
move |_| {
34+
let dialog = gtk::AboutDialog::builder()
35+
.transient_for(&window)
36+
.modal(true)
37+
.program_name("About Dialog Example")
38+
.version("0.1.0")
39+
.website("https://gtk-rs.org")
40+
.license_type(gtk::License::MitX11)
41+
.authors(["Author 1", "Author 2"])
42+
.logo(&logo)
43+
.build();
44+
45+
dialog.present();
46+
}
47+
));
4448

4549
window.present();
4650
});

examples/clipboard/main.rs

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,42 @@ fn build_ui(application: &gtk::Application) {
5454
text_container.append(&from_entry);
5555

5656
let copy_btn = gtk::Button::with_label("Copy");
57-
copy_btn.connect_clicked(clone!(@weak clipboard, @weak from_entry => move |_btn| {
58-
let text = from_entry.text();
59-
clipboard.set_text(&text);
60-
}));
57+
copy_btn.connect_clicked(clone!(
58+
#[weak]
59+
clipboard,
60+
#[weak]
61+
from_entry,
62+
move |_btn| {
63+
let text = from_entry.text();
64+
clipboard.set_text(&text);
65+
}
66+
));
6167
text_container.append(&copy_btn);
6268

6369
let into_entry = gtk::Entry::new();
6470
text_container.append(&into_entry);
6571

6672
let paste_btn = gtk::Button::with_label("Paste");
67-
paste_btn.connect_clicked(clone!(@weak clipboard, @weak into_entry => move |_btn| {
68-
clipboard.read_text_async(gio::Cancellable::NONE, clone!(@weak into_entry => move|res| {
69-
if let Ok(Some(text)) = res {
70-
into_entry.set_text(&text);
71-
}
72-
}));
73-
}));
73+
paste_btn.connect_clicked(clone!(
74+
#[weak]
75+
clipboard,
76+
#[weak]
77+
into_entry,
78+
move |_btn| {
79+
clipboard.read_text_async(
80+
gio::Cancellable::NONE,
81+
clone!(
82+
#[weak]
83+
into_entry,
84+
move |res| {
85+
if let Ok(Some(text)) = res {
86+
into_entry.set_text(&text);
87+
}
88+
}
89+
),
90+
);
91+
}
92+
));
7493
text_container.append(&paste_btn);
7594
container.append(&text_container);
7695

@@ -100,10 +119,19 @@ fn build_ui(application: &gtk::Application) {
100119
.label("Copy")
101120
.valign(gtk::Align::Center)
102121
.build();
103-
copy_texture_btn.connect_clicked(clone!(@weak clipboard, @weak image_from => move |_btn| {
104-
let texture = image_from.paintable().and_downcast::<gdk::Texture>().unwrap();
105-
clipboard.set_texture(&texture);
106-
}));
122+
copy_texture_btn.connect_clicked(clone!(
123+
#[weak]
124+
clipboard,
125+
#[weak]
126+
image_from,
127+
move |_btn| {
128+
let texture = image_from
129+
.paintable()
130+
.and_downcast::<gdk::Texture>()
131+
.unwrap();
132+
clipboard.set_texture(&texture);
133+
}
134+
));
107135
texture_container.append(&copy_texture_btn);
108136

109137
let image_into = gtk::Image::builder()
@@ -115,13 +143,24 @@ fn build_ui(application: &gtk::Application) {
115143
.label("Paste")
116144
.valign(gtk::Align::Center)
117145
.build();
118-
paste_texture_btn.connect_clicked(clone!(@weak clipboard => move |_btn| {
119-
clipboard.read_texture_async(gio::Cancellable::NONE, clone!(@weak image_into => move |res| {
120-
if let Ok(Some(texture)) = res {
121-
image_into.set_paintable(Some(&texture));
122-
}
123-
}));
124-
}));
146+
paste_texture_btn.connect_clicked(clone!(
147+
#[weak]
148+
clipboard,
149+
move |_btn| {
150+
clipboard.read_texture_async(
151+
gio::Cancellable::NONE,
152+
clone!(
153+
#[weak]
154+
image_into,
155+
move |res| {
156+
if let Ok(Some(texture)) = res {
157+
image_into.set_paintable(Some(&texture));
158+
}
159+
}
160+
),
161+
);
162+
}
163+
));
125164
texture_container.append(&paste_texture_btn);
126165
container.append(&texture_container);
127166

examples/confetti_snapshot_animation/confetti_widget/mod.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@ impl ConfettiWidget {
2727
let frame_clock = self.frame_clock().unwrap();
2828
exp.init_time(&frame_clock, duration);
2929

30-
frame_clock.connect_update(clone!(@weak self as this, @weak exp => move |clock| {
31-
match exp.update(clock) {
32-
ControlFlow::Continue => {
33-
this.queue_draw();
34-
},
35-
ControlFlow::Break => {
36-
this.imp().explosions.borrow_mut().remove(&exp);
37-
clock.end_updating();
30+
frame_clock.connect_update(clone!(
31+
#[weak(rename_to = this)]
32+
self,
33+
#[weak]
34+
exp,
35+
move |clock| {
36+
match exp.update(clock) {
37+
ControlFlow::Continue => {
38+
this.queue_draw();
39+
}
40+
ControlFlow::Break => {
41+
this.imp().explosions.borrow_mut().remove(&exp);
42+
clock.end_updating();
43+
}
3844
}
3945
}
40-
}));
46+
));
4147
self.imp().explosions.borrow_mut().insert(exp.clone());
4248
frame_clock.begin_updating();
4349
exp

0 commit comments

Comments
 (0)