* * *

Author Topic: How to use button "groups" (NSSegmentedControl?) in Lazarus?  (Read 673 times)

Hansaplast

  • Sr. Member
  • ****
  • Posts: 446
  • Tweaking4All.com
    • Tweaking4All
How to use button "groups" (NSSegmentedControl?) in Lazarus?
« on: November 07, 2018, 03:13:52 pm »
I know this is not is standard LCL control, it's Cocoa specific (even though I'd suspect something like this exists in most OS'es).
I was wondering if anyone knew how to implement a Segmented Control (using NSSegmentedControl), or something like that?


I've tried alternatives like Toolbar and Coolbar, but they kind-a look bad and outdated - especially under MacOS.
The challenge is to put several buttons next to each other as a group, where the sides of the buttons line up nicely, as seen in the screenshot.
In the screenshot I've used BGRAControls, but unfortunately, they do not adapt to changes in themes unless I hardcode a theme (for all scenarios), where as regular buttons do adapt very well without any extra coding.

lainz

  • Hero Member
  • *****
  • Posts: 2882
    • Home
Re: How to use button "groups" (NSSegmentedControl?) in Lazarus?
« Reply #1 on: November 07, 2018, 08:45:18 pm »
Theme a ttoolbar with your own drawing.

Hansaplast

  • Sr. Member
  • ****
  • Posts: 446
  • Tweaking4All.com
    • Tweaking4All
Re: How to use button "groups" (NSSegmentedControl?) in Lazarus?
« Reply #2 on: November 08, 2018, 10:36:09 am »
Could you elaborate how this is done or what you mean?

lainz

  • Hero Member
  • *****
  • Posts: 2882
    • Home
Re: How to use button "groups" (NSSegmentedControl?) in Lazarus?
« Reply #3 on: November 08, 2018, 02:58:12 pm »
TToolBar has on paint event and on paint button event.

You can draw anything using themes unit or a bitmap.

Draw the first and last as special with rounded corners and everything else as a middle button.

Hansaplast

  • Sr. Member
  • ****
  • Posts: 446
  • Tweaking4All.com
    • Tweaking4All
Re: How to use button "groups" (NSSegmentedControl?) in Lazarus?
« Reply #4 on: November 08, 2018, 03:19:23 pm »
Ah OK, thank you! :)


I already thought you meant something like that - even though I have zero experience with the Themes unit, I did play with the test/demo application I found in the forum. Most controls do not seem to work under macOS though.

On that note; I guess I currently do something similar right now with BGRAControls (meaning: define the look and such).
The problem I'm running into is that regular controls, for example TButton, automatically adapt on the fly to theme changes. Latest SVN version work very well with macOS Dark Theme and Accent Colors and this seems to work pretty good under GTK2 as well. Note: But it doesn't work under Windows with it's new dark mode and accent colors, due to UWP vs Win32. The Themes demo/test shows that the Themes unit does not appear to respond to changes of themes either (under macOS).


Since I have no mechanism (by my knowledge) to receive a notification that a theme has changed, I wouldn't know when to change custom drawn controls (like your excellent suggestion, and BGRAControls) to match the changes (on the fly). Is there such a notification that I respond to?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus