However i found that most of the time, and in situations where that would be the most useful, it, in fact, does not try to squash/stretch.Natural width specifies the width of the element tries to have, but it can still be squashed/stretched to have a smaller or bigger size.
Example 1:
Code: Select all
local frame = game.players[1].gui.screen.add{
type = "frame",
name = "test"
}
frame.auto_center = true
frame.style.horizontally_stretchable = true
local label = frame.add{
type = "label",
caption = "this is a long label dsbajdbkasbdkjabsjkdbakjdbksj"
}
label.style.horizontally_stretchable = true
label.style.natural_width = 300
Expected result: label stretches to its natural width since the parent element allows it.
Actual result:
Example 2:
Code: Select all
local frame = game.players[1].gui.screen.add{
type = "frame",
name = "test"
}
frame.auto_center = true
frame.style.natural_width = 150
frame.style.horizontally_stretchable = true
local label = frame.add{
type = "label",
caption = "this is a long label dsbajdbkasbdkjabsjkdbakjdbksj"
}
label.style.horizontally_stretchable = true
label.style.natural_width = 300
Actual result:
Frame stretches up to its natural_width. This makes sense, it shows that natural_width sometimes works. Whether it should stretch up to label natural_width could be ambiguous, so i assume this works as intended.
Example 3:
Code: Select all
local frame = game.players[1].gui.screen.add{
type = "frame",
name = "test"
}
frame.auto_center = true
frame.style.natural_width = 150
frame.style.horizontally_stretchable = true
local label = frame.add{
type = "label",
caption = "this is a long label"
}
label.style.horizontally_stretchable = true
label.style.horizontally_squashable = true
label.style.natural_width = 100
local empty = frame.add{
type = "empty-widget",
}
empty.style.horizontally_stretchable = true
empty.style.horizontally_squashable = true
empty.style.natural_width = 20
Expected result: Either label or empty-widget stretches to its natural_width, with the other stretching to fill the remaining space.
So the width should either be 100 and 50 or 130 and 20, or at a 100:20 ratio (ignoring padding/margins).
Actual result: even sizes The last example is of a real problem i encountered trying to have a stretchable label, while having an empty widget as padding so that the label is as wide as it can fit in a flow without hardcoding the widths. While this can probably be solved with some hacks, it is extremely unintuitive and the natural size feature turns out to be mostly useless; i rarely see it used even in gui heavy projects, despite its description making it seem like it allows more versatility in layouts.