1
return function(parent, dir)
3
local lgi = require 'lgi'
6
local function create_menu(depth, tearoff)
7
if depth < 1 then return nil end
8
local menu = Gtk.Menu()
10
menu:append(Gtk.TearoffMenuItem { visible = true })
14
local item = Gtk.RadioMenuItem {
16
label = ("item %2d - %d"):format(depth, i),
17
submenu = create_menu(depth - 1, true),
20
if not group then group = item end
26
local window = Gtk.Window {
29
orientation = 'VERTICAL',
33
label = "test\nline2",
35
submenu = create_menu(2, true),
40
submenu = create_menu(3),
45
submenu = create_menu(4, true),
49
orientation = 'VERTICAL',
64
function window.child.close:on_clicked()
68
function window.child.flip:on_clicked()
69
local menubar = window.child.menubar
70
local orientation = menubar.parent.orientation
71
orientation = (orientation == 'HORIZONTAL'
72
and 'VERTICAL' or 'HORIZONTAL')
73
menubar.parent.orientation = orientation
74
menubar.pack_direction = (orientation == 'VERTICAL'
85
[[There are several widgets involved in displaying menus. ]],
86
[[The Gtk.MenuBar widget is a menu bar, which normally appears ]],
87
[[horizontally at the top of an application, but can also be ]],
88
[[layed out vertically. The Gtk.Menu widget is the actual menu ]],
89
[[that pops up. Both Gtk.MenuBar and Gtk.Menu are subclasses ]],
90
[[of Gtk.MenuShell; a Gtk.MenuShell contains menu items (Gtk.MenuItem). ]],
91
[[Each menu item contains text and/or images and can be selected ]],
94
[[There are several kinds of menu item, including plain ]],
95
[[Gtk.MenuItem, Gtk.CheckMenuItem which can be checked/unchecked, ]],
96
[[Gtk.RadioMenuItem which is a check menu item that's in a mutually ]],
97
[[exclusive group, Gtk.SeparatorMenuItem which is a separator bar, ]],
98
[[Gtk.TearoffMenuItem which allows a Gtk.Menu to be torn off, ]],
99
[[and Gtk.ImageMenuItem which can place a Gtk.Image or other widget ]],
100
[[next to the menu text.
102
[[A Gtk.MenuItem can have a submenu, which is simply a Gtk.Menu ]],
103
[[to pop up when the menu item is selected. Typically, all menu ]],
104
[[items in a menu bar have submenus.
106
[[Gtk.UIManager provides a higher-level interface for creating ]],
107
[[menu bars and menus; while you can construct menus manually, ]],
108
[[most people don't do that. There's a separate demo for ]],