1
0
Fork 0

canvas.gui: widget focus fixes and clean up.

This commit is contained in:
Thomas Geymayer 2014-06-29 12:03:47 +02:00
parent f8bbc32d68
commit bc714fa39c
2 changed files with 21 additions and 12 deletions

View file

@ -68,7 +68,6 @@ var Window = {
_ghost: ghost, _ghost: ghost,
_node: props.wrapNode(ghost._node_ghost), _node: props.wrapNode(ghost._node_ghost),
_focused: 0, _focused: 0,
_focused_widget: nil,
_widgets: [] _widgets: []
}; };
@ -155,6 +154,8 @@ var Window = {
canvas_.addPlacement({type: "window", "id": me.get("id")}); canvas_.addPlacement({type: "window", "id": me.get("id")});
me['_canvas'] = canvas_; me['_canvas'] = canvas_;
canvas_._focused_widget = nil;
canvas_.data("focused", me._focused); canvas_.data("focused", me._focused);
# prevent resizing if canvas is placed from somewhere else # prevent resizing if canvas is placed from somewhere else

View file

@ -1,10 +1,4 @@
gui.Widget = { gui.Widget = {
# enum FocusPolicy:
NoFocus: 0,
TabFocus: 1,
ClickFocus: 2,
StrongFocus: 1 + 2,
# #
new: func(derived) new: func(derived)
{ {
@ -82,7 +76,7 @@ gui.Widget = {
return me; return me;
var canvas = me.getCanvas(); var canvas = me.getCanvas();
if( canvas._focused_widget != nil ) if( canvas._impl['_focused_widget'] != nil )
canvas._focused_widget.clearFocus(); canvas._focused_widget.clearFocus();
if( !me._enabled ) if( !me._enabled )
@ -118,7 +112,13 @@ gui.Widget = {
onRemove: func onRemove: func
{ {
if( me._view != nil ) if( me._view != nil )
{
me._view._root.del(); me._view._root.del();
me._view = nil;
}
if( me._focused )
me.getCanvas()._focused_widget = nil;
}, },
# protected: # protected:
_MAX_SIZE: 32768, # size for "no size-limit" _MAX_SIZE: 32768, # size for "no size-limit"
@ -148,7 +148,7 @@ gui.Widget = {
me._onStateChange(); me._onStateChange();
}); });
root.addEventListener("mousedown", func { root.addEventListener("mousedown", func {
if( bits.test(me._focus_policy, me.ClickFocus / 2) ) if( me._focus_policy & me.ClickFocus )
me.setFocus(); me.setFocus();
}); });
root.addEventListener("mouseleave", func { root.addEventListener("mouseleave", func {
@ -159,9 +159,10 @@ gui.Widget = {
}, },
_trigger: func(type, data = nil) _trigger: func(type, data = nil)
{ {
me._view._root.dispatchEvent( if( me._view != nil )
canvas.CustomEvent.new("cb." ~ type, {detail: data}) me._view._root.dispatchEvent(
); canvas.CustomEvent.new("cb." ~ type, {detail: data})
);
return me; return me;
}, },
_windowFocus: func _windowFocus: func
@ -170,3 +171,10 @@ gui.Widget = {
return canvas != nil ? canvas.data("focused") : 0; 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;