Can't get segmented control to shrink-expand horizontally when resizing a window

I guess the subject says it all…

I tried with an empty project with a SC on a window with all four locks active and expanding it vertically, works OK, but when I resize the window horizontally the SC does not change at all…

Oh, wait… let me add that within the IDE it works ok… but on the compiled app fails…

Is this ‘as expected’ ?

a) I would not use all FOUR locks… just 3 (left, right and top OR bottom), since you cannnot change the HEIGHT of an SC
b) but even still it does seem SC does NOT follow the left/right locks… just the top or bottom

and NO, that is NOT what I would have expected.

Verified Issue since 2012: <>

Yup. it just doesn’t work.

Well with some work it can be made to work…

[quote=356587:@Karen Atkocius]Well with some work it can be made to work…[/quote]

how did you accomplish that??

I subclassed the segment control and wrote a general resizing method that allows you to set teh whole control to a specific size… and used that to get it to respect lock left and lock right if they are set…

Because the segmented control does not have resizing events ( i wished it did!) I could not make respecting the locks set in the IDE totally self contained.

What I did about that was create Window and container controls subclasses that send resize messages to any instances of my segmented control subclass on them. The method that receives the message checks if the seg control’s parent RectControl (if any) was resized and if so resizes the seg control appropriately.

It’s a bit more involved then that (registration and close logic). I also created Class interfaces to generalize it all in case I ever needed to handle resizing of other controls myself in the future.

The way the resizing logic works Is:

[code]If TotalSegContentWidth >= AvailbleContentWidth

IF All Segments can be fully displayed at equal width Then
It does that (and distributes extra pixels among the segments to hide any unevenness)
It tries setting the largest segment to it’s full width and then sees if it can set the rest to equal sizes and loops
that logic for the next largest etc until done with the min being all segs set to the minimum width that will
display their full content
End if


Since it can’t all fit, it finds a seg width that works to display the largest # of the segments fully, and sets all
of them to that width, minimizing the # that need to show an ellipsis
(Need to check my code for my exact algorithm)

End if

Basically it displays all the content it can, as evenly as it can, in all situations… Seems to work well in my testing.

Then I added more stuff … Individual segments can be menu buttons (which can be hierarchical) …

Also The SegmentedControl can return a menu of the segments contents (including icons) which can be attached to a menubar or used as a contextual menu…

When one of those menuitems is elected, it calls the SegmentedControl Action event as if the corresponding had preen pressed. The menuitems also reflects the the button status,… If a button in in the selected state the MenuItem is checked… if the segment is disabled that MenuItem is disabled

I also added an option that allows a segment to be unselected by clicking on it when in radio button mode, so that no button is pressed… That way I don’t have to waste space on a “none” segment when I need that capability and space is tight.

  • Karen

thanks for explaining to me how you did it.

Possibly related with case <>

Resize every section.

BTW the other issue that I came across is that seems in code in code you can never made the segmented control wider than you initially set it in the Side- only smaller…

So for a fully resizable segmented control, I initially set it in the IDE to a width larger than it could ever be, and use my “size to specific total width” method to set the initial width in the open event.

Most of the other code I’ve seen for handling resizing of the whole control to a specific with does not take into account the segment contents (text + icon - if present) to set the size of each segment, and just resizes the segments equally, which is far from ideal if the segment contents are of significantly different widths…

Is having a nicely resizable segmented control a very common need?

It’s not that hard to do, but it’s a pain because the non content width (Frame/end caps, margins/dividers) needs to be determined empirically and appear to be somewhat platform specific. I had to do that for Mac and Windows for my subclass

  • karen