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 Vala #34

Merged
merged 2 commits 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
35 changes: 35 additions & 0 deletions demos/Context Menu/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main() {
var box_menu_parent = (Gtk.Box) workbench.builder.get_object(
"box_menu_parent"
);
var label_emoji = (Gtk.Label) workbench.builder.get_object(
"label_emoji"
);
var gesture_click = (Gtk.GestureClick) workbench.builder.get_object(
"gesture_click"
);
var popover_menu = (Gtk.PopoverMenu) workbench.builder.get_object(
"popover_menu"
);

gesture_click.pressed.connect((gesture, n_press, x, y) => {
var position = Gdk.Rectangle() { x = (int) x, y = (int) y };
popover_menu.set_pointing_to(position);
popover_menu.popup();
});

var mood_group = new SimpleActionGroup();
box_menu_parent.insert_action_group("mood", mood_group);

var emoji_action = new SimpleAction(
"emoji",
new GLib.VariantType("s")
);

emoji_action.activate.connect((action, parameter) => {
label_emoji.label = parameter.get_string();
});
mood_group.add_action(emoji_action);
}