Page 1 of 1

[kovarex] [1.1.5] switch type LuaGuiElement overwrites label style width

Posted: Tue Dec 15, 2020 3:08 am
by eradicator
What?

Creating a switch type gui element with labels overrides the width of the labels. No matter what i try it seems impossible to create a switch with fixed-width labels.

Explanation

After going through a small odyssey trying to create a column of aligned switches and writing down the lengthy lua-side reimplementation i came to the conclusion that that switch style label behavior makes no sense.

So i was trying to fix this horrible zig-zag:

Image

The only way i can think of to align the switches is to make the labels fixed width.
I tried overwriting the switches label style properties one-by-one, trying anything that seemed related to width.

Code: Select all

local styles = data.raw['gui-style'].default
styles.test_switch_style = util.table.deepcopy(styles.switch)

local il = styles.test_switch_style.inactive_label

local switch_label_width = 70

-- il. width                    = switch_label_width
il. horizontally_stretchable = 'off'
il. horizontally_squashable  = 'on'
-- il. size = {switch_label_width,24}
-- il. minimal_width = switch_label_width
il. maximal_width = switch_label_width
-- il. natural_width = switch_label_width
-- il. maximum_horizontal_squash_size = switch_label_width

But no matter what i try i can not make the labels wider, only smaller.

notstretched.png
notstretched.png (144.53 KiB) Viewed 2433 times
minimal_width.png
minimal_width.png (170.09 KiB) Viewed 2433 times

Re: [kovarex] [1.1.5] switch type LuaGuiElement overwrites label style width

Posted: Thu Jan 07, 2021 6:05 pm
by kovarex
The problem is, that there is internal, custom, logic that changes the minimal width of the labels to fit the on/off variant, as they are different font witht different width, and the switch would move on toggle otherwise.
What I coudld change is, that it would respect the minimal width specified by the parent style when it is being auto-adjusted, so the value could be just enlraged, but not made smaller, which could solve your problem.
So I'm moving this to resolved for 1.1.8

P.S. I didn't test it, as the fix seemed obvious in the code, so let me know if it doesn't solve your problem.