"
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
SimpleView subclass:#Scale
instanceVariableNames:'slider range action'
classVariableNames:''
poolDictionaries:''
category:'Views-Interactors'
!
!Scale class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
version
^ '$Header: /cvs/stx/stx/libwidg2/Scale.st,v 1.4 1995-11-11 16:29:19 cg Exp $'
!
documentation
"
like a slider, but with a range (i.e. may be different from 0..100)
and displaying the current value.
"
!
examples
"
|top s1 s2|
top := StandardSystemView new.
top extent:200@200.
s1 := Scale origin:0.0 @ 0.0 extent:50 @ 1.0 in:top.
s2 := Scale origin:0.5 @ 0.0 extent:50 @ 1.0 in:top.
s2 range:(-50 to:50).
top open
"
! !
!Scale methodsFor:'slider actions'!
scroll:percent
|value y label|
action notNil ifTrue:[
value := (range last - range first) * (percent / 100).
value := value + range first.
action value:value.
y := slider thumbFrame top + (slider thumbFrame height // 2).
self clear.
self paint:Black.
value := value roundTo:(range last - range first) / 100.
label := value asFloat printString.
(label endsWith:'.0') ifTrue:[
label := value asInteger printString
].
self displayString:label
x:slider width + device horizontalPixelPerMillimeter
y:y + (font ascent // 2)
]
! !
!Scale methodsFor:'accessing'!
range:anInterval
range := anInterval
!
scrollAction:aBlock
action := aBlock
! !
!Scale methodsFor:'initialization'!
initialize
super initialize.
range := (0 to:100).
slider := Slider in:self.
slider fixSize.
slider origin:0.0 @ 0.0.
slider extent:slider width@ 1.0.
self width:(slider width
+ (font widthOf:'100')
+ (device horizontalPixelPerMillimeter * 2) rounded).
slider scrollAction:[:percent | self scroll:percent].
! !