Sliders & Ticks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Sliders & Ticks

Patrick Huffer
Another slider question: I cannot figure out how to set the tick marks. If
my range is say, 0 to 99, how could I set ticks at intervals of 5, or 10? I
can only seem to get ticks at intervals of 1, or a tick at the beginning and
a tick at the end. I looked at the sample called Video Library that has a
dialog with a slider that does exactly what I want (ticks at intervals
greater than 1), but I can't see how this was done. "hasAutoTicks" is false,
"hasTicks" is true, "range" is (0: 240). "pageSize" and "lineSize" seem to
have no effect on where the ticks are drawn. The ticks appear to be at
intervals of 30. However, when I change "hasAutoTicks" to true (ticks appear
at intervals of 1) and then back to false, all the ticks disappear except
the one at the beginning and the one at the end!! What's going on?? Is there
some programming of the ticks that I can't see?


Reply | Threaded
Open this post in threaded view
|

Re: Sliders & Ticks

Louis Sumberg-2
Patrick,

> Another slider question: I cannot figure out how to set the tick marks.

There's a private method in Slider, #tbmSetTicFreq:, that seems to do the
trick, e.g.,
    aSlider tbmSetTicFreq: 15.

I believe that hasAutoTicks has to be true for this to work.

-- Louis


Reply | Threaded
Open this post in threaded view
|

Re: Sliders & Ticks

Ian Bartholomew-15
Patrick,

In addition to Louis' suggestion you can also specify which ticks you want
to display.  You just send #ticks: to the slider with an argument, a
Collection of some sort, that defines the tick marks you require.  For
example, evaluate the following in a workspace to set 9 irregular tick
marks (0 and 100 are always included)

s := Slider show.
s topShell view extent: 500@100.
s view ticks: #(5 10 25 50 75 90 95)

There are a number of ways that you could set the ticks in your application
but the simplest is probably just to add an #onViewOpened method to the
Shell - something like.

YourShell>>onViewOpened
    super onViewOpened.
    aSlider view ticks: (5 to: 95 by: 5) asArray

I'm not sure why #ticks isn't exposed as an aspect of the Slider control
though?

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: Sliders & Ticks

Patrick Huffer
Ian - that works very well, thanks! I didn't know about these event
methods...

"Ian Bartholomew" <[hidden email]> wrote in message
news:TV5R8.7727$xU5.668462@wards...
> YourShell>>onViewOpened
>     super onViewOpened.
>     aSlider view ticks: (5 to: 95 by: 5) asArray


Reply | Threaded
Open this post in threaded view
|

Re: Sliders & Ticks

Louis Sumberg-2
In reply to this post by Ian Bartholomew-15
> I'm not sure why #ticks isn't exposed as an aspect of the Slider control
> though?

Good question, but what would the aspect symbol be?  (I haven't done much in
this area.)

I did a quick try (in Aspect class>>publishedAspectsOfInstances) adding
Aspect collection: #ticks and went into the VC.  It looks like ticks returns
either an Array or nil, the latter which caused an error to be written to
the Transcript, i.e., Error inspecting an UndefinedObject: 'UndefinedObject
does not understand #asOrderedCollection'.

Ahh, changing it to Aspect sequenceableCollection: #ticks seems to work
rather nicely.


Reply | Threaded
Open this post in threaded view
|

Re: Sliders & Ticks

Ian Bartholomew-15
Louis,

> Ahh, changing it to Aspect sequenceableCollection: #ticks seems to work
> rather nicely.

It does, doesn't it. I was a bit dubious before because the aspects methods
were not straight accessors and the set method also changes a couple of
other aspect values, but neither of those seem to cause a problem in
practice.

It might be better if the default was an empty Array rather than nil (I saw
the walkback you mention with #sequenceableCollection as well as
#collection) but all in all the change does seem to add a bit of value to
the class.

Ian