How to set width of label in labeled popup

Using Dialog Toolkit I have a labeled popup which is left aligned with all the other controls in the accessory view. I have set the popup left parameter so that the popup shows a nice amount to the right of the label.

However, the label is localised and so can be of varying length. I can increase the popup left parameter to make more room for longer labels but when I do, the entire control shifts an amount to the right i.e. is no longer left aligned with other controls. To avoid that, I need to get the width of the label in each language and set the popup left accordingly.

Is there a way to get the width of the label and use that to provide enough room to show all the text in the label ? Or, should I just create a label control and a popup control separately ? (the label control would return its width which I could then use to position the popup)

Related to that, when I set popup left to an amount less than left inset, the popup overlaps the label. I thought that the popup left amount would be ignored if less than left inset. Here is an example where popup left is 10 and left inset is 70:

Overlap

This is the entire call:

set theLabeledPopUpFileFormatLabel to localized string "File format:"

set {popup_returned, theLabel, theTop} to create labeled popup {"Default", "1", "2", "3", "4", "5"} left inset 70 bottom (theTop + 5) popup width 90 max width 400 label text theLabeledPopUpLabel popup left 10 initial choice "Default"

Thanks.

That’s probably the easiest thing. If you look at the code, that’s what’s happening anyway.

I’m not sure why that’s happening. I suspect there’s been a change in behavior. If so, you’ll probably also see it when you try the above; yell if that happens.

Dang. I find it a bit fiddly to get controls horizontally aligned nicely. Anyway, an ordinary label returns its width so, I can always position the popup without overlapping.

Yes, it should work the way I’d like. I’ll do some investigations tomorrow.

Many thanks.

Sorry for not replying earlier.

I think I’ve found the cause of the overlap. The create labeled popup handler passes the width of the label to create popup. That means that the popup will be placed at that position (+6). But, that ignores the amount of inset of the label. So, if the label is inset, say 70 and is 70 wide, the popup will also be inset at 70, instead of 140.

I fixed the issue by adding theLeft to newWidth and the popup no longer overlaps the label (when popupLeft ≤ theLeft):

	if popupLeft ≤ theLeft then
	set {theLabel, theTop, newWidth} to create label theLabel left inset theLeft bottom (theBottom + 6) max width theWidth aligns left aligned without multiline
	set popupLeft to (newWidth + theLeft)

I would need to do more testing to ensure this change has no undesirable consequences.

Cheers.

That makes sense – I’ll work on an update. Might take a little time, as my main Mac is in for repairs :frowning: