2013-07-27 09:54:41 +00:00
|
|
|
gui.widgets.Button = {
|
|
|
|
new: func(parent, style, cfg)
|
|
|
|
{
|
|
|
|
var cfg = Config.new(cfg);
|
|
|
|
var m = gui.Widget.new(gui.widgets.Button);
|
|
|
|
m._focus_policy = m.StrongFocus;
|
|
|
|
m._active = 0;
|
|
|
|
m._flat = cfg.get("flat", 0);
|
|
|
|
|
|
|
|
if( style != nil and !m._flat )
|
2014-06-08 22:37:14 +00:00
|
|
|
m._setView( style.createWidget(parent, "button", cfg) );
|
2014-06-01 10:25:34 +00:00
|
|
|
|
2013-07-27 09:54:41 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
setText: func(text)
|
|
|
|
{
|
2014-06-08 22:37:14 +00:00
|
|
|
me._view.setText(me, text);
|
2013-07-27 09:54:41 +00:00
|
|
|
return me;
|
|
|
|
},
|
|
|
|
setActive: func
|
|
|
|
{
|
|
|
|
if( me._active )
|
|
|
|
return me;
|
|
|
|
|
|
|
|
me._active = 1;
|
|
|
|
me._onStateChange();
|
|
|
|
return me;
|
|
|
|
},
|
|
|
|
clearActive: func
|
|
|
|
{
|
|
|
|
if( !me._active )
|
|
|
|
return me;
|
|
|
|
|
|
|
|
me._active = 0;
|
|
|
|
me._onStateChange();
|
|
|
|
return me;
|
|
|
|
},
|
|
|
|
onClick: func {},
|
|
|
|
# protected:
|
|
|
|
_onStateChange: func
|
|
|
|
{
|
2014-06-08 22:37:14 +00:00
|
|
|
if( me._view != nil )
|
|
|
|
me._view.update(me);
|
2013-07-27 09:54:41 +00:00
|
|
|
},
|
2014-06-08 22:37:14 +00:00
|
|
|
_setView: func(view)
|
2013-07-27 09:54:41 +00:00
|
|
|
{
|
2014-06-08 22:37:14 +00:00
|
|
|
var el = view._root;
|
2013-07-27 09:54:41 +00:00
|
|
|
el.addEventListener("mousedown", func me.setActive());
|
|
|
|
el.addEventListener("mouseup", func me.clearActive());
|
|
|
|
|
|
|
|
# Use 'call' to ensure 'me' is not set and can be used in the closure of
|
|
|
|
# custom callbacks. TODO pass 'me' as argument?
|
|
|
|
el.addEventListener("click", func call(me.onClick));
|
|
|
|
|
|
|
|
el.addEventListener("mouseleave",func me.clearActive());
|
|
|
|
el.addEventListener("drag", func(e) e.stopPropagation());
|
|
|
|
|
2014-06-08 22:37:14 +00:00
|
|
|
call(gui.Widget._setView, [view], me);
|
2013-07-27 09:54:41 +00:00
|
|
|
}
|
|
|
|
};
|