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
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)
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.