1
0
Fork 0
fgdata/Nasal/canvas/gui/widgets/PopupMenu.nas
2023-01-11 10:57:42 +00:00

61 lines
1.3 KiB
Text

# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
# SPDX-License-Identifier: GPL-2.0-or-later
gui.widgets.PopupMenu = {
new: func(parent, style, cfg)
{
var cfg = Config.new(cfg);
var m = gui.Widget.new(gui.widgets.Button);
m._focus_policy = m.StrongFocus;
m._flat = cfg.get("flat", 0);
m._menu = nil;
m._setView( style.createWidget(parent, cfg.get("type", "button"), cfg) );
return m;
},
setText: func(text)
{
if( me._view != nil )
me._view.setText(me, text);
return me;
},
show: func()
{
# check if enabled
},
menu: func()
{
if (!me._menu) {
# FIXME pass style
me.menu = gui.widgets.Menu.new(cfg);
}
return me._menu;
},
# convenience helper to add simple items
addMenuItem: func(text, value) {
# FIXME pass style
me.menu().append(gui.widgets.MenuItem.new());
},
# helper to set the current item by passing in
# a value of an item
setCurrentByValue: func(value) {
},
# protected:
_setView: func(view)
{
call(gui.Widget._setView, [view], me);
var el = view._root;
el.addEventListener("mousedown", func if( me._enabled ) me.setDown(1));
el.addEventListener("mouseup", func if( me._enabled ) me.setDown(0));
el.addEventListener("mouseleave",func me.setDown(0));
}
};