eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Slider':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Slider


Inheritance:

   Object
   |
   +--GraphicsMedium
      |
      +--DisplaySurface
         |
         +--SimpleView
            |
            +--View
               |
               +--Scroller
                  |
                  +--Slider
                     |
                     +--FractionalWidgetView
                     |
                     +--HorizontalSlider

Package:
stx:libwidg2
Category:
Views-Interactors
Version:
rev: 1.42 date: 2017/12/20 20:13:45
user: cg
file: Slider.st directory: libwidg2
module: stx stc-classLibrary: libwidg2
Author:
Claus Gittinger

Description:


this class implements sliders - which are simply scrollers
with a constant thumbHeight. For details on actionBlocks and
MVC operation, see the documentation in Scroller.


Instance protocol:

Compatibility-VW
o  beHorizontal
ST-80 compatibility: make the slider a horizontalSlider

o  beVertical
ST-80 compatibility: make the slider a verticalSlider

accessing
o  sliderHeight: numPixels

o  thumbHeight
redefined since a slider has no height - just origin

event handling
o  buttonPress: butt x: x y: y

o  keyPress: key x: x y: y
Modified (format): / 16-11-2016 / 23:13:56 / cg

forced scroll
o  pageDown
fallback to scroll-stepping (same as kbd-right/down)

o  pageUp
fallback to scroll-stepping (same as kbd-right/down)

initialization
o  initStyle
initialize style specifics

o  initialize

private
o  absFromPercent: percent
given a percentage, compute number of pixels

o  computeThumbFrame
redefined, since the thumb-height stays constant

o  percentFromAbs: absValue
given a number of pixels, compute percentage


Examples:


a slider with action block (ST/X style):
    |top s|

    top := StandardSystemView new extent:200@200.
    s := Slider in:top.
    s origin:(0.0@0.0) corner:(15@1.0).
    s scrollAction:[:percent | Transcript show:'moved to: '; showCR:percent asFloat].
    top open
same, horizontal:
    |top s|

    top := StandardSystemView new extent:200@200.
    s := HorizontalSlider in:top.
    s origin:(0.0@0.0) corner:(1.0@15).
    s scrollAction:[:percent | Transcript show:'moved to: '; showCR:percent asFloat].
    top open
with a range other than the default:
    |top s|

    top := StandardSystemView new extent:200@200.
    s := Slider in:top.
    s origin:(0.0@0.0) corner:(20@1.0).
    s scrollAction:[:percent | Transcript show:'moved to: '; showCR:percent asFloat].
    s start:-50 stop:50.
    top open
using a model (ST-80 style): (see the changing value in the inspector)
    |top s m|

    m := 0 asValue.
    m inspect.
    top := StandardSystemView new extent:200@200.
    s := Slider in:top.
    s origin:(0.0@0.0) corner:(20@1.0).
    s model:m.
    top open
reacting to changes from the model: (look at and/or change value using 'self value:' in the inspector).
    |top s m|

    m := 0 asValue.
    m inspect. 
    top := StandardSystemView new extent:200@200.
    s := Slider in:top.
    s origin:(0.0@0.0) corner:(20@1.0).
    s model:m.
    top open
using a different changeSelector:
    |top s1 s2 m|

    m := Plug new.
    m respondTo:#value1: with:[:v | Transcript show:'scroller 1 moved to: '; showCR:v].
    m respondTo:#value2: with:[:v | Transcript show:'scroller 2 moved to: '; showCR:v].

    top := StandardSystemView new extent:200@200.
    s1 := Slider in:top.
    s1 origin:(0.0@0.0) corner:(20@1.0).
    s1 thumbHeight:10.  'percent'.     
    s1 model:m; change:#value1:.

    s2 := Slider in:top.
    s2 origin:(30@0.0) corner:(50@1.0).
    s2 thumbHeight:10.  'percent'.     
    s2 model:m; change:#value2:.
    top open
another example:
    |top redVal greenVal blueVal 
     colorVal upd s1 s2 s3 l|

    redVal := 0 asValue.
    greenVal := 0 asValue.
    blueVal := 0 asValue.

    upd := [colorVal value:(Color red:redVal value
                                  green:greenVal value
                                  blue:blueVal value)].

    colorVal := (Color red:0 green:0 blue:0) asValue.
    colorVal onChangeSend:#value to:[l backgroundColor:colorVal value].

    redVal onChangeSend:#value to:upd.
    greenVal onChangeSend:#value to:upd.
    blueVal onChangeSend:#value to:upd.

    top := StandardSystemView new extent:200@200.
    top label:'Color mixer'.

    s1 := Slider in:top.
    s1 origin:(0.0@0.0) corner:(20@1.0).
    s1 thumbHeight:10.  'percent'.     
    s1 model:redVal.

    s2 := Slider in:top.
    s2 origin:(30@0.0) corner:(50@1.0).
    s2 thumbHeight:10.  'percent'.     
    s2 model:greenVal.

    s3 := Slider in:top.
    s3 origin:(60@0.0) corner:(80@1.0).
    s3 thumbHeight:10.  'percent'.     
    s3 model:blueVal.

    l := Label in:top.
    l origin:90@0.0 corner:1.0@1.0.
    l backgroundColor:Color black.

    top open
the same setup, using action blocks:
    |top red green blue
     colorVal upd s1 s2 s3 labelModel l|

    red := green := blue := 0.

    top := StandardSystemView new extent:200@200.
    top label:'Color mixer'.

    s1 := Slider in:top.
    s1 origin:(0.0@0.0) corner:(20@1.0).
    s1 thumbHeight:10.  'percent'.     
    s1 action:[:percent | red := percent.
                          l backgroundColor:(Color red:red green:green blue:blue)].

    s2 := Slider in:top.
    s2 origin:(30@0.0) corner:(50@1.0).
    s2 thumbHeight:10.  'percent'.     
    s2 action:[:percent | green := percent.
                          l backgroundColor:(Color red:red green:green blue:blue)].

    s3 := Slider in:top.
    s3 origin:(60@0.0) corner:(80@1.0).
    s3 thumbHeight:10.  'percent'.     
    s3 action:[:percent | blue := percent.
                          l backgroundColor:(Color red:red green:green blue:blue)].

    l := Label in:top.
    l origin:90@0.0 corner:1.0@1.0.
    l backgroundColor:Color black.

    top open


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 29 Mar 2024 08:50:35 GMT