Canvas widgets: style for Slider
Only horizontal mode for now, and not quite right visually, but usable enough to start with.
|
@ -84,6 +84,15 @@ var WidgetsFactoryDialog = {
|
||||||
});
|
});
|
||||||
m.tab_2.addItem(m.resize_button, 5);
|
m.tab_2.addItem(m.resize_button, 5);
|
||||||
|
|
||||||
|
m.numericControlsTab = VBoxLayout.new();
|
||||||
|
m.tabs.addTab("ncTab", "Numeric Controls", m.numericControlsTab);
|
||||||
|
m.slider = gui.widgets.Slider.new(m.tabsContent, style,
|
||||||
|
{"max-value" : 100,
|
||||||
|
"page-step" : 20,
|
||||||
|
"tick-count" : 10})
|
||||||
|
.setValue(42);
|
||||||
|
m.numericControlsTab.addItem(m.slider);
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -709,61 +709,87 @@ DefaultStyle.widgets.frame = {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# a horionztal or vertical slider, for selecting /
|
# a horizontal or vertical slider, for selecting /
|
||||||
# dragging over a numerical range
|
# dragging over a numerical range
|
||||||
DefaultStyle.widgets.slider = {
|
DefaultStyle.widgets.slider = {
|
||||||
new: func(parent, cfg)
|
new: func(parent, cfg)
|
||||||
{
|
{
|
||||||
me._root = parent.createChild("group", "slider");
|
me._root = parent.createChild("group", "slider");
|
||||||
me._createElement("bg", "image")
|
me._createElement("bg", "image")
|
||||||
.set("slice", "10 10");
|
.set("slice", "2 6");
|
||||||
|
|
||||||
me._createElement("thumb", "image")
|
me._createElement("fill", "image")
|
||||||
.set("slice", "10 10");
|
.set("slice", "2 6");
|
||||||
|
|
||||||
me._ticks = 0;
|
me._fillHeight = me._fill.imageSize()[1];
|
||||||
me._ticksPath = nil;
|
me._createElement("thumb", "image");
|
||||||
|
me._thumbSize = me._thumb.imageSize();
|
||||||
|
|
||||||
|
me._ticks = 0;
|
||||||
|
me._ticksPath = nil;
|
||||||
},
|
},
|
||||||
|
|
||||||
setNormValue: func(model, normValue)
|
setNormValue: func(model, normValue)
|
||||||
{
|
{
|
||||||
var (w, h) = model._size;
|
var (w, h) = model._size;
|
||||||
var availWidthPos = w - h; # pixel range the thumb can move over
|
var halfThumbWidth = me._thumbSize[0] * 0.5;
|
||||||
me._thumb.setTranslation(round(availWidthPos * normValue), 0);
|
var availWidthPos = w - me._thumbSize[0];
|
||||||
|
var thumbX = math.round(availWidthPos * normValue);
|
||||||
|
var thumbY = (h - me._thumbSize[1]) * 0.5;
|
||||||
|
me._thumb.setTranslation(thumbX - halfThumbWidth, thumbY);
|
||||||
|
me._fill.setSize(thumbX, me._fillHeight);
|
||||||
},
|
},
|
||||||
|
|
||||||
update: func(model)
|
update: func(model)
|
||||||
{
|
{
|
||||||
|
var direction = "horizontal";
|
||||||
# set background state
|
# set background state
|
||||||
var file = me._style._dir_widgets ~ "/";
|
var file = me._style._dir_widgets ~ "/";
|
||||||
file ~= "backdrop-";
|
file ~= "scale-" ~ direction ~ "-trough";
|
||||||
if( !model._enabled )
|
if( !model._enabled )
|
||||||
file ~= "-disabled";
|
file ~= "-disabled";
|
||||||
|
|
||||||
me._bg.set("src", file ~ ".png");
|
me._bg.set("src", file ~ ".png");
|
||||||
|
|
||||||
|
# fill state
|
||||||
|
var file = me._style._dir_widgets ~ "/";
|
||||||
|
file ~= "scale-" ~ direction ~ "-fill";
|
||||||
|
if( !model._enabled ) {
|
||||||
|
file ~= "-disabled";
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
me._fill.set("src", file ~ ".png");
|
||||||
|
|
||||||
# set thumb state
|
# set thumb state
|
||||||
file = me._style._dir_widgets ~ "/";
|
file = me._style._dir_widgets ~ "/";
|
||||||
file ~= "button-"; # should we use a seperate thumb?
|
file ~= "slider-" ~ direction;
|
||||||
if( !model._enabled )
|
if( !model._enabled ) {
|
||||||
file ~= "-disabled";
|
file ~= "-disabled";
|
||||||
else if (model._down)
|
} else {
|
||||||
file ~= "-down";
|
if (model._down)
|
||||||
elsif (model._hover)
|
file ~= "-focused";
|
||||||
file ~= "-hovered";
|
if (model._hover)
|
||||||
|
file ~= "-hover";
|
||||||
|
}
|
||||||
|
|
||||||
me._thumb.set("src", file ~ ".png");
|
me._thumb.set("src", file ~ ".png");
|
||||||
|
|
||||||
# set thumb size
|
|
||||||
var (w, h) = model._size;
|
|
||||||
# fixme assumes horizonal for now
|
|
||||||
me._thumb.setSize(h, h);
|
|
||||||
|
|
||||||
# update the position as well, since other stuff
|
# update the position as well, since other stuff
|
||||||
# may have changed
|
# may have changed
|
||||||
me.setNormValue(model, model._normValue());
|
me.setNormValue(model, model._normValue());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setSize: func(model, w, h)
|
||||||
|
{
|
||||||
|
var fillTop = (h - me._fillHeight) * 0.5;
|
||||||
|
me._bg.setTranslation(0, fillTop);
|
||||||
|
me._fill.setTranslation(0, fillTop);
|
||||||
|
me._bg.setSize(w, me._fillHeight);
|
||||||
|
me.setNormValue(model, model._normValue());
|
||||||
|
},
|
||||||
|
|
||||||
updateRanges: func(minValue, maxValue, numTicks = 0)
|
updateRanges: func(minValue, maxValue, numTicks = 0)
|
||||||
{
|
{
|
||||||
if (me._ticks != numTicks) {
|
if (me._ticks != numTicks) {
|
||||||
|
|
|
@ -22,36 +22,62 @@ gui.widgets.Slider = {
|
||||||
# TODO : select where value is shown
|
# TODO : select where value is shown
|
||||||
# TODO : select where tick marks are shown
|
# TODO : select where tick marks are shown
|
||||||
|
|
||||||
if( style != nil ) {
|
m._setView( style.createWidget(parent, cfg.get("type", "slider"), cfg) );
|
||||||
m._setView( style.createWidget(parent, cfg.get("type", "slider"), cfg) );
|
m._view.updateRanges(m._minValue, m._maxValue, m._numTicks);
|
||||||
m._view.updateRanges(m._minValue, m._maxValue, m._numTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
|
|
||||||
setValue: func(val)
|
setValue: func(val)
|
||||||
{
|
{
|
||||||
|
me._value = val;
|
||||||
if( me._view != nil ) {
|
if( me._view != nil ) {
|
||||||
me._view.setNormValue(me._normValue());
|
me._view.setNormValue(me, me._normValue());
|
||||||
}
|
}
|
||||||
return me;
|
return me;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setDown: func(down = 1)
|
||||||
|
{
|
||||||
|
if (me._down == down )
|
||||||
|
return me;
|
||||||
|
|
||||||
|
me._down = down;
|
||||||
|
me._onStateChange();
|
||||||
|
return me;
|
||||||
|
},
|
||||||
|
|
||||||
# protected:
|
# protected:
|
||||||
_setView: func(view)
|
_setView: func(view)
|
||||||
{
|
{
|
||||||
call(gui.Widget._setView, [view], me);
|
call(gui.Widget._setView, [view], me);
|
||||||
|
|
||||||
# var el = view._root;
|
var el = view._root;
|
||||||
# el.addEventListener("mousedown", func if( me._enabled ) me.setDown(1));
|
el.addEventListener("mousedown", func if( me._enabled ) me.setDown(1));
|
||||||
# el.addEventListener("mouseup", func if( me._enabled ) me.setDown(0));
|
el.addEventListener("mouseup", func if( me._enabled ) me.setDown(0));
|
||||||
# el.addEventListener("click", func if( me._enabled ) me.toggle());
|
# el.addEventListener("click", func if( me._enabled ) me.toggle());
|
||||||
|
el.addEventListener("mouseleave",func me.setDown(0));
|
||||||
|
|
||||||
|
view._thumb.addEventListener("drag", func(e) {
|
||||||
|
me._dragThumb(e);
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
# el.addEventListener("mouseleave",func me.setDown(0));
|
_dragThumb: func(event)
|
||||||
# el.addEventListener("drag", func(e) e.stopPropagation());
|
{
|
||||||
|
var vr = me._view._root;
|
||||||
|
var viewPosX = vr.canvasToLocal([event.clientX, event.clientY])[0];
|
||||||
|
var width = me._size[0];
|
||||||
|
|
||||||
|
if (viewPosX < 0) {
|
||||||
|
me.setValue(me._minValue);
|
||||||
|
} elsif (viewPosX > width) {
|
||||||
|
me.setValue(me._maxValue);
|
||||||
|
} else {
|
||||||
|
var norm = viewPosX / width;
|
||||||
|
me.setValue(norm * ( me._maxValue - me._minValue));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
# return value as its normalised equivalent
|
# return value as its normalised equivalent
|
||||||
|
|
After Width: | Height: | Size: 156 B |
After Width: | Height: | Size: 217 B |
BIN
gui/styles/AmbianceClassic/widgets/scale-horizontal-fill.png
Normal file
After Width: | Height: | Size: 256 B |
After Width: | Height: | Size: 153 B |
After Width: | Height: | Size: 249 B |
BIN
gui/styles/AmbianceClassic/widgets/scale-horizontal-trough.png
Normal file
After Width: | Height: | Size: 249 B |
After Width: | Height: | Size: 193 B |
After Width: | Height: | Size: 213 B |
BIN
gui/styles/AmbianceClassic/widgets/scale-vertical-fill.png
Normal file
After Width: | Height: | Size: 257 B |
After Width: | Height: | Size: 163 B |
After Width: | Height: | Size: 243 B |
BIN
gui/styles/AmbianceClassic/widgets/scale-vertical-trough.png
Normal file
After Width: | Height: | Size: 246 B |
After Width: | Height: | Size: 373 B |
After Width: | Height: | Size: 597 B |
BIN
gui/styles/AmbianceClassic/widgets/slider-horizontal-focused.png
Normal file
After Width: | Height: | Size: 575 B |
BIN
gui/styles/AmbianceClassic/widgets/slider-horizontal-hover.png
Normal file
After Width: | Height: | Size: 510 B |
BIN
gui/styles/AmbianceClassic/widgets/slider-horizontal.png
Normal file
After Width: | Height: | Size: 459 B |