Canvas windows: allow hiding without deletion
Optionally, allow Canvas windows to persist (and be shown again) when closed.
This commit is contained in:
parent
4fd8092e38
commit
6e8520dbb5
1 changed files with 38 additions and 3 deletions
|
@ -79,12 +79,13 @@ var Window = {
|
||||||
# Constructor
|
# Constructor
|
||||||
#
|
#
|
||||||
# @param size ([width, height])
|
# @param size ([width, height])
|
||||||
new: func(size, type = nil, id = nil, allowfocus = 1)
|
new: func(size, type = nil, id = nil, allowfocus = 1, destroy_on_close = 1)
|
||||||
{
|
{
|
||||||
var ghost = _newWindowGhost(id);
|
var ghost = _newWindowGhost(id);
|
||||||
var m = {
|
var m = {
|
||||||
parents: [Window, PropertyElement, ghost],
|
parents: [Window, PropertyElement, ghost],
|
||||||
_allowfocus: allowfocus,
|
_allowfocus: allowfocus,
|
||||||
|
_destroy_on_close: destroy_on_close,
|
||||||
_ghost: ghost,
|
_ghost: ghost,
|
||||||
_node: props.wrapNode(ghost._node_ghost),
|
_node: props.wrapNode(ghost._node_ghost),
|
||||||
_focused: 0,
|
_focused: 0,
|
||||||
|
@ -101,7 +102,11 @@ var Window = {
|
||||||
|
|
||||||
# TODO better default position
|
# TODO better default position
|
||||||
m.move(0,0);
|
m.move(0,0);
|
||||||
|
if (destroy_on_close) {
|
||||||
m.setFocus();
|
m.setFocus();
|
||||||
|
} else {
|
||||||
|
m._ghost.hide();
|
||||||
|
}
|
||||||
|
|
||||||
# arg = [child, listener_node, mode, is_child_event]
|
# arg = [child, listener_node, mode, is_child_event]
|
||||||
setlistener(m._node, func m._propCallback(arg[0], arg[2]), 0, 2);
|
setlistener(m._node, func m._propCallback(arg[0], arg[2]), 0, 2);
|
||||||
|
@ -293,6 +298,36 @@ var Window = {
|
||||||
|
|
||||||
me.setFocus();
|
me.setFocus();
|
||||||
},
|
},
|
||||||
|
hide: func()
|
||||||
|
{
|
||||||
|
me.clearFocus();
|
||||||
|
me._ghost.hide();
|
||||||
|
},
|
||||||
|
show: func()
|
||||||
|
{
|
||||||
|
me._ghost.show();
|
||||||
|
me.raise();
|
||||||
|
},
|
||||||
|
# Hide / show the window based on whether it's currently visible
|
||||||
|
toggle: func()
|
||||||
|
{
|
||||||
|
if (me.isVisible()) {
|
||||||
|
me.hide();
|
||||||
|
} else {
|
||||||
|
me.show();
|
||||||
|
me.raise();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# function to be executed when the close button is pressed
|
||||||
|
onClose: func()
|
||||||
|
{
|
||||||
|
if (me._destroy_on_close)
|
||||||
|
{
|
||||||
|
me.del();
|
||||||
|
} else {
|
||||||
|
me.hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
onResize: func()
|
onResize: func()
|
||||||
{
|
{
|
||||||
if( me['_canvas'] == nil )
|
if( me['_canvas'] == nil )
|
||||||
|
@ -492,7 +527,7 @@ var Window = {
|
||||||
|
|
||||||
var button_close = WindowButton.new(title_bar, "close")
|
var button_close = WindowButton.new(title_bar, "close")
|
||||||
.move(x, y);
|
.move(x, y);
|
||||||
button_close.listen("clicked", func me.del());
|
button_close.listen("clicked", func me.onClose());
|
||||||
|
|
||||||
# title
|
# title
|
||||||
var title = me.get("title", "Canvas Dialog");
|
var title = me.get("title", "Canvas Dialog");
|
||||||
|
|
Loading…
Reference in a new issue