Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 'Contex Menu' demo to Rust #32

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions demos/Context Menu/code.rs
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);
}