Lazarus

Programming => General => Topic started by: Jonny on February 28, 2025, 02:58:18 pm

Title: TTrackbar - single colour for both sides
Post by: Jonny on February 28, 2025, 02:58:18 pm
As the position of TTtackBar changes, one side of the slider is one colour and the other side is another colour.

Is it possible to make the colour the same on both sides regardless of the slider position?

Or maybe there the is a simple slider component but I did not see it on the list.

Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 01, 2025, 02:05:56 am
I have found CustomDrawnControls which seems to offer the ability to change colours but can find no working example - does anyone have one, please?
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 02, 2025, 01:05:01 am
Seems that neither TTrackBar nor TCDTrackBar have an OnPaint event that can be overridden. Is a TrackBar somehow a special component that cannot be changed?
Title: Re: TTrackbar - single colour for both sides
Post by: cdbc on March 02, 2025, 07:41:22 am
Hi
TTrackBar is probably a thin wrapper around the TrackBar implemented in the underlying WidgetSet, i.e.: Qt4/5/6, Gtk1/2/3, winders or Mac.
As such, it's not easily changed. You could try implementing it yourself from scratch...
eta: Have a look in 'fpGui' or 'MseGui', for inspiration...
Regards Benny
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 02, 2025, 12:22:03 pm
A "thin wrapper"? Is it April 1st and this forum us teasing me!?!  :)

Seriously though, thanks @Benny, especially for the pointers to the other libraries, I did not realise that GUI programming was so complicated. I have wasted too much time on this small aspect that I shall drop it down on my list and look at it afresh later.
Title: Re: TTrackbar - single colour for both sides
Post by: wp on March 02, 2025, 02:30:50 pm
You could try the TMultiSlider in the IndustrialStuff package. It was written for 3 sliders, but they can be reduced to a single slider. It is fully custom-drawn and gives you access to every color. It is a standalone component and depends only on standard units, i.e. you do not have to install the Industrialstuff package, you can just copy the unit indSliders in your project and create the slider by code at runtime.
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 02, 2025, 02:39:27 pm
Thank you @wp, I shall take a look. One thing that has concerns me about custom drawn components is how they blend in with themes and widgetsets. I am deploying to Linux (GTK2, QT5), Windows and macOS (although I only have Linux to test here). Will custom drawn components inherit colours and appearance or will they look out of place? The reason that I decided upon the LCL originally was for consistency and localised look everywhere.
Title: Re: TTrackbar - single colour for both sides
Post by: cdbc on March 02, 2025, 02:53:48 pm
Hi
Well, now you've got me right confused....
Quote
The reason that I decided upon the LCL originally was for consistency and localised look everywhere.
If that's your aim, then why the h*ll would you want to change the individual widgets to 'out of consistency' look?!?
Sorry, I don't get it...
Regards Benny
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 02, 2025, 03:20:41 pm
Quote from: cdbc
Sorry, I don't get it...

I know, it's rather silly. This is a scientific app. A user provided feedback to complain that the coloured bar suggested that a higher value was "more" or "better" because increasing colour indicated that it was "more" whereas they argued that it was just another "value" and its size was inconsequential. Hence a slider or trackbar without a colour implying magnitide (ie same colour both sizes of the slider) was requested.

I honestly thought that it was going to be trivial, yet days later,here I still am. Users,.. pffft.

Now it looks like one (or several) slider(s) may look different to everything else. Last time I agree to make a GUI for my code!
Title: Re: TTrackbar - single colour for both sides
Post by: cdbc on March 02, 2025, 03:54:47 pm
Hi
Hmmm, with users like yours....
I think I would follow @wp's advice and pick out the unit from 'Industrial Controls' and just use that, just create it manually on startup, should be easy enough...
Regards Benny
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 05, 2025, 04:19:07 pm
The TMultiSlider was very well accepted so big thank you to @wp and @cdbc, the 'Industrial Controls' is a very nice and useful package.

There are a couple of very, very minor drawing issues which the user calls "bleed", especially when knob is at either end, just wanted to report it - I have only tested on GTK2:

Code: Pascal  [Select][+][-]
  1.   with Slider1 do
  2.   begin
  3.     Parent := frmMain;
  4.     Left := 20;
  5.     Height := 24;
  6.     Top := 20;
  7.     Width := 120;
  8.     SliderMode := smSingle;
  9.     ColorAbove := clHighlightText;
  10.     ColorBelow := ColorAbove;
  11.     ColorThumb := clHighlight;
  12.     ThumbStyle := tsCircle;
  13.     RangeMin := 40;
  14.     RangeMax := 120;
  15.     Position := 60;
  16.   end;                      
  17.  

Also, as the slider has no text/caption property, I added a TLabel to my form and set the OnPositionChange event to update the label, but is there a better or "proper" way to link two components together?
Title: Re: TTrackbar - single colour for both sides
Post by: wp on March 05, 2025, 04:49:32 pm
There are a couple of very, very minor drawing issues which the user calls "bleed", especially when knob is at either end, just wanted to report it - I have only tested on GTK2:
What do you mean? What is "bleeding"? If you mean the black pixels around the slider in you screenshot did you try to turn the "Flat" property off?
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 05, 2025, 05:22:00 pm
The "bleeding" that my user reported was the colour of the bar appearing after the knob when the slider is all the way left or right, please see attached image showing flat and non flat sliders.

Good shout with the flat property (I have seen it on GUI components but have never used it before), it does improve it, but does look like the knob could go a few pixels further and the user was thinking that their mouse was broken (:facepalm:).

I was wondering why they worried about it so much, only to find out that they are visually impaired and use a screen magnifier which enhances the so-called "bleed".
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 05, 2025, 05:25:37 pm
PS: not sure if I am being silly but they cannot TAB to the slider or use the keyboard to adjust it - is there a property to set for that?
Title: Re: TTrackbar - single colour for both sides
Post by: wp on March 05, 2025, 05:58:54 pm
The "bleeding" that my user reported was the colour of the bar appearing after the knob when the slider is all the way left or right, please see attached image showing flat and non flat sliders.
It seems to me that the logical tracklength (the length the slider can be shifted from one end to the other) is the visibible track length minus the diameter of the sliders. Therefore, the sliders should stop when they just touch the end of the visible track rectangle. And since the sliders are round and the track is (almost) rectangular some track pixels remain visible. Maybe it's better when you choose a rectangular slider (but of course your users absolutely need the circular slider...). There may still be issues at the right side because I always have difficulties to correctly work with the concept that the "width" of a rectangle is off by one from the count of pixels.

PS: not sure if I am being silly but they cannot TAB to the slider or use the keyboard to adjust it - is there a property to set for that?
No, I designed it without keyboard support to avoid the hassle with focus control needed to determine which one of the three sliders should receive the key input.

Certainly, both issues can be fixed, but require some time which I do not have a the moment.
Title: Re: TTrackbar - single colour for both sides
Post by: Jonny on March 05, 2025, 06:43:09 pm
Quote from: wp
Certainly, both issues can be fixed, but require some time which I do not have a the moment.

Thanks @wp - tbh, I was not expecting a fix, simply passing on a report from an end user (as opposed to us developers) - they can wait!

Quote from: wp
(but of course your users absolutely need the circular slider...)

Hahaha, they get what they are given, thanks for the workaround, rectangular it is!
TinyPortal © 2005-2018