From 581f8d163f24648bd57349097e37d962491b272a Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 11 Jan 2023 10:53:52 +0000 Subject: [PATCH] GUI: add PUI combo-box mapping --- Nasal/canvas/gui/widgets/PopupMenu.nas | 7 ++++ Nasal/gui/XMLDialog.nas | 52 ++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Nasal/canvas/gui/widgets/PopupMenu.nas b/Nasal/canvas/gui/widgets/PopupMenu.nas index 51163b302..07b688329 100644 --- a/Nasal/canvas/gui/widgets/PopupMenu.nas +++ b/Nasal/canvas/gui/widgets/PopupMenu.nas @@ -41,6 +41,13 @@ gui.widgets.PopupMenu = { 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) { diff --git a/Nasal/gui/XMLDialog.nas b/Nasal/gui/XMLDialog.nas index 2179cecda..88962cfee 100644 --- a/Nasal/gui/XMLDialog.nas +++ b/Nasal/gui/XMLDialog.nas @@ -383,10 +383,7 @@ var XMLSlider = { init: func(objectProps) { - logprint(LOG_INFO, "Init of XMLSlider"); # TODO: support vertical sliders - - }, show: func(viewParent) @@ -481,10 +478,27 @@ var XMLHRule = { show: func(viewParent) { + var label = me.configValue("label"); + me._view = cwidgets.HorizontalRule.new(viewParent, canvas.style, {}); + if (label) { + me._view.setText(label); + } + me._layout = me._view; me._applyLayoutConfig(); return me._view; + }, + + update: func() + { + # allow label to be updated live + var l = me.value(); + if (l) { + me._view.setText(l); + } + + me._view.setSize(me._size); } }; @@ -499,6 +513,32 @@ var XMLVRule = } }; + +var XMLPopupMenu = +{ + init: func(objectProps) + { + }, + + show: func(viewParent) + { + # do we support a label or is that a seperate widget? + + me._view = cwidgets.PopupMenu.new(viewParent, canvas.style, {}); + me._layout = me._view; + me._applyLayoutConfig(); + me.update(); + return me._view; + }, + + update: func() + { + if (me._view and !me._view.hasActiveFocus()) { + me._view.setCurrentByValue(me.value); + } + } +}; + # this is the callback function invoked by C++ to build Nasal peers # for the C++ objects defined by XML (PUICompatObject). It's primarly # a factory method: once the peer object is created, all other behaviour @@ -545,6 +585,12 @@ var _createCompatObject = func(type) widget = XMLVRule; } + # these are called combos in XML, but are really + # popup menus, no free value entry is possible + if (type == "combo") { + widget = XMLPopupMenu; + } + return gui.xml.Object.new({ parents: [widget, XMLObjectBase] }, type);