1
0
Fork 0

Gui: add some helpers:

- clear() function on LineEdit
 - setDefault/Destructive flags on Button
 - check if focus is set on a Widget
This commit is contained in:
James Turner 2022-06-30 12:39:41 +02:00
parent fe7c87b21a
commit 3965f216e5
3 changed files with 33 additions and 0 deletions

View file

@ -108,6 +108,12 @@ gui.Widget = {
return me;
},
#
hasActiveFocus:func
{
return me.getCanvas()._focused_widget == me;
},
#
listen: func(type, cb)
{
me._view._root.addEventListener("cb." ~ type, cb);

View file

@ -7,6 +7,8 @@ gui.widgets.Button = {
m._down = 0;
m._checkable = 0;
m._flat = cfg.get("flat", 0);
m._isDefault = cfg.get("default", 0);
m._destructive = cfg.get("destructive", 0);
if( style != nil and !m._flat )
m._setView( style.createWidget(parent, cfg.get("type", "button"), cfg) );
@ -54,6 +56,16 @@ gui.widgets.Button = {
return me;
},
setDefault: func(isDefault)
{
me._isDefault = isDefault;
return me;
},
setDestructive: func(isDestructive)
{
me._destructive = isDestructive;
return me;
},
# protected:
_setView: func(view)
{

View file

@ -19,6 +19,11 @@ gui.widgets.LineEdit = {
},
setText: func(text)
{
if (text == nil) {
me.clear();
return me;
}
me._text = utf8.substr(text, 0, me._max_length);
me._cursor = utf8.size(me._text);
me._selection_start = me._cursor;
@ -29,6 +34,16 @@ gui.widgets.LineEdit = {
return me;
},
clear: func
{
me._text = "";
me._cursor = 0;
me._selection_start = 0;
me._selection_end = 0;
if( me._view != nil )
me._view.setText(me, "");
},
text: func()
{
return me._text;