1
0
Fork 0

canvas.gui: Add checkbox widget.

This commit is contained in:
Thomas Geymayer 2014-06-17 21:02:59 +02:00
parent e496ca56ab
commit 5d723e6eab
16 changed files with 77 additions and 2 deletions

View file

@ -14,6 +14,7 @@ loadGUIFile("Style.nas");
loadGUIFile("Widget.nas");
loadGUIFile("styles/DefaultStyle.nas");
loadWidget("Button");
loadWidget("CheckBox");
loadWidget("Label");
loadWidget("ScrollArea");
loadDialog("MessageBox");

View file

@ -27,7 +27,6 @@ var DefaultStyle = {
# A button
DefaultStyle.widgets.button = {
padding: [6, 8, 6, 8],
new: func(parent, cfg)
{
me._root = parent.createChild("group", "button");
@ -108,6 +107,69 @@ DefaultStyle.widgets.button = {
}
};
# A checbox
DefaultStyle.widgets.checkbox = {
new: func(parent, cfg)
{
me._root = parent.createChild("group", "checkbox");
me._icon =
me._root.createChild("image", "checkbox-icon")
.setSize(18, 18);
me._label =
me._root.createChild("text")
.set("font", "LiberationFonts/LiberationSans-Regular.ttf")
.set("character-size", 14)
.set("alignment", "left-center");
},
setSize: func(model, w, h)
{
me._icon.setTranslation(0, (h - 18) / 2);
me._label.setTranslation(20, h / 2);
return me;
},
setText: func(model, text)
{
me._label.set("text", text);
var text_width = me._label.maxWidth();
model.setMinimumSize([text_width + 20, 18]);
model.setSizeHint([text_width + 26, 24]);
return me;
},
update: func(model)
{
var backdrop = !model._windowFocus();
var (w, h) = model._size;
var file = me._style._dir_widgets ~ "/";
if( backdrop )
{
file ~= "backdrop-";
me._label.set("fill", me._style.getColor("backdrop_fg_color"));
}
else
me._label.set("fill", me._style.getColor("fg_color"));
file ~= "check";
if( model._down )
file ~= "-selected";
else
file ~= "-unselected";
if( model._enabled )
{
if( model._hover )
file ~= "-hover";
}
else
file ~= "-disabled";
me._icon.set("src", file ~ ".png");
}
};
# A label
DefaultStyle.widgets.label = {
new: func(parent, cfg)

View file

@ -9,7 +9,7 @@ gui.widgets.Button = {
m._flat = cfg.get("flat", 0);
if( style != nil and !m._flat )
m._setView( style.createWidget(parent, "button", cfg) );
m._setView( style.createWidget(parent, cfg.get("type", "button"), cfg) );
return m;
},

View file

@ -0,0 +1,12 @@
gui.widgets.CheckBox = {
new: func(parent, style, cfg)
{
cfg["type"] = "checkbox";
var m = gui.widgets.Button.new(parent, style, cfg);
m._checkable = 1;
append(m.parents, gui.widgets.CheckBox);
return m;
},
setCheckable: nil
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B