Skip to content

Commit

Permalink
Use action parameters, improve layout
Browse files Browse the repository at this point in the history
  • Loading branch information
UrtsiSantsi committed Dec 14, 2023
1 parent c54824c commit 74ac8fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
19 changes: 11 additions & 8 deletions demos/Context Menu/main.blp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ using Adw 1;

Adw.StatusPage demo {
title: _("Context Menu");
description: _("Display context menu");
description: _("Offer contextual actions");

Box {
orientation: vertical;

Box box_menu_parent {
orientation: vertical;
height-request: 140;
halign: center;
width-request: 300;
height-request: 200;

styles [
"card",
]

Label label_emoji {
margin-top: 12;
valign: fill;
label: "😀";
vexpand: true;

styles [
"title-1",
]
}

Label {
margin-top: 12;
label: _("Right click on me");

styles [
Expand Down Expand Up @@ -62,16 +62,19 @@ Adw.StatusPage demo {
menu context_menu {
item {
label: _("Happy");
action: "mood.happy";
action: "mood.emoji";
target: "😀";
}

item {
label: _("Start Struck");
action: "mood.start-struck";
action: "mood.emoji";
target: "🤩";
}

item {
label: _("Partying");
action: "mood.partying";
action: "mood.emoji";
target: "🥳";
}
}
36 changes: 9 additions & 27 deletions demos/Context Menu/main.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
import Gdk from "gi://Gdk";
import GLib from "gi://GLib";
import Gio from "gi://Gio";

const box_menu_parent = workbench.builder.get_object("box_menu_parent");
const label_emoji = workbench.builder.get_object("label_emoji");
const gesture_click = workbench.builder.get_object("gesture_click");
const popover_menu = workbench.builder.get_object("popover_menu");

gesture_click.connect("pressed", (_, __, x, y) => {
const position = new Gdk.Rectangle();
position.x = x;
position.y = y;
gesture_click.connect("pressed", (_self, _n_press, x, y) => {
const position = new Gdk.Rectangle({ x: x, y: y });
popover_menu.set_pointing_to(position);
popover_menu.popup();
});

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

const happy_action = new Gio.SimpleAction({
name: "happy",
const emoji_action = new Gio.SimpleAction({
name: "emoji",
parameter_type: new GLib.VariantType("s"),
});

happy_action.connect("activate", () => {
label_emoji.label = "😀";
emoji_action.connect("activate", (_action, parameter) => {
label_emoji.label = parameter.deepUnpack().toString();
});
mood_group.add_action(happy_action);

const start_struck_action = new Gio.SimpleAction({
name: "start-struck",
});

start_struck_action.connect("activate", () => {
label_emoji.label = "🤩";
});
mood_group.add_action(start_struck_action);

const partying_action = new Gio.SimpleAction({
name: "partying",
});

partying_action.connect("activate", () => {
label_emoji.label = "🥳";
});
mood_group.add_action(partying_action);
mood_group.add_action(emoji_action);

0 comments on commit 74ac8fb

Please sign in to comment.