Add popup border, added option to enable popups taking focus (disabled by default)
This commit is contained in:
parent
0f1ac87cae
commit
da894c87c5
1 changed files with 48 additions and 8 deletions
|
@ -6,7 +6,7 @@ gui.Popup = {
|
||||||
# Constructor
|
# Constructor
|
||||||
#
|
#
|
||||||
# @param size ([width, height])
|
# @param size ([width, height])
|
||||||
new: func(size_, id = nil, parent = nil) {
|
new: func(size_, id = nil, parent = nil, take_focus = 0) {
|
||||||
var ghost = _newWindowGhost(id);
|
var ghost = _newWindowGhost(id);
|
||||||
var m = {
|
var m = {
|
||||||
parents: [gui.Popup, PropertyElement, ghost],
|
parents: [gui.Popup, PropertyElement, ghost],
|
||||||
|
@ -16,10 +16,13 @@ gui.Popup = {
|
||||||
_widgets: [],
|
_widgets: [],
|
||||||
_parent: parent,
|
_parent: parent,
|
||||||
_canvas: nil,
|
_canvas: nil,
|
||||||
|
_frame_width: 1,
|
||||||
|
_take_focus: take_focus,
|
||||||
};
|
};
|
||||||
|
|
||||||
m.setInt("content-size[0]", size_[0]);
|
m.setInt("content-size[0]", size_[0]);
|
||||||
m.setInt("content-size[1]", size_[1]);
|
m.setInt("content-size[1]", size_[1]);
|
||||||
|
m._updateDecoration();
|
||||||
|
|
||||||
m.setFocus();
|
m.setFocus();
|
||||||
|
|
||||||
|
@ -115,14 +118,14 @@ gui.Popup = {
|
||||||
},
|
},
|
||||||
#
|
#
|
||||||
setFocus: func {
|
setFocus: func {
|
||||||
if (gui.focused_window != nil) {
|
if (gui.focused_window != nil and me._take_focus) {
|
||||||
gui.focused_window.clearFocus();
|
gui.focused_window.clearFocus();
|
||||||
|
gui.focused_window = me;
|
||||||
}
|
}
|
||||||
|
|
||||||
# me.onFocusIn();
|
# me.onFocusIn();
|
||||||
me._focused = 1;
|
me._focused = 1;
|
||||||
me._onStateChange();
|
me._onStateChange();
|
||||||
gui.focused_window = me;
|
|
||||||
return me;
|
return me;
|
||||||
},
|
},
|
||||||
#
|
#
|
||||||
|
@ -130,11 +133,13 @@ gui.Popup = {
|
||||||
# me.onFocusOut();
|
# me.onFocusOut();
|
||||||
me._focused = 0;
|
me._focused = 0;
|
||||||
me._onStateChange();
|
me._onStateChange();
|
||||||
if (gui.focused_window == me) {
|
if (me._take_focus) {
|
||||||
gui.focused_window = nil;
|
if (gui.focused_window == me) {
|
||||||
}
|
gui.focused_window = nil;
|
||||||
if (me._parent != nil and contains(gui.open_popups, me._parent)) {
|
}
|
||||||
me._parent.setFocus();
|
if (me._parent != nil and contains(gui.open_popups, me._parent)) {
|
||||||
|
me._parent.setFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return me;
|
return me;
|
||||||
},
|
},
|
||||||
|
@ -242,6 +247,12 @@ gui.Popup = {
|
||||||
} elsif (name == "bottom") {
|
} elsif (name == "bottom") {
|
||||||
me._handlePositionAbsolute(child, mode, name, 1);
|
me._handlePositionAbsolute(child, mode, name, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode == 0) {
|
||||||
|
if (name == "size") {
|
||||||
|
me._resizeDecoration();
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_handlePositionAbsolute: func(child, mode, name, index) {
|
_handlePositionAbsolute: func(child, mode, name, index) {
|
||||||
# mode
|
# mode
|
||||||
|
@ -274,6 +285,35 @@ gui.Popup = {
|
||||||
getprop("/sim/gui/canvas/size[" ~ index ~ "]") - me.get(name) - me.get("content-size[" ~ index ~ "]")
|
getprop("/sim/gui/canvas/size[" ~ index ~ "]") - me.get(name) - me.get("content-size[" ~ index ~ "]")
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
getCanvasDecoration: func() {
|
||||||
|
return wrapCanvas(me._getCanvasDecoration());
|
||||||
|
},
|
||||||
|
_updateDecoration: func() {
|
||||||
|
me.set("decoration-border", "1 1 1");
|
||||||
|
me.set("shadow-inset", 5);
|
||||||
|
me.set("shadow-radius", 2);
|
||||||
|
me.setBool("update", 1);
|
||||||
|
|
||||||
|
var canvas_deco = me.getCanvasDecoration();
|
||||||
|
canvas_deco.addEventListener("mousedown", func me.raise());
|
||||||
|
canvas_deco.set("blend-source-rgb", "src-alpha");
|
||||||
|
canvas_deco.set("blend-destination-rgb", "one-minus-src-alpha");
|
||||||
|
canvas_deco.set("blend-source-alpha", "one");
|
||||||
|
canvas_deco.set("blend-destination-alpha", "one");
|
||||||
|
|
||||||
|
var group_deco = canvas_deco.getGroup("decoration");
|
||||||
|
me._frame = group_deco.createChild("path");
|
||||||
|
me._frame.set("fill", "none");
|
||||||
|
me._frame.set("stroke", "#888888");
|
||||||
|
me._frame.set("stroke-width", me._frame_width);
|
||||||
|
|
||||||
|
me._resizeDecoration();
|
||||||
|
me._onStateChange();
|
||||||
|
},
|
||||||
|
_resizeDecoration: func() {
|
||||||
|
me._frame.reset()
|
||||||
|
.rect(0, 0, me.get("size[0]"), me.get("size[1]"));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue