Segmented control width cannot be changed at run time

OS: Windows 8 / Mac OS X 10.10.2 as well

Xojo: Xojo 2015r1

Steps: Run the attached project.

When the button is clicked, the segmented control width is doubled, and the value of Width displayed above.

No matter the value, the width of the SegmentedControl never changes.

The same problem manifests in Mac OS X 10.10.2.

The LR does not say this property is available only at design time. On the contrary, it shows an example of change by code.

Expected Result:
Width of the control changes

Actual Result:
Width of the control never changes

Workarounds:
None

<https://xojo.com/issue/38823>

Resize each segment

for i as integer = 0 to SegmentedControl1.Items.UBound
SEgmentedControl1.items(i).Width = SEgmentedControl1.items(i).Width * 2
next
SegmentedControl1.SizeToFit
Label2.Text = "SegmentedControl Width : "+Str(SegmentedControl1.Width)

[quote=178240:@Norman Palardy]Resize each segment

for i as integer = 0 to SegmentedControl1.Items.UBound
SEgmentedControl1.items(i).Width = SEgmentedControl1.items(i).Width * 2
next
SegmentedControl1.SizeToFit
Label2.Text = "SegmentedControl Width : "+Str(SegmentedControl1.Width)[/quote]

Norman this is great. I had not really read through the LR and realize now it is described, although not as clearly as you made it.

Thank you.

The LR certainly doesn’t make it clear
BUT since each segment has a width what would you expect to happen if you set the controls width ?
Stretch each segment to maintain proportions ?
Stretch the right most segment to take up the delta ?
Or something else ?

[quote=178309:@Norman Palardy]The LR certainly doesn’t make it clear
BUT since each segment has a width what would you expect to happen if you set the controls width ?
Stretch each segment to maintain proportions ?
Stretch the right most segment to take up the delta ?
Or something else ?[/quote]

In the IDE, one sets a width and then segments simply get equal fraction of that width. Pretty much like a listbox when no width is indicated for each column. Since the IDE does not have separate width for each segment, I did not think more. So I was simply expecting the control to behave as in the IDE : stretch or contract each segment proportional to the change in width.

Now I understand it is not as simple. Being able to set each segment width is nice. It would be even nnicer if that was possible in the IDE. It would help comprehend better the nature of the control.

Once again, thank you.

My question was quite serious.
We could alter the runtime behavior to do something else and what I’m trying to sort out is what you expect the “something else to be”
The IDE could do something to make it more obvious that each segment can be sized differently.
And the runtime could try & make sizes consistent if you set the overall width.

This is me fishing around for “what would make sense to you” as a precursor to filing a FR

[quote=178334:@Norman Palardy]My question was quite serious.
We could alter the runtime behavior to do something else and what I’m trying to sort out is what you expect the “something else to be”
The IDE could do something to make it more obvious that each segment can be sized differently.
And the runtime could try & make sizes consistent if you set the overall width.

This is me fishing around for “what would make sense to you” as a precursor to filing a FR[/quote]

I see. As a general rule, all controls which have a width property in the IDE can be change the same way at runtime. In the IDE, if you change the width, the segmentedcontrol seems to change all segments equally. I was expecting the same to happen at runtime. It would be coherent with the way all other controls work with width.

Somehow, I find the IDE not adequate to reflect the possibility to set the width of each individual segment. After reading your post, I went back in the IDE and went into segments/edit hoping to find there a way to change each segment width. But it is not there. I compared with the listbox because I feel it is similar. I imagine being able to set segments size for instance as 20,*,20. A listbox would not stretch if columns exceeded the width of the control, though, when a SC would. But yet, keeping the same syntax as a listbox feels right.

[quote=178334:@Norman Palardy]My question was quite serious.

This is me fishing around for “what would make sense to you” as a precursor to filing a FR[/quote]
I would say using the same mechanism as for the ListBox would be the most consistent behaviour.

It enables you to set individual withs, proportional withs, etc

Listbox style would be interesting but I can foresee some issues like :

  1. set the overall control width to 100 and have 3 segments
  2. then set the 3 segments to 40, 40, 40
    Do you adjust the overall control size OR shrink the segment sizes to fit ?
    Or do those in the opposite order of setting each segment then the overall control.
    And should the order you do things actually matter ?

Listbox doesn’t have this issue as the columns can NOT take up 100% of the width.
Or if you specify widths that cumulatively would exceed the listbox width thats OK too.
For a segmented control thats not possible. Its width IS the sum of the segment widths.

So there are some reasons why exact same listbox style might not be possible.
Variations on it might be.

[quote]1) set the overall control width to 100 and have 3 segments
2) then set the 3 segments to 40, 40, 40
Do you adjust the overall control size OR shrink the segment sizes to fit ?[/quote]

I’d suggest that a programmer’s hardcoded values should take precedence. In the absence of any or all hardcoded values then the SC would default to it’s current auto-adjusting behaviour. So for your example in step 2, the SC should become 120px wide.

I don’t know how much of an issue it would be to update the SC width property field in the IDE to reflect that, or if it’s even necessary. It currently doesn’t if you change widths in code, but an IDE reporting incorrect width is a different beast.

At run time you can already override whats done in the IDE. That already works.

Not sure I follow what you mean by “a programmer’s hardcoded values should take precedence”
If I wrote

segmentedcontrol1.width = 100
segementedcontrol.items(0).width = 40
segementedcontrol.items(1).width = 40
segementedcontrol.items(2).width = 40

or

segementedcontrol.items(0).width = 40
segementedcontrol.items(1).width = 40
segementedcontrol.items(2).width = 40
segmentedcontrol1.width = 100

everything is hard coded but it’s conceivable I could get different results just from the order I did things.
In the first case I could believe that the control ended up being 120 pixels wide.
In the second I could believe it ended up at 100 but overrode the width setting for each segment.

I meant that explicit values is entered for any or all individual segments should be the first ones considered.

In your example (IDE width 100px, with 3 x 40 px hardcoded segments) I think the SC should be sized to 120px in the IDE. (When I say hardcoded I mean the as yet non-existant interface to specify a segment’s width).

This way, the SC visually reflects the explicit values entered. I guess this would ultimately require sync’ing with the SC width value in the IDE.

So, explicit segment settings should override an SC’s width property.

Hope this is clearer.

[quote=178454:@Norman Palardy]Listbox style would be interesting but I can foresee some issues like :

  1. set the overall control width to 100 and have 3 segments
  2. then set the 3 segments to 40, 40, 40
    Do you adjust the overall control size OR shrink the segment sizes to fit ?
    Or do those in the opposite order of setting each segment then the overall control.
    And should the order you do things actually matter ?[/quote]

Is it not a matter of priority ? If no segment custom size has been selected, then Width has precedence, and segments are resized evenly, as it happens right now in the IDE. In that respect, it is just like a listbox where no column size has been entered.

If any segment size has been set, then it should be just like now a resizetofit situation. In that respect, that is where the analogy with the listbox stops, since segments cannot scroll. To get back to the default proportional segments, a FitToSize method would be necessary, which would revert to the IDE behavior, where all segments are of equal size, based on the total width of the control.

Like I said I’m just poking around for ideas.
It’s possible we could have the inverse of SizeToFit. Size to Fit takes the segment sizes & resizes the control to the sum.
If we had “Fit To Size” then it might resize the segments to an equal proportion of the overall size.
That’d make it possible to set the overall width and have each segment resize OR resize the segments & have the control resize via size to fit.

How its set in the IDE mostly doesn’t play into this as that is just the IDE not having a means to set the individual segment sizes.
But thats only the initial set up.
Right now it does calculate the segment size given the number of segments & the total width & sets each to that fractional size (basically fit to size)

Going further to support something like the listbox column widths syntax would be another longer term FR

[quote=178476:@Norman Palardy]Like I said I’m just poking around for ideas.
It’s possible we could have the inverse of SizeToFit. Size to Fit takes the segment sizes & resizes the control to the sum.
If we had “Fit To Size” then it might resize the segments to an equal proportion of the overall size.
That’d make it possible to set the overall width and have each segment resize OR resize the segments & have the control resize via size to fit.

How its set in the IDE mostly doesn’t play into this as that is just the IDE not having a means to set the individual segment sizes.
But thats only the initial set up.
Right now it does calculate the segment size given the number of segments & the total width & sets each to that fractional size (basically fit to size)

Going further to support something like the listbox column widths syntax would be another longer term FR[/quote]

Indeed we do not need more than FitToSize. As it stands, the way each segment size is set works just fine, followed by SizeToFit.

[quote=178476:@Norman Palardy]If we had “Fit To Size” then it might resize the segments to an equal proportion of the overall size.
That’d make it possible to set the overall width and have each segment resize OR resize the segments & have the control resize via size to fit.[/quote]

Norman, I would like it very much. I use to localize my software with several languages, and to have the ability to make segmented items’ width proportional to the text, without modifying the total length of the control would be great.

I would like, as well, the ability to set different items’ width from the inspector (Appearance | Edit) (Feedback Case #39357)

I just noticed Fit to Size is what happens on Web Edition.

If we have size to fit, can we still keep individual segment resizing please? Perhaps it could even have a system like the listbox with column width by percentage/pixels; then no size to fit is necessary, as the segments could fit to the control bounds when sized and maintain their proportions, with less needed from the developer. :slight_smile: just ideas.