Add more Nasal skeleton for new UI objects
This commit is contained in:
parent
82cb79feb3
commit
459dea77e5
11 changed files with 257 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: (C) 2016 Thomas Geymayer
|
||||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
gui.widgets.Button = {
|
||||
new: func(parent, style, cfg)
|
||||
{
|
||||
|
|
61
Nasal/canvas/gui/widgets/Dial.nas
Normal file
61
Nasal/canvas/gui/widgets/Dial.nas
Normal file
|
@ -0,0 +1,61 @@
|
|||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
gui.widgets.Dial = {
|
||||
new: func(parent, style, cfg)
|
||||
{
|
||||
var cfg = Config.new(cfg);
|
||||
var m = gui.Widget.new(gui.widgets.Dial);
|
||||
m._focus_policy = m.StrongFocus;
|
||||
m._down = 0;
|
||||
m._minValue = 0;
|
||||
m._maxValue = cfg.get("max-value", 100);
|
||||
m._value = 50;
|
||||
|
||||
m._wraps = cfg.get("wrap", 0);
|
||||
m._pageStep = cfg.get("page-step", 0);
|
||||
m._numTicks = cfg.get("tick-count", 0);
|
||||
m._tickStyle = cfg.get("ticks-style", 0);
|
||||
|
||||
# todo : optional value display in the center
|
||||
|
||||
if( style != nil ) {
|
||||
m._setView( style.createWidget(parent, cfg.get("type", "slider"), cfg) );
|
||||
m._view.updateRanges(m._minValue, m._maxValue, m._numTicks);
|
||||
}
|
||||
|
||||
return m;
|
||||
},
|
||||
|
||||
setValue: func(val)
|
||||
{
|
||||
if( me._view != nil ) {
|
||||
me._view.setNormValue(me._normValue());
|
||||
}
|
||||
return me;
|
||||
},
|
||||
|
||||
|
||||
|
||||
# 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("click", func if( me._enabled ) me.toggle());
|
||||
|
||||
# el.addEventListener("mouseleave",func me.setDown(0));
|
||||
# el.addEventListener("drag", func(e) e.stopPropagation());
|
||||
},
|
||||
|
||||
# return value as its normalised equivalent
|
||||
_normValue: func
|
||||
{
|
||||
var range = me._maxValue - me._minValue;
|
||||
var v = math.clamp(me._value, me._minValue, me._maxValue) - me._minValue;
|
||||
return v / range;
|
||||
}
|
||||
};
|
|
@ -2,7 +2,7 @@
|
|||
# and optional checkbox / label (usuallt at the top / left)
|
||||
# to enable / disable it
|
||||
|
||||
# Copyright (C) 2022 James Turner
|
||||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
gui.widgets.Label = {
|
||||
new: func(parent, style, cfg)
|
||||
{
|
||||
|
|
30
Nasal/canvas/gui/widgets/Menu.nas
Normal file
30
Nasal/canvas/gui/widgets/Menu.nas
Normal file
|
@ -0,0 +1,30 @@
|
|||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
gui.widgets.Menu = {
|
||||
|
||||
new: func(parent, style, cfg)
|
||||
{
|
||||
var cfg = Config.new(cfg);
|
||||
var m = gui.Widget.new(gui.widgets.Menu);
|
||||
m._focus_policy = m.StrongFocus;
|
||||
|
||||
# m._flat = cfg.get("flat", 0);
|
||||
# m._isDefault = cfg.get("default", 0);
|
||||
# m._destructive = cfg.get("destructive", 0);
|
||||
|
||||
m._setView( style.createWidget(parent, cfg.get("type", "menu"), cfg) );
|
||||
return m;
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
# protected:
|
||||
_setView: func(view)
|
||||
{
|
||||
call(gui.Widget._setView, [view], me);
|
||||
var el = view._root;
|
||||
}
|
||||
};
|
||||
|
54
Nasal/canvas/gui/widgets/PopupMenu.nas
Normal file
54
Nasal/canvas/gui/widgets/PopupMenu.nas
Normal file
|
@ -0,0 +1,54 @@
|
|||
# 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());
|
||||
},
|
||||
|
||||
# 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));
|
||||
}
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
# RadioButton.nas : radio button, and group helper
|
||||
# to manage updating checked state conherently
|
||||
# Copyright (C) 2022 James Turner
|
||||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
gui.widgets.RadioButton = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Rule.nas : horizontal or vertical dividing line,
|
||||
# optionally with a text label, eg to name a section
|
||||
# Copyright (C) 2022 James Turner
|
||||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
# Slider.nas : show a user-draggable slider
|
||||
# with optional tick marks and value display
|
||||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
gui.widgets.Slider = {
|
||||
new: func(parent, style, cfg)
|
||||
{
|
||||
|
@ -6,11 +11,16 @@ gui.widgets.Slider = {
|
|||
m._focus_policy = m.StrongFocus;
|
||||
m._down = 0;
|
||||
m._minValue = 0;
|
||||
m._maxValue = 100;
|
||||
m._maxValue = cfg.get("max-value", 100);
|
||||
m._value = 50;
|
||||
m._pageStep = 10;
|
||||
m._numTicks = 10;
|
||||
m._pageStep = cfg.get("page-step", 0);
|
||||
m._numTicks = cfg.get("tick-count", 0);
|
||||
|
||||
m._tickStyle = cfg.get("ticks-style", 0);
|
||||
m._valueDisplayStyle = cfg.get("value-style", 0);
|
||||
|
||||
# TODO : select where value is shown
|
||||
# TODO : select where tick marks are shown
|
||||
|
||||
if( style != nil ) {
|
||||
m._setView( style.createWidget(parent, cfg.get("type", "slider"), cfg) );
|
||||
|
|
60
Nasal/gui/MenuBar.nas
Normal file
60
Nasal/gui/MenuBar.nas
Normal file
|
@ -0,0 +1,60 @@
|
|||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
||||
var GUIMenuItem = {
|
||||
|
||||
aboutToShow: func() {
|
||||
|
||||
},
|
||||
|
||||
# return a Canvas object (group) of the contents
|
||||
show: func(viewParent) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var GUIMenu = {
|
||||
|
||||
aboutToShow: func() {
|
||||
|
||||
},
|
||||
|
||||
# return a Canvas object (group) of the contents
|
||||
show: func(viewParent) {
|
||||
# loop over children
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var GUIMenuBar = {
|
||||
aboutToShow: func() {
|
||||
|
||||
},
|
||||
|
||||
# return a Canvas object (group) of the contents
|
||||
show: func(viewParent) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
# this is the callback function invoked by C++ to build Nasal peers
|
||||
# for the C++ menu objects.
|
||||
var _createMenuObject = func(type)
|
||||
{
|
||||
if (type == "menubar") {
|
||||
|
||||
} else if (type == "menuitem") {
|
||||
|
||||
} else if (type == "seperator") {
|
||||
|
||||
} else if (type == "menu") {
|
||||
# do we need to distuinguish submenus here:
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
logprint(LOG_INFO, "Did load GUI menubar");
|
|
@ -1,5 +1,5 @@
|
|||
# XML Dialog - XML dialog object without using PUI
|
||||
# Copyright (C) 2022 James Turner
|
||||
# SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# alias this module to keep things somewhat readable
|
||||
|
@ -405,6 +405,30 @@ var XMLSlider =
|
|||
}
|
||||
};
|
||||
|
||||
var XMLDial =
|
||||
{
|
||||
init: func(objectProps)
|
||||
{
|
||||
logprint(LOG_INFO, "Init of XMLDial");
|
||||
|
||||
|
||||
},
|
||||
|
||||
show: func(viewParent)
|
||||
{
|
||||
me._view = cwidgets.Dial.new(viewParent, canvas.style, {});
|
||||
me._layout = me._view;
|
||||
me._applyLayoutConfig();
|
||||
me.update();
|
||||
return me._view;
|
||||
},
|
||||
|
||||
update: func()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
var XMLTextEdit =
|
||||
{
|
||||
init: func(objectProps)
|
||||
|
@ -497,6 +521,10 @@ var _createCompatObject = func(type)
|
|||
widget = XMLSlider;
|
||||
}
|
||||
|
||||
if (type == "dial") {
|
||||
widget = XMLDial;
|
||||
}
|
||||
|
||||
if (type == "group") {
|
||||
widget = XMLGroup;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue