canvas.gui: Add checkbox widget.
|
@ -14,6 +14,7 @@ loadGUIFile("Style.nas");
|
||||||
loadGUIFile("Widget.nas");
|
loadGUIFile("Widget.nas");
|
||||||
loadGUIFile("styles/DefaultStyle.nas");
|
loadGUIFile("styles/DefaultStyle.nas");
|
||||||
loadWidget("Button");
|
loadWidget("Button");
|
||||||
|
loadWidget("CheckBox");
|
||||||
loadWidget("Label");
|
loadWidget("Label");
|
||||||
loadWidget("ScrollArea");
|
loadWidget("ScrollArea");
|
||||||
loadDialog("MessageBox");
|
loadDialog("MessageBox");
|
||||||
|
|
|
@ -27,7 +27,6 @@ var DefaultStyle = {
|
||||||
|
|
||||||
# A button
|
# A button
|
||||||
DefaultStyle.widgets.button = {
|
DefaultStyle.widgets.button = {
|
||||||
padding: [6, 8, 6, 8],
|
|
||||||
new: func(parent, cfg)
|
new: func(parent, cfg)
|
||||||
{
|
{
|
||||||
me._root = parent.createChild("group", "button");
|
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
|
# A label
|
||||||
DefaultStyle.widgets.label = {
|
DefaultStyle.widgets.label = {
|
||||||
new: func(parent, cfg)
|
new: func(parent, cfg)
|
||||||
|
|
|
@ -9,7 +9,7 @@ gui.widgets.Button = {
|
||||||
m._flat = cfg.get("flat", 0);
|
m._flat = cfg.get("flat", 0);
|
||||||
|
|
||||||
if( style != nil and !m._flat )
|
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;
|
return m;
|
||||||
},
|
},
|
||||||
|
|
12
Nasal/canvas/gui/widgets/CheckBox.nas
Normal 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
|
||||||
|
};
|
After Width: | Height: | Size: 420 B |
After Width: | Height: | Size: 753 B |
BIN
gui/styles/AmbianceClassic/widgets/backdrop-check-selected.png
Normal file
After Width: | Height: | Size: 698 B |
After Width: | Height: | Size: 299 B |
After Width: | Height: | Size: 531 B |
BIN
gui/styles/AmbianceClassic/widgets/backdrop-check-unselected.png
Normal file
After Width: | Height: | Size: 599 B |
BIN
gui/styles/AmbianceClassic/widgets/check-selected-disabled.png
Normal file
After Width: | Height: | Size: 422 B |
BIN
gui/styles/AmbianceClassic/widgets/check-selected-hover.png
Normal file
After Width: | Height: | Size: 907 B |
BIN
gui/styles/AmbianceClassic/widgets/check-selected.png
Normal file
After Width: | Height: | Size: 812 B |
BIN
gui/styles/AmbianceClassic/widgets/check-unselected-disabled.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
gui/styles/AmbianceClassic/widgets/check-unselected-hover.png
Normal file
After Width: | Height: | Size: 531 B |
BIN
gui/styles/AmbianceClassic/widgets/check-unselected.png
Normal file
After Width: | Height: | Size: 599 B |