Segmented control not locking right

Xojo 2015 r3 MacOS
Segmented control set to lock left and right , doesnt change size with the window.
Anyone else seeing that?

Edit: it wont resize at run time using ctrlSeg.width = either
very odd

It’s an old bug, at least 4 years. I think it was Norman that posted the following workaround. Call it from your Window resized/resizing events.

Public Sub resize(MatchingPanel as PagePanel)
  dim segwidth as integer = MatchingPanel.width / (me.Items.UBound+1)
  dim spillage as integer = MatchingPanel.width - (segwidth * (me.items.ubound+1))
  for i as integer = 0 to me.Items.UBound
    if i = me.Items.UBound then
      me.Items(i).width = segwidth + spillage
    else
      me.Items(i).width = segwidth
    end if
  next
  me.width = MatchingPanel.width
  Me.left = MatchingPanel.left
  Me.SizeToFit
End Sub

Private Property mPanelName as String

Public Property PanelName as String
Get
  return mPanelName
End Get
Set
  mPanelName = value
End Set
End Property

I’d prefer it if he had fixed it in Xojo …

Yup. I’m old-fashioned that way …

marked as answered although I have decided to make the thing a fixed size for now.

[quote=318019:@Tanner Lee]Public Sub resize(MatchingPanel as PagePanel)
dim segwidth as integer = MatchingPanel.width / (me.Items.UBound+1)
dim spillage as integer = MatchingPanel.width - (segwidth * (me.items.ubound+1))
for i as integer = 0 to me.Items.UBound
if i = me.Items.UBound then
me.Items(i).width = segwidth + spillage
else
me.Items(i).width = segwidth
end if
next
me.width = MatchingPanel.width
Me.left = MatchingPanel.left
Me.SizeToFit
End Sub[/quote]

do u mean PagePanel or SegmentControl?

The code refers to a SegmentedControl placed within a PagePanel.

I ran into this issues last week… It is annoying…

Norms solution is a quick and dirty fix but it puts all the EXTRA space to the end segment which not great esthetically. I was going to create a feedback but when I searched I found one already existed…

In it Norm asks how should it behave it if you could could lock left and right…

As I did not like the quick and dirty solution I decided to figure that out for my use…

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

That way it works is

[code]
If TotalSegContentWidth >= AvailbleWidth

IF All Segments can be displayed at equal width
It does that (and distributes odd pixels among the segments to hide unevenness)
Else
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
until done with the min being all segs set to the minimum width that will display their full content
End if

Else

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

End if[/code]

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

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 selected a menuitem calls the SegmentedControl Action event and it’s segment behaves as if it was pressed… The menu also reflects the the button status,… If a button in in the selected state the MenuItem is checked… if the segment is disabled the MenuItem is disabled

I also added a settable option so that when in radio button mode if you click on a selected button it will unselect so that no button is pressed… That way I don’t have to waste space on a “none” segment when I need one!