Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] /view slider data (size - 4) ? Re:

From: jkinraid:clear at: 2-Aug-2000 14:57

[RChristiansen--pop--isdfa--sei-it--com] wrote:
> When I make a slider, how come the slider /data value reaches a maximum > of four integers less than the size of the slider? > > For example, to return a maximum /data value of 255, use the following... > > REBOL [] > > face-one: layout [ > s: slider 10x259 [s/color: 0.0.0 + s/data show s print s/data] > ] > > view/title face-one "face one"
The problem is because of the edges on the slider. Because they use up 4 pixels of space, you end up with a maximum value of the slider width - 4. So if you did this - face-one: layout [ s: slider 10x259 with [edge/size: 4x4] [s/color: 0.0.0 + s/data show s print s/data] ] view/title face-one "face one" You can use these functions to get/set the position of a slider - get-slider-position: func [ "Returns the sliders position, a value between 0.0 and 1.0" slider [object!] /scale amount [number!] "Scales the position by amount, and converts to an integer" /local result way ] [ way: not zero? slider/pane/way/1 result: (slider/data - 1) / pick (slider/size - (2 * slider/edge/size) - slider/pane/way) way if scale [result: to-integer result * amount] result ] set-slider-position: func [ slider [object!] position [number!] /scale amount [number!] "Scale the position down to a number between 0.0 and 1.0" /local way offset ] [ if scale [position: position / amount] way: not zero? slider/pane/way/1 offset: to-integer (position * pick (slider/size - (2 * slider/edge/size) - slider/pane/way) way) + 1 slider/data: offset slider/pane/offset: slider/pane/way * (to-integer position * pick (slider/size - slider/pane/size - (2 * slider/edge/size)) way) ] So now the code becomes - face-one: layout [ s: slider 10x300 [ s/color: 0.0.0 + get-slider-position/scale s 255 show s print s/color ] ] view/title face-one "face one" Julian Kinraid