-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port 'Contex Menu' demo to Rust (#32)
- Loading branch information
1 parent
42188ab
commit 0f45df8
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::workbench; | ||
use gtk::gdk; | ||
use gtk::gio; | ||
use gtk::glib; | ||
use gtk::prelude::*; | ||
|
||
pub fn main() { | ||
let box_menu_parent: gtk::Box = workbench::builder().object("box_menu_parent").unwrap(); | ||
let label_emoji: gtk::Label = workbench::builder().object("label_emoji").unwrap(); | ||
let gesture_click: gtk::GestureClick = workbench::builder().object("gesture_click").unwrap(); | ||
let popover_menu: gtk::PopoverMenu = workbench::builder().object("popover_menu").unwrap(); | ||
|
||
gesture_click.connect_pressed(move |_gesture, _n_press, x, y| { | ||
let position = gdk::Rectangle::new(x as i32, y as i32, 0, 0); | ||
popover_menu.set_pointing_to(Some(&position)); | ||
popover_menu.popup(); | ||
}); | ||
|
||
let mood_group = gio::SimpleActionGroup::new(); | ||
box_menu_parent.insert_action_group("mood", Some(&mood_group)); | ||
|
||
let emoji_action = gio::SimpleAction::new("emoji", Some(&glib::VariantType::new("s").unwrap())); | ||
|
||
emoji_action.connect_activate( | ||
glib::clone!(@weak label_emoji => move |_action, parameter| { | ||
label_emoji.set_label(parameter.unwrap().get::<String>().unwrap().as_str()); | ||
}), | ||
); | ||
mood_group.add_action(&emoji_action); | ||
} |