Revision: 2562 http://vexi.svn.sourceforge.net/vexi/?rev=2562&view=rev Author: clrg Date: 2007-11-14 13:00:46 -0800 (Wed, 14 Nov 2007)
Log Message: ----------- Slider/spin clean ups - use minvalue/maxvalue instead of just min/max - fix slider first time display jump - other mainly superficial code changes Modified Paths: -------------- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/slider.t trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/spin.t trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/spin.t trunk/widgets/org.vexi.widgets/src/vexi/widget/slider.t trunk/widgets/org.vexi.widgets/src/vexi/widget/spin.t Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/slider.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/slider.t 2007-11-14 20:16:49 UTC (rev 2561) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/slider.t 2007-11-14 21:00:46 UTC (rev 2562) @@ -11,8 +11,8 @@ // public variables thisbox.interval = 1; // user defined interval between steps - thisbox.min = 0; // the lower limit of the value range - thisbox.max = 10; // the upper limit of the value range + thisbox.minvalue = 0; // the lower limit of the value range + thisbox.maxvalue = 10; // the upper limit of the value range thisbox.step = 0; // the current step (integer) thisbox.value = 0; // the current value @@ -41,8 +41,8 @@ // assign static trap functions KeyPressed ++= static.keypressEvent; interval ++= static.syncLimits; - min ++= static.syncLimits; - max ++= static.syncLimits; + minvalue ++= static.syncLimits; + maxvalue ++= static.syncLimits; step ++= static.stepWrite; value ++= static.valueRead; value ++= static.valueWrite; @@ -74,12 +74,12 @@ static.syncLimits = function(v) { cascade = v; // we need all of the following to be set - if (trapee.interval == null || trapee.min == null || trapee.max == null) return; + if (trapee.interval == null || trapee.minvalue == null || trapee.maxvalue == null) return; // interval should be a factor of (max - min) //if ((trapee.max - trapee.min) % trapee.interval) // vexi.log.warn("min/max range is not divisible by interval"); // work out the number of steps - trapee.numsteps = (trapee.max - trapee.min) / trapee.interval; + trapee.numsteps = (trapee.maxvalue - trapee.minvalue) / trapee.interval; } /** mak sure the handle is kept at the write track position */ @@ -90,21 +90,14 @@ /** return value based on step */ static.valueRead = function() { - return vexi.math.min(trapee.min + trapee.step * trapee.interval, trapee.max); + return vexi.math.min(trapee.minvalue + trapee.step * trapee.interval, trapee.maxvalue); } /** set step based on value */ static.valueWrite = function(v) { if (!trapee.traplock) - trapee.step = vexi.math.round((v - trapee.min) / trapee.interval); + trapee.step = vexi.math.round((v - trapee.minvalue) / trapee.interval); return; } - /** reset handle position when widget width changes */ - static.widthWrite = function(v) { - cascade = v; - try { throw "slider width: "+v; } catch(e) { vexi.log.info(e); } - trapee.step = trapee.step; - } - </vexi> Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/spin.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/spin.t 2007-11-14 20:16:49 UTC (rev 2561) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/widget/spin.t 2007-11-14 21:00:46 UTC (rev 2562) @@ -3,57 +3,48 @@ <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.lib.widget"> <meta:doc> <author>Charles Goodwin</author> - <todo> - - use edit to make value editable - </todo> </meta:doc> <ui:box enabled="true"> // public variables + thisbox.interval = 1; // interval by which up/down in/de-crement the result + thisbox.maxvalue; // maximum value of the result + thisbox.minvalue; // minimum value of the result + thisbox.precision = 0; // number of decimal places of result + thisbox.value = 0; // current spin value - thisbox.interval = 1; // interval by which up/down in/de-crement the result - thisbox.max = 1; // maximum value of the result - thisbox.min = 0; // minimum value of the result - thisbox.precision = 0; // number of decimal places of result - thisbox.value = 0; // current spin value - // theme box variables - thisbox.th_less; // the button to decrement thisbox.th_more; // the button to increment thisbox.th_output; // the th_output for the result // assign static trap functions - enabled ++= static.enableFunc; - max ++= static.maxFunc; - min ++= static.minFunc; - value ++= static.valueFunc; - KeyPressed ++= static.keypressFunc; + enabled ++= static.enableWrite; + maxvalue ++= static.maxvalueWrite; + minvalue ++= static.minvalueWrite; + value ++= static.valueWrite; + KeyPressed ++= static.keypressWrite; /** set up 'less' button */ - th_less ++= function(v) - { + th_less ++= function(v) { /** action: decrease value by interval if possible */ - v.action ++= function(v) - { - if (value != null and min != null) - value = vexi.math.max(value - interval, min); - else if (min != null) value = min; + v.action ++= function(v) { + if (value != null and minvalue != null) + value = vexi.math.max(value - interval, minvalue); + else if (minvalue != null) value = minvalue; return; } cascade = v; } /** set up 'more' button */ - th_more ++= function(v) - { + th_more ++= function(v) { /** action: increase value by interval if possible */ - v.action ++= function(v) - { - if (value != null and max != null) - value = vexi.math.min(value + interval, max); - else if (max != null) value = max; + v.action ++= function(v) { + if (value != null and maxvalue != null) + value = vexi.math.min(value + interval, maxvalue); + else if (maxvalue != null) value = maxvalue; return; } cascade = v; @@ -62,16 +53,14 @@ </ui:box> /** propogate enabled value */ - static.enableFunc = function(v) - { + static.enableWrite = function(v) { if (trapee.th_less) trapee.th_less.enabled = v; if (trapee.th_more) trapee.th_more.enabled = v; cascade = v; } /** key control */ - static.keypressFunc = function(v) - { + static.keypressWrite = function(v) { if (v == "down" or v == "DOWN") trapee.th_less.action = true; else if (v == "up" or v == "UP") @@ -80,37 +69,30 @@ } /** constrain value to min */ - static.minFunc = function(v) - { + static.minvalueWrite = function(v) { cascade = v; if (trapee.value > v) trapee.value = v; } /** constrain value to max */ - static.maxFunc = function(v) - { + static.maxvalueWrite = function(v) { cascade = v; if (v > trapee.value) trapee.value = v; } /** check, constrain, and display new value */ - static.valueFunc = function(v) - { + static.valueWrite = function(v) { // FEATURE: deal with precision if (v == null) v = 0; - if (typeof(v) != "number") - { - try - { + if (typeof(v) != "number") { + try { if (typeof(v) != "string") throw "Error"; v = vexi.string.parseFloat(v); - } - catch (e) - { + } catch (e) { throw "Tried to put non-numeric '"+v+"' to 'value' on a spin widget"; } } - v = (v > trapee.min ? (trapee.max > v ? v : trapee.max) : trapee.min); + v = (v > trapee.minvalue ? (trapee.maxvalue > v ? v : trapee.maxvalue) : trapee.minvalue); trapee.th_output.text = "" + v; cascade = v; } Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/spin.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/spin.t 2007-11-14 20:16:49 UTC (rev 2561) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/win2k/spin.t 2007-11-14 21:00:46 UTC (rev 2562) @@ -9,8 +9,8 @@ <lib:spin /> <ui:box redirect=":$content" fill="white" margin="3" padding="3" vshrink="true"> <bevel form="down"> - <focusborder id="focus" layout="place"> - <ui:box id="content" align="right" shrink="true" /> + <focusborder id="focus" layout="layer"> + <ui:box id="content" shrink="true" /> </focusborder> <ui:box orient="vertical" width="15" shrink="true"> <button id="more" height="9" repeats="true"> @@ -22,15 +22,14 @@ </ui:box> </bevel> - thisbox.th_content = $content; thisbox.th_focus = $focus; thisbox.th_more = $more; thisbox.th_less = $less; - thisbox.focused ++= .focusborder..focusWrite; - thisbox.enabled ++= static.enableWrite; - thisbox.max ++= static.constrainWidth; - thisbox.min ++= static.constrainWidth; + thisbox.focused ++= .focusborder..focusWrite; + thisbox.enabled ++= static.enableWrite; + thisbox.maxvalue ++= static.constrainWidth; + thisbox.minvalue ++= static.constrainWidth; </ui:box> @@ -41,9 +40,9 @@ static.constrainWidth = function(v) { cascade = v; - var l1 = (""+trapee.max).length; - var l2 = (""+trapee.min).length; - trapee.th_focus.minwidth = 6 + (l1>l2?l1:l2) + var l1 = (""+trapee.maxvalue).length; + var l2 = (""+trapee.minvalue).length; + trapee.th_output.minwidth = (l1>l2?l1:l2) * vexi.ui.font.width(trapee.font,trapee.fontsize,"0"); } Modified: trunk/widgets/org.vexi.widgets/src/vexi/widget/slider.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/vexi/widget/slider.t 2007-11-14 20:16:49 UTC (rev 2561) +++ trunk/widgets/org.vexi.widgets/src/vexi/widget/slider.t 2007-11-14 21:00:46 UTC (rev 2562) @@ -18,8 +18,8 @@ rdrt..addRedirect($widget, thisbox, "hshrink", "shrink", "vshrink"); rdrt..addRedirect(thisbox, $margin, "margin", "marginleft", "marginright", "margintop", "marginbottom"); - rdrt..addRedirect(thisbox, $widget, "enabled", "focusable", "focused", "interval", "max", "min", - "orient", "value", "KeyPressed", "KeyReleased"); + rdrt..addRedirect(thisbox, $widget, "enabled", "focusable", "focused", "interval", "orient", + "maxvalue", "minvalue", "value", "KeyPressed", "KeyReleased"); </ui:box> <role:focusable /> Modified: trunk/widgets/org.vexi.widgets/src/vexi/widget/spin.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/vexi/widget/spin.t 2007-11-14 20:16:49 UTC (rev 2561) +++ trunk/widgets/org.vexi.widgets/src/vexi/widget/spin.t 2007-11-14 21:00:46 UTC (rev 2562) @@ -1,7 +1,7 @@ <!-- Copyright 2007 - see COPYING for details [LGPL] --> <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.theme" - xmlns:lay="vexi.layout" xmlns:role="org.vexi.lib.role" xmlns:rdrt="vexi.util.redirect"> + xmlns:lay="vexi.layout" xmlns:role="org.vexi.lib.role" xmlns:rdt="vexi.util.redirect"> <meta:doc> <name>Spin Widget</name> <desc>Creates a spin value selector</desc> @@ -21,10 +21,11 @@ // glue code - rdrt..addRedirect(thisbox, $output, "orient", "layout", "font", "fontsize", "text", "textcolor"); - rdrt..addRedirect(thisbox, $margin, "margin", "marginleft", "marginright", "margintop", "marginbottom"); - rdrt..addRedirect(thisbox, $pad, "fill", "padding", "paddingleft", "paddingright", "paddingtop", "paddingbottom"); - rdrt..addRedirect(thisbox, $widget, "enabled", "focusable", "focused", "interval", "max", "min", "value", "KeyPressed", "KeyReleased"); + rdt..addRedirect(thisbox, $output, "orient", "layout", "font", "fontsize", "text", "textcolor"); + rdt..addRedirect(thisbox, $margin, "margin", "marginleft", "marginright", "margintop", "marginbottom"); + rdt..addRedirect(thisbox, $pad, "fill", "padding", "paddingleft", "paddingright", "paddingtop", "paddingbottom"); + rdt..addRedirect(thisbox, $widget, "enabled", "focusable", "focused", "interval", "maxvalue", + "minvalue", "value", "KeyPressed", "KeyReleased"); if ($widget.margin) $margin.margin = $widget.margin; if ($widget.padding) $pad.padding = $widget.padding; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn