1
0
Fork 0

Load example UI

This commit is contained in:
Alex Kotov 2021-12-05 23:23:44 +05:00
parent f13d992163
commit dec7747a26
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 13 additions and 172 deletions

View File

@ -1,124 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="show_menubar">False</property>
<child type="titlebar">
<placeholder/>
</child>
<object class="GtkApplicationWindow" id="app_window">
<property name="title">My GTK App</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tab_pos">left</property>
<property name="show_border">False</property>
<child>
<placeholder/>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">page 1</property>
</object>
<packing>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">page 2</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">page 3</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<object class="GtkButton" id="button">
<property name="label">Press me!</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
</object>
</child>
</object>

View File

@ -1,12 +1,8 @@
use crate::glib::clone;
use std::cell::Cell;
use std::rc::Rc;
use gtk::prelude::*;
use gtk::*;
static ID: &str = "com.causa-arcana.polytree.polytree-session";
static UI: &str = include_str!("../main.glade");
fn main() {
let app = Application::builder().application_id(ID).build();
@ -17,53 +13,8 @@ fn main() {
}
fn build_ui(app: &Application) {
let window = ApplicationWindow::builder()
.application(app)
.title("Hello, World!")
.build();
let label = Label::builder()
.label("0")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
let button1 = Button::builder()
.label("Increase")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
let button2 = Button::builder()
.label("Decrease")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
let number = Rc::new(Cell::new(0));
button1.connect_clicked(clone!(@weak number, @weak label => move |_| {
number.set(number.get() + 1);
label.set_label(&number.get().to_string());
}));
button2.connect_clicked(clone!(@weak label => move |_| {
number.set(number.get() - 1);
label.set_label(&number.get().to_string());
}));
let box_ = Box::new(Orientation::Vertical, 0);
box_.append(&label);
box_.append(&button1);
box_.append(&button2);
window.set_child(Some(&box_));
window.present();
let builder = Builder::from_string(UI);
let app_window: ApplicationWindow = builder.object("app_window").unwrap();
app_window.set_application(Some(app));
app_window.present();
}