Skip to content

Commit

Permalink
Merge pull request #1773 from sdroege/clone-new
Browse files Browse the repository at this point in the history
Update to new clone! macro syntax
  • Loading branch information
sdroege authored Jun 17, 2024
2 parents f7ff7a0 + bc99862 commit f0e1d9e
Show file tree
Hide file tree
Showing 27 changed files with 542 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows-msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Install pkgconfig-lite
run: |
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
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
Expand-Archive /pkg_config_lite.zip -DestinationPath C:\
ls C:\
ls C:\pkg-config-lite-0.28-1
Expand Down
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions examples/about_dialog/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ fn main() {
let bytes = glib::Bytes::from_static(LOGO_SVG);
let logo = gdk::Texture::from_bytes(&bytes).expect("gtk-rs.svg to load");

button.connect_clicked(glib::clone!(@weak window => move |_| {
let dialog = gtk::AboutDialog::builder()
.transient_for(&window)
.modal(true)
.program_name("About Dialog Example")
.version("0.1.0")
.website("https://gtk-rs.org")
.license_type(gtk::License::MitX11)
.authors(["Author 1", "Author 2"])
.logo(&logo)
.build();

dialog.present();
}));
button.connect_clicked(glib::clone!(
#[weak]
window,
move |_| {
let dialog = gtk::AboutDialog::builder()
.transient_for(&window)
.modal(true)
.program_name("About Dialog Example")
.version("0.1.0")
.website("https://gtk-rs.org")
.license_type(gtk::License::MitX11)
.authors(["Author 1", "Author 2"])
.logo(&logo)
.build();

dialog.present();
}
));

window.present();
});
Expand Down
83 changes: 61 additions & 22 deletions examples/clipboard/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,42 @@ fn build_ui(application: &gtk::Application) {
text_container.append(&from_entry);

let copy_btn = gtk::Button::with_label("Copy");
copy_btn.connect_clicked(clone!(@weak clipboard, @weak from_entry => move |_btn| {
let text = from_entry.text();
clipboard.set_text(&text);
}));
copy_btn.connect_clicked(clone!(
#[weak]
clipboard,
#[weak]
from_entry,
move |_btn| {
let text = from_entry.text();
clipboard.set_text(&text);
}
));
text_container.append(&copy_btn);

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

let paste_btn = gtk::Button::with_label("Paste");
paste_btn.connect_clicked(clone!(@weak clipboard, @weak into_entry => move |_btn| {
clipboard.read_text_async(gio::Cancellable::NONE, clone!(@weak into_entry => move|res| {
if let Ok(Some(text)) = res {
into_entry.set_text(&text);
}
}));
}));
paste_btn.connect_clicked(clone!(
#[weak]
clipboard,
#[weak]
into_entry,
move |_btn| {
clipboard.read_text_async(
gio::Cancellable::NONE,
clone!(
#[weak]
into_entry,
move |res| {
if let Ok(Some(text)) = res {
into_entry.set_text(&text);
}
}
),
);
}
));
text_container.append(&paste_btn);
container.append(&text_container);

Expand Down Expand Up @@ -100,10 +119,19 @@ fn build_ui(application: &gtk::Application) {
.label("Copy")
.valign(gtk::Align::Center)
.build();
copy_texture_btn.connect_clicked(clone!(@weak clipboard, @weak image_from => move |_btn| {
let texture = image_from.paintable().and_downcast::<gdk::Texture>().unwrap();
clipboard.set_texture(&texture);
}));
copy_texture_btn.connect_clicked(clone!(
#[weak]
clipboard,
#[weak]
image_from,
move |_btn| {
let texture = image_from
.paintable()
.and_downcast::<gdk::Texture>()
.unwrap();
clipboard.set_texture(&texture);
}
));
texture_container.append(&copy_texture_btn);

let image_into = gtk::Image::builder()
Expand All @@ -115,13 +143,24 @@ fn build_ui(application: &gtk::Application) {
.label("Paste")
.valign(gtk::Align::Center)
.build();
paste_texture_btn.connect_clicked(clone!(@weak clipboard => move |_btn| {
clipboard.read_texture_async(gio::Cancellable::NONE, clone!(@weak image_into => move |res| {
if let Ok(Some(texture)) = res {
image_into.set_paintable(Some(&texture));
}
}));
}));
paste_texture_btn.connect_clicked(clone!(
#[weak]
clipboard,
move |_btn| {
clipboard.read_texture_async(
gio::Cancellable::NONE,
clone!(
#[weak]
image_into,
move |res| {
if let Ok(Some(texture)) = res {
image_into.set_paintable(Some(&texture));
}
}
),
);
}
));
texture_container.append(&paste_texture_btn);
container.append(&texture_container);

Expand Down
24 changes: 15 additions & 9 deletions examples/confetti_snapshot_animation/confetti_widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ impl ConfettiWidget {
let frame_clock = self.frame_clock().unwrap();
exp.init_time(&frame_clock, duration);

frame_clock.connect_update(clone!(@weak self as this, @weak exp => move |clock| {
match exp.update(clock) {
ControlFlow::Continue => {
this.queue_draw();
},
ControlFlow::Break => {
this.imp().explosions.borrow_mut().remove(&exp);
clock.end_updating();
frame_clock.connect_update(clone!(
#[weak(rename_to = this)]
self,
#[weak]
exp,
move |clock| {
match exp.update(clock) {
ControlFlow::Continue => {
this.queue_draw();
}
ControlFlow::Break => {
this.imp().explosions.borrow_mut().remove(&exp);
clock.end_updating();
}
}
}
}));
));
self.imp().explosions.borrow_mut().insert(exp.clone());
frame_clock.begin_updating();
exp
Expand Down
Loading

0 comments on commit f0e1d9e

Please sign in to comment.