Absolute placement for canvas gui dialogs (CSS like right/bottom margin)
This commit is contained in:
parent
f4c828c4de
commit
9af21f41c0
1 changed files with 48 additions and 0 deletions
|
@ -10,6 +10,9 @@ var Dialog = {
|
|||
m.setInt("size[0]", size_dlg[0]);
|
||||
m.setInt("size[1]", size_dlg[1]);
|
||||
|
||||
# arg = [child, listener_node, mode, is_child_event]
|
||||
setlistener(m._node, func m._propCallback(arg[0], arg[2]), 0, 2);
|
||||
|
||||
return m;
|
||||
},
|
||||
# Create the canvas to be used for this dialog
|
||||
|
@ -59,6 +62,51 @@ var Dialog = {
|
|||
raise: func()
|
||||
{
|
||||
me.setBool("raise-top", 1);
|
||||
},
|
||||
# private:
|
||||
_propCallback: func(child, mode)
|
||||
{
|
||||
# support for CSS like position: absolute; with right and/or bottom margin
|
||||
if( child.getName() == "right" )
|
||||
me._handlePositionAbsolute(child, mode, child.getName(), 0);
|
||||
else if( child.getName() == "bottom" )
|
||||
me._handlePositionAbsolute(child, mode, child.getName(), 1);
|
||||
},
|
||||
_handlePositionAbsolute: func(child, mode, name, index)
|
||||
{
|
||||
# mode
|
||||
# -1 child removed
|
||||
# 0 value changed
|
||||
# 1 child added
|
||||
|
||||
if( mode == 0 )
|
||||
me._updatePos(index, name);
|
||||
else if( mode == 1 )
|
||||
me["_listener_" ~ name] = [
|
||||
setlistener
|
||||
(
|
||||
"/sim/gui/canvas/size[" ~ index ~ "]",
|
||||
func me._updatePos(index, name)
|
||||
),
|
||||
setlistener
|
||||
(
|
||||
me._node.getNode("size[" ~ index ~ "]"),
|
||||
func me._updatePos(index, name)
|
||||
)
|
||||
];
|
||||
else if( mode == -1 )
|
||||
for(var i = 0; i < 2; i += 1)
|
||||
removelistener(me["_listener_" ~ name][i]);
|
||||
},
|
||||
_updatePos: func(index, name)
|
||||
{
|
||||
me.setInt
|
||||
(
|
||||
index == 0 ? "x" : "y",
|
||||
getprop("/sim/gui/canvas/size[" ~ index ~ "]")
|
||||
- me.get(name)
|
||||
- me.get("size[" ~ index ~ "]")
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue