1
0
Fork 0

canvas.gui: allow disabling widgets.

This commit is contained in:
Thomas Geymayer 2014-06-11 00:00:55 +02:00
parent e4d60f2153
commit 1b5fc0cbdf
9 changed files with 54 additions and 13 deletions

View file

@ -13,6 +13,7 @@ gui.Widget = {
_focused: 0,
_focus_policy: gui.Widget.NoFocus,
_hover: 0,
_enabled: 1,
_view: nil,
_pos: [0, 0],
_size: [32, 32]
@ -32,6 +33,17 @@ gui.Widget = {
me.setSizeHint([x, y]);
me.setMaximumSize([x, y]);
},
setEnabled: func(enabled)
{
if( me._enabled == enabled )
return me;
me._enabled = enabled;
me.clearFocus();
me._onStateChange();
return me;
},
# Move the widget to the given position (relative to its parent)
move: func(x, y)
{
@ -72,6 +84,9 @@ gui.Widget = {
if( canvas._focused_widget != nil )
canvas._focused_widget.clearFocus();
if( !me._enabled )
return me;
me._focused = 1;
canvas._focused_widget = me;

View file

@ -79,16 +79,24 @@ DefaultStyle.widgets.button = {
me._label.setTranslation(w / 2, h / 2 + 5);
if( model._focused and !backdrop )
file ~= "-focused";
if( model._hover and !model._down )
if( model._enabled )
{
file ~= "-hover";
me._bg.set("fill", me._style.getColor("button_bg_color_hover"));
if( model._focused and !backdrop )
file ~= "-focused";
if( model._hover and !model._down )
{
file ~= "-hover";
me._bg.set("fill", me._style.getColor("button_bg_color_hover"));
}
else
me._bg.set("fill", me._style.getColor("button_bg_color"));
}
else
me._bg.set("fill", me._style.getColor("button_bg_color"));
{
file ~= "-disabled";
me._bg.set("fill", me._style.getColor("button_bg_color_insensitive"));
}
me._border.set("src", file ~ ".png");
}

View file

@ -62,9 +62,9 @@ gui.widgets.Button = {
_setView: func(view)
{
var el = view._root;
el.addEventListener("mousedown", func me.setDown(1));
el.addEventListener("mouseup", func me.setDown(0));
el.addEventListener("click", func me.toggle());
el.addEventListener("mousedown", func if( me._enabled ) me.setDown(1));
el.addEventListener("mouseup", func if( me._enabled ) me.setDown(0));
el.addEventListener("click", func if( me._enabled ) me.toggle());
el.addEventListener("mouseleave",func me.setDown(0));
el.addEventListener("drag", func(e) e.stopPropagation());

View file

@ -126,18 +126,30 @@ gui.widgets.ScrollArea = {
view.vert.addEventListener
(
"drag",
func(e) me.moveTo(me._scroll_pos[0], me._drag_offsetY + e.clientY)
func(e)
{
if( me._enabled )
me.moveTo(me._scroll_pos[0], me._drag_offsetY + e.clientY);
}
);
view.horiz.addEventListener
(
"drag",
func(e) me.moveTo(me._drag_offsetX + e.clientX, me._scroll_pos[1])
func(e)
{
if( me._enabled )
me.moveTo(me._drag_offsetX + e.clientX, me._scroll_pos[1]);
}
);
view._root.addEventListener
(
"wheel",
func(e) me.moveTo(me._scroll_pos[0], me._scroll_pos[1] - e.deltaY)
func(e)
{
if( me._enabled )
me.moveTo(me._scroll_pos[0], me._scroll_pos[1] - e.deltaY);
}
);
call(gui.Widget._setView, [view], me);

View file

@ -78,6 +78,12 @@
<blue type="float">0.988</blue>
</button_bg_color_hover>
<button_bg_color_insensitive>
<red type="float">0.89</red>
<green type="float">0.89</green>
<blue type="float">0.89</blue>
</button_bg_color_insensitive>
</colors>
</PropertyList>

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B