gtk-rs

Update drawing function of a DrawingArea

杀马特。学长 韩版系。学妹 提交于 2021-01-29 09:23:11
问题 I want to update a cairo drawing inside a DrawingArea. I tried to achieve this by calling DrawingArea::connect_draw(...) with a new function as the parameter. My issue is that it does not replace the original drawing function, but calls both when showing the window. Here is an example extern crate cairo; extern crate gio; extern crate gtk; use gio::prelude::*; use gtk::prelude::*; fn main() { let application = gtk::Application::new(Some("com.example"), Default::default()) .expect(

How to move data into multiple Rust closures?

天涯浪子 提交于 2020-06-27 09:39:26
问题 I have a two widgets in a simple GTK app: extern crate gdk; extern crate gtk; use super::desktop_entry::DesktopEntry; use gdk::enums::key; use gtk::prelude::*; pub fn launch_ui(_desktop_entries: Vec<DesktopEntry>) { gtk::init().unwrap(); let builder = gtk::Builder::new_from_string(include_str!("interface.glade")); let window: gtk::Window = builder.get_object("main_window").unwrap(); let search_entry: gtk::SearchEntry = builder.get_object("search_entry").unwrap(); let list_box: gtk::ListBox =

How to set a variable inside a gtk-rs closure?

本秂侑毒 提交于 2020-01-30 11:16:10
问题 I'm building a markdown app, and I want to keep two copies of the text, one a source text, and the other the TextBuffer with all the correct tags and such. I need to set the contents of this source field inside a closure: buffer.connect_begin_user_action(clone!(source => move |a| { let text = a.get_text(&a.get_start_iter(), &a.get_end_iter(), false).unwrap(); source = text; // error: cannot assign to captured outer variable in an `Fn` closure An alternative might be to set some attribute on

How do I get information from an entry on button click?

青春壹個敷衍的年華 提交于 2020-01-24 02:08:17
问题 I want to get an input from an entry on a button click and display that information when another button is clicked. This gives me an error because the closure takes ownership of my firstname variable, in which I want to store the information. How do I get the information out of the entry and reuse it? // import gtk libs extern crate gio; extern crate gtk; // declare use of gtk use gtk::prelude::*; fn main() { let mut firstname = String::new(); if gtk::init().is_err() { println!("Failed to

Why does cloning data inside a closure not prevent the error “closure may outlive the current function”?

会有一股神秘感。 提交于 2019-12-20 02:15:08
问题 I built a GTK application with gtk-rs. When I build the main window, I want to use some dynamic parameters such as window height. I created a struct which contains all such settings and want to use this as an input parameter for the function building the UI: fn main() { let application = gtk::Application::new(Some("id"), Default::default()) .expect("Initialization failed..."); let config = Config {width: 100., height: 100.}; application.connect_activate(|app| { build_ui(app, config.clone());

Why does cloning data inside a closure not prevent the error “closure may outlive the current function”?

一曲冷凌霜 提交于 2019-12-02 02:05:51
I built a GTK application with gtk-rs. When I build the main window, I want to use some dynamic parameters such as window height. I created a struct which contains all such settings and want to use this as an input parameter for the function building the UI: fn main() { let application = gtk::Application::new(Some("id"), Default::default()) .expect("Initialization failed..."); let config = Config {width: 100., height: 100.}; application.connect_activate(|app| { build_ui(app, config.clone()); }); // Use config further application.run(&args().collect::<Vec<_>>()); } #[derive(Debug, Clone)] pub