canvas.gui: widget focus fixes and clean up.
This commit is contained in:
parent
f8bbc32d68
commit
bc714fa39c
2 changed files with 21 additions and 12 deletions
|
@ -68,7 +68,6 @@ var Window = {
|
|||
_ghost: ghost,
|
||||
_node: props.wrapNode(ghost._node_ghost),
|
||||
_focused: 0,
|
||||
_focused_widget: nil,
|
||||
_widgets: []
|
||||
};
|
||||
|
||||
|
@ -155,6 +154,8 @@ var Window = {
|
|||
|
||||
canvas_.addPlacement({type: "window", "id": me.get("id")});
|
||||
me['_canvas'] = canvas_;
|
||||
|
||||
canvas_._focused_widget = nil;
|
||||
canvas_.data("focused", me._focused);
|
||||
|
||||
# prevent resizing if canvas is placed from somewhere else
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
gui.Widget = {
|
||||
# enum FocusPolicy:
|
||||
NoFocus: 0,
|
||||
TabFocus: 1,
|
||||
ClickFocus: 2,
|
||||
StrongFocus: 1 + 2,
|
||||
|
||||
#
|
||||
new: func(derived)
|
||||
{
|
||||
|
@ -82,7 +76,7 @@ gui.Widget = {
|
|||
return me;
|
||||
|
||||
var canvas = me.getCanvas();
|
||||
if( canvas._focused_widget != nil )
|
||||
if( canvas._impl['_focused_widget'] != nil )
|
||||
canvas._focused_widget.clearFocus();
|
||||
|
||||
if( !me._enabled )
|
||||
|
@ -118,7 +112,13 @@ gui.Widget = {
|
|||
onRemove: func
|
||||
{
|
||||
if( me._view != nil )
|
||||
{
|
||||
me._view._root.del();
|
||||
me._view = nil;
|
||||
}
|
||||
|
||||
if( me._focused )
|
||||
me.getCanvas()._focused_widget = nil;
|
||||
},
|
||||
# protected:
|
||||
_MAX_SIZE: 32768, # size for "no size-limit"
|
||||
|
@ -148,7 +148,7 @@ gui.Widget = {
|
|||
me._onStateChange();
|
||||
});
|
||||
root.addEventListener("mousedown", func {
|
||||
if( bits.test(me._focus_policy, me.ClickFocus / 2) )
|
||||
if( me._focus_policy & me.ClickFocus )
|
||||
me.setFocus();
|
||||
});
|
||||
root.addEventListener("mouseleave", func {
|
||||
|
@ -159,6 +159,7 @@ gui.Widget = {
|
|||
},
|
||||
_trigger: func(type, data = nil)
|
||||
{
|
||||
if( me._view != nil )
|
||||
me._view._root.dispatchEvent(
|
||||
canvas.CustomEvent.new("cb." ~ type, {detail: data})
|
||||
);
|
||||
|
@ -170,3 +171,10 @@ gui.Widget = {
|
|||
return canvas != nil ? canvas.data("focused") : 0;
|
||||
}
|
||||
};
|
||||
|
||||
# enum FocusPolicy:
|
||||
gui.Widget.NoFocus = 0;
|
||||
gui.Widget.TabFocus = 1;
|
||||
gui.Widget.ClickFocus = 2;
|
||||
gui.Widget.StrongFocus = gui.Widget.TabFocus
|
||||
| gui.Widget.ClickFocus;
|
||||
|
|
Loading…
Reference in a new issue