I created a simple GUI with a window,entry box ,label and a button using glade and saved as example.glade
in my src
directory of my rust project.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkFixed" id="windows1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="x">182</property>
<property name="y">146</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="box1">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="x">68</property>
<property name="y">45</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="x">321</property>
<property name="y">44</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
My aim is to create a simple rust application which changes label name when a value is entered in the entry box and submitted by a button click.
I tried to write a rust backend using this example with gtk-rs v0.9.2 . This is my code
use gtk::glib;
use gtk::prelude::*;
use gtk::{ApplicationWindow, Builder, Button, MessageDialog};
use std::env::args;
fn build_ui(application: >k::Application) {
let glade_src = include_str!("example.glade");
let builder = Builder::from_string(glade_src);
let window: ApplicationWindow = builder.get_object("window1").expect("Couldn't get window1");
window.show_all();
}
fn main() {
let application = gtk::Application::new(
Some("com.github.gtk-rs.examples.builder_basics"),
Default::default(),
)
.expect("Initialization failed...");
application.connect_activate(build_ui);
application.run(&args().collect::<Vec<_>>());
}
When I run this I get below errors
error: extern crate `glib` is private, and cannot be re-exported (error E0365), consider declaring with `pub`
--> src/main.rs:1:5
|
1 | use gtk::glib;
error[E0599]: no method named `connect_activate` found for struct `Application` in the current scope
--> src/main.rs:23:17
|
23 | application.connect_activate(build_ui);
| ^^^^^^^^^^^^^^^^ method not found in `Application`
error[E0599]: no method named `run` found for struct `Application` in the current scope
--> src/main.rs:25:17
|
25 | application.run(&args().collect::<Vec<_>>());
| ^^^ method not found in `Application`
How do we build GUI with glade, gtk-rs in rust?
#Cargo.toml
[dependencies]
gtk = "0.9.2"