This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
main.rs
62 lines (50 loc) · 1.88 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use gtk::prelude::*;
use gtk::{gdk, gio};
fn main() {
let application = gtk::Application::new(Some("com.github.css"), gio::ApplicationFlags::empty());
application.connect_startup(|app| {
// The CSS "magic" happens here.
let provider = gtk::CssProvider::new();
// Load the CSS file
let style = include_bytes!("style.css");
provider.load_from_data(style).expect("Failed to load CSS");
// We give the CssProvided to the default screen so the CSS rules we added
// can be applied to our window.
gtk::StyleContext::add_provider_for_screen(
&gdk::Screen::default().expect("Error initializing gtk css provider."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
// We build the application UI.
build_ui(app);
});
application.run();
}
fn build_ui(application: >k::Application) {
let window = gtk::ApplicationWindow::new(application);
window.set_title("CSS");
window.set_position(gtk::WindowPosition::Center);
// The container container.
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
let label = gtk::Button::with_label("hover me!");
// We need to name it in order to be able to use its name as a CSS label to
// apply CSS on it.
label.set_widget_name("label1");
let entry = gtk::Entry::new();
// We need to name it in order to apply CSS on it.
entry.set_widget_name("entry1");
entry.set_text("Some text");
let combo = gtk::ComboBoxText::new();
combo.append_text("option 1");
combo.append_text("option 2");
combo.append_text("option 3");
combo.set_active(Some(0));
vbox.add(&label);
vbox.add(&entry);
vbox.add(&combo);
// Then we add the container inside our window.
window.add(&vbox);
application.connect_activate(move |_| {
window.show_all();
});
}