Revision: 4446 http://vexi.svn.sourceforge.net/vexi/?rev=4446&view=rev Author: clrg Date: 2012-10-10 11:37:31 +0000 (Wed, 10 Oct 2012) Log Message: ----------- Mousewheel feature for scrollbars - lineheight initializes to default font height - should work for both VScroll (tested) and HScroll (untested) - HScroll/VScroll added to polarizable as property 'mousewheel'
Modified Paths: -------------- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/polarizable.t trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/scrollbar.t trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/table.t trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/scrollbar.t trunk/org.vexi-vexi.widgets/src_test/test/widget/scrollbar_page.t Added Paths: ----------- trunk/org.vexi-vexi.widgets/src_poke/poke/core/ trunk/org.vexi-vexi.widgets/src_poke/poke/core/mousewheel.t Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/polarizable.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/polarizable.t 2012-10-05 01:16:06 UTC (rev 4445) +++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/polarizable.t 2012-10-10 11:37:31 UTC (rev 4446) @@ -12,11 +12,11 @@ thisbox.mindim = "minwidth"; thisbox.maxdim = "maxwidth"; thisbox.orient = "horizontal"; + thisbox.mousewheel = "HScroll"; thisbox.pos = "x"; thisbox.shr = "hshrink"; thisbox.flip = static.flip; thisbox.horizontal = true; - thisbox.orient ++= static.orientWrite; </ui:box> @@ -37,6 +37,8 @@ case "vertical": return "horizontal"; case "hshrink": return "vshrink"; case "vshrink": return "hshrink"; + case "HScroll": return "VScroll"; + case "VScroll": return "HScroll"; default: return null; } } @@ -58,6 +60,7 @@ t.mindim = "minwidth"; t.pos = "x"; t.shr = "hshrink"; + t.mousewheel = "HScroll"; t.horizontal = true; } else { t.contentdim = "contentheight"; @@ -66,6 +69,7 @@ t.mindim = "minheight"; t.pos = "y"; t.shr = "vshrink"; + t.mousewheel = "VScroll"; t.horizontal = false; } } Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/scrollbar.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/scrollbar.t 2012-10-05 01:16:06 UTC (rev 4445) +++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/scrollbar.t 2012-10-10 11:37:31 UTC (rev 4446) @@ -14,7 +14,7 @@ <ui:box> // public variables - thisbox.lineshift; + thisbox.lineheight = vexi.ui.font.height(font, fontsize, "dp");; thisbox.pageshift; thisbox.autohide; thisbox.enabled = true; @@ -45,18 +45,18 @@ // sync functions /** sync viewport with thumb position */ - var syncViewport = function() { + const syncViewport = function() { if (vport and varea) varea[pos] = percent * (vport[dim] - varea[dim]); } /** sync specific listener with viewport position */ - var syncListener = function(v) { + const syncListener = function(v) { if (v and v[0]) v[0][pos] = percent * (v[dim] - v[0][dim]); } /** syncs all listeners with viewport position */ - var syncAllListeners = function(v) { + const syncAllListeners = function(v) { if (motion) { for (var key in listeners) { if (v == key) continue; @@ -66,7 +66,7 @@ } /** sync thumb with viewport size and position */ - var syncThumb = function() { + const syncThumb = function() { // don't do much if we're hidden if (hide) display = false; // conditions where thumb placement is not [yet] desirable @@ -93,7 +93,7 @@ // trap functions to invoke sync /** invokes sync funcs on all but listener trapee */ - var listenerMove = function(v) { + const listenerMove = function(v) { if (trapee[trapname] == v) return; cascade = v; if (percentset or !trapee.constrain) return; @@ -105,11 +105,11 @@ } /** listener resized - sync with viewport */ - var listenerResize = function(v) { cascade = v; syncListener(trapee); } + const listenerResize = function(v) { cascade = v; syncListener(trapee); } - var syncThumbTrap = function(v) { cascade = v; syncThumb(); } + const syncThumbTrap = function(v) { cascade = v; syncThumb(); } - var viewportMove = function(v) { + const viewportMove = function(v) { cascade = min(0, max(v, vport[dim] - varea[dim])); if (percentset) return; percentset = true; @@ -120,7 +120,7 @@ } /** viewport or varea resized */ - var viewportResize = function(v) { + const viewportResize = function(v) { cascade = v; if (percentset) return; // avoid resetting percent @@ -134,6 +134,12 @@ percentset = false; } + /** vertical mousewheel movement */ + const mwheelWrite = function(v) { + cascade = v; + shift = lineheight * v; + } + //////// // public functions @@ -178,18 +184,24 @@ // reassign viewport traps if (vport) { if (!varea) throw "viewport must have a child"; + // mouse wheel scrolling + vport[flip(mousewheel)] --= mwheelWrite; + vport[mousewheel] ++= mwheelWrite; + // react to viewport resize vport[flip(dim)] --= viewportResize; vport[dim] ++= viewportResize; + // react to viewarea resize varea[flip(dim)] --= viewportResize; + varea[dim] ++= viewportResize; + // react to viewarea movement varea[flip(pos)] --= viewportMove; - varea[dim] ++= viewportResize; varea[pos] ++= viewportMove; } // reassign listener traps - var olddim = flip(dim); - var oldpos = flip(pos); - var newdim = dim; - var newpos = pos; + const olddim = flip(dim); + const oldpos = flip(pos); + const newdim = dim; + const newpos = pos; for (var key in listeners) { dim = olddim; pos = oldpos; @@ -206,7 +218,7 @@ min(0, max(vport[dim] - varea[dim], varea[pos] - v)); - return;; + return; } /** set up viewport */ @@ -217,6 +229,7 @@ vport[dim] --= viewportResize; varea[dim] --= viewportResize; varea[pos] --= viewportMove; + v[mousewheel] --= mwheelWrite; } // set up new viewprot if (v) { @@ -224,6 +237,7 @@ v[dim] ++= viewportResize; v[0][dim] ++= viewportResize; v[0][pos] ++= viewportMove; + v[mousewheel] ++= mwheelWrite; } cascade = v; vport = v; @@ -235,7 +249,7 @@ // theme trap assignments /** move up a line */ - var backAction = function(a) { shift = -lineshift; cascade = a; } + const backAction = function(a) { shift = -lineshift; cascade = a; } /** set up back button */ th_back ++= function(v) { @@ -245,7 +259,7 @@ } /** move down a line */ - var nextAction = function(a) { shift = lineshift; cascade = a; } + const nextAction = function(a) { shift = lineshift; cascade = a; } /** set up next button */ th_next ++= function(v) { @@ -255,8 +269,8 @@ } /** invokes a pageshift in appropriate direction */ - var trackAction = function(a) { - var trackpos = track.mouse[pos]; + const trackAction = function(a) { + const trackpos = track.mouse[pos]; if (thumb[pos] > trackpos) shift = -pageshift; else if (trackpos > thumb[pos] + thumb[dim]) shift = pageshift; cascade = a; @@ -275,14 +289,14 @@ var lastpos; var limitpos; var startpos; - var thumbStart = function(v) { + const thumbStart = function(v) { motion = true; startpos = v==1 ? thumb[pos] : varea[pos]; limitpos = v==1 ? track[dim] - thumb[dim] : vport[dim] - varea[dim]; return; } - var thumbStop = function(v) { motion = false; lastpos = null; return; } - var thumbMove = function(d) { + const thumbStop = function(v) { motion = false; lastpos = null; return; } + const thumbMove = function(d) { // avoid duplicates (when flip(pos) changes) if (d[pos] == lastpos) return; lastpos = d[pos]; @@ -318,6 +332,12 @@ /** scrollbars can not have content */ static.containerWrite = function(v) { cascade = v; trapee.v_content = null; } + /** updates the lineheight as used by mousewheel scrolling */ + static.fontWrite = function(v) { + cascade = v; + trapee.lineheight = vexi.ui.font.height(trapee.font, trapee.fontsize, "dp"); + } + /** constrain track to minimum size of thumb */ static.minthumbsizeWrite = function(v) { cascade = v; Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/table.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/table.t 2012-10-05 01:16:06 UTC (rev 4445) +++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/lib/widget/table.t 2012-10-10 11:37:31 UTC (rev 4446) @@ -319,7 +319,7 @@ th_bodyview = fakeviewport[0]; th_body.align = "topleft"; th_body.initAsDynamic(); - th_vscroll.lineshift = rowheight; + th_vscroll.lineheight = rowheight; // [un]assign relevant traps rowheight ++= static.rowheightWrite; selectedindex ++= selectByIndex; @@ -638,7 +638,7 @@ throw "rowtemplate..rowheight must be a valid integer (>0)"; } cascade = v; - trapee.th_vscroll.lineshift = rowheight; + trapee.th_vscroll.lineheight = rowheight; if (trapee.fetchData) { trapee.forceFetchData(); } Modified: trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/scrollbar.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/scrollbar.t 2012-10-05 01:16:06 UTC (rev 4445) +++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/scrollbar.t 2012-10-10 11:37:31 UTC (rev 4446) @@ -7,7 +7,7 @@ </meta:doc> <lib:scrollbar /> - <ui:box lineshift="20" minthumbsize="8"> + <ui:box minthumbsize="8"> <button id="back" width="16" height="16" repeats="true" shrink="true"> <ui:box layout="place"><ui:box id="backimg" debug="true" shrink="true" /></ui:box> </button> Added: trunk/org.vexi-vexi.widgets/src_poke/poke/core/mousewheel.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_poke/poke/core/mousewheel.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_poke/poke/core/mousewheel.t 2012-10-10 11:37:31 UTC (rev 4446) @@ -0,0 +1,8 @@ +<vexi xmlns:ui="vexi://ui" + xmlns="vexi.widget"> + <ui:box> + thisbox.HScroll ++= function(v) { vexi.trace("H: "+v); cascade = v; } + thisbox.VScroll ++= function(v) { vexi.trace("V: "+v); cascade = v; } + vexi.ui.frame = thisbox; + </ui:box> +</vexi> Modified: trunk/org.vexi-vexi.widgets/src_test/test/widget/scrollbar_page.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_test/test/widget/scrollbar_page.t 2012-10-05 01:16:06 UTC (rev 4445) +++ trunk/org.vexi-vexi.widgets/src_test/test/widget/scrollbar_page.t 2012-10-10 11:37:31 UTC (rev 4446) @@ -18,15 +18,14 @@ viewport.height = 300; viewport[0].height = 200000; scrollbar.viewport = viewport; - scrollbar.lineshift = 20; scrollbar.pageshift ++= function() { if (viewport) return 0.9 * (viewport.height); }; var scrollAssert = function(up){ var y = viewport[0].y; track.action = true; vexi.log.info(y + " -> " + viewport[0].y); - if(up) vunit..assertApproxEquals( scrollbar.pageshift, viewport[0].y-y, 20); - else vunit..assertApproxEquals( scrollbar.pageshift, y-viewport[0].y, 20); + if(up) vunit..assertApproxEquals( scrollbar.pageshift, viewport[0].y-y, scrollbar.lineheight); + else vunit..assertApproxEquals( scrollbar.pageshift, y-viewport[0].y, scrollbar.lineheight); }; // spoof mouse This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn