Skip to content

Commit ef50ef8

Browse files
felinirabilelmoussaoui
authored andcommitted
examples: Add example for About Dialog
1 parent f2a530f commit ef50ef8

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

examples/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ default = []
3232
femtovg-support = ["epoxy", "femtovg", "glow", "libloading"]
3333
glium-support = ["glium", "epoxy", "libloading"]
3434
tokio = ["dep:tokio", "async-channel", "reqwest", "serde"]
35+
v4_6 = ["gtk/v4_6"]
3536
v4_10 = ["gtk/v4_10"]
3637
v4_12 = ["gtk/v4_12"]
3738
v4_14 = ["gtk/v4_14"]
3839

40+
[[bin]]
41+
name = "about_dialog"
42+
path = "about_dialog/main.rs"
43+
required-features = ["v4_6"]
44+
3945
[[bin]]
4046
name = "basics"
4147
path = "basics/main.rs"

examples/about_dialog/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Basics
2+
3+
This example demonstrates the usage of `AboutDialog`.
4+
5+
![Screenshot](screenshot.png)

examples/about_dialog/gtk-rs.svg

Lines changed: 2 additions & 0 deletions
Loading

examples/about_dialog/main.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use gtk::gdk;
2+
use gtk::glib;
3+
use gtk::prelude::*;
4+
5+
static LOGO_SVG: &[u8] = include_bytes!("gtk-rs.svg");
6+
7+
fn main() {
8+
let app = gtk::Application::builder()
9+
.application_id("com.github.gtk-rs.examples.basic")
10+
.build();
11+
12+
app.connect_activate(|app| {
13+
let button = gtk::Button::builder()
14+
.label("Show About Dialog")
15+
.margin_top(24)
16+
.margin_bottom(24)
17+
.margin_start(24)
18+
.margin_end(24)
19+
.build();
20+
21+
let window = gtk::ApplicationWindow::builder()
22+
.application(app)
23+
.title("Example")
24+
.child(&button)
25+
.build();
26+
27+
let bytes = glib::Bytes::from_static(LOGO_SVG);
28+
let logo = gdk::Texture::from_bytes(&bytes).expect("gtk-rs.svg to load");
29+
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+
}));
44+
45+
window.present();
46+
});
47+
48+
app.run();
49+
}

examples/about_dialog/screenshot.png

22 KB
Loading

0 commit comments

Comments
 (0)