summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2016-10-23 21:27:58 +0200
committerJustin Worthe <justin.worthe@gmail.com>2016-10-23 21:27:58 +0200
commit494e89fd10511e1830ac76d0c0309f097a185774 (patch)
tree5c285d8699a8b86e49dc072ea68c0ad07ae32902 /src
parent3b264ac05a532828e3ce8c035249903ca0a51ecd (diff)
Added changing of mutable state from dropdown
Diffstat (limited to 'src')
-rw-r--r--src/gui.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/gui.rs b/src/gui.rs
index bae29c2..c48c45d 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -1,5 +1,6 @@
use gtk;
use gtk::prelude::*;
+use std::cell::Cell;
const GUI_XML: &'static str = r#"
<interface>
@@ -16,7 +17,8 @@ const GUI_XML: &'static str = r#"
pub fn start_gui() -> Result<(), String> {
let pa = try!(::audio::init().map_err(|e| e.to_string()));
let microphones = try!(::audio::get_device_list(&pa).map_err(|e| e.to_string()));
-
+ let selected_mic: Cell<Option<u32>> = Cell::new(None);
+
try!(gtk::init().map_err(|_| "Failed to initialize GTK."));
let gtk_builder = try!(create_window(microphones));
@@ -25,10 +27,9 @@ pub fn start_gui() -> Result<(), String> {
gtk_builder.get_object("dropdown")
.ok_or("GUI does not contain an object with id 'dropdown'")
);
- dropdown.connect_changed(|ref dropdown| {
- println!("{}", dropdown.get_active_id().unwrap());
- //This callback can now mutate state on the same level as our
- //other logic to get the list of microphones
+ dropdown.connect_changed(move |dropdown: &gtk::ComboBoxText| {
+ selected_mic.set(dropdown.get_active_id().and_then(|id| id.parse().ok()));
+ println!("{}", selected_mic.get().unwrap());
});
gtk::main();