How to get the width of GUI element containers?
Posted: Thu Apr 21, 2022 5:06 pm
I've this frame:
It contains a variable number of tables, where only one table will be visible at any given time. Each table contains two rows. The top row contains "camera" GUI elements of a fixed width, the bottom row contains buttons with a localized text:
Below that frame there is a flow that contains a variable number of more flows:
Between the flows inside main_flow, I've added empty widgets as spacers:
I want to achieve that the first flow in main_flow is starts at the left margin (no problem), and the last element ends at the right margin. However, it seems that the spacers won't be really squashable unless I define the width of main_flow.
Problem: The width of main_flow should be the same as that of char_window. The width of char_window depends on the width of the visible table inside it. The width of the table depends on the width of the individual columns in that table. In an ideal world, this would be the same as the width of the "camera" elements -- but I can't guarantee that because the buttons below the cameras may be wider (depending on the localized string they display).
I thought that I could just read main_flow.style.width after the flow has been rendered, but that won't work. Also, style.width of the visible table inside character_frame is nil. Is there any way how I could determine the real width of character_frame, so that I can set the width of main_flow?
Code: Select all
local char_window = gui.add({
type = "frame",
name = character_frame,
caption = {"minime-GUI.gui-name-charselector-caption"},
direction = "vertical",
visible = true,
})
Code: Select all
for p_index, p in pairs(global.gui_character_pages) do
element = make_table(char_window, p_index)
end
Code: Select all
main_flow = gui.add({
type = "flow",
name = bottom_flow,
direction = "horizontal",
visible = true,
})
Code: Select all
local function make_spacer(parent, name, width)
local ret = parent.add({
type = "empty-widget",
name = name,
direction = "horizontal",
})
ret.style.natural_width = width or 100
ret.style.horizontally_squashable = true
return ret
end
Problem: The width of main_flow should be the same as that of char_window. The width of char_window depends on the width of the visible table inside it. The width of the table depends on the width of the individual columns in that table. In an ideal world, this would be the same as the width of the "camera" elements -- but I can't guarantee that because the buttons below the cameras may be wider (depending on the localized string they display).
I thought that I could just read main_flow.style.width after the flow has been rendered, but that won't work. Also, style.width of the visible table inside character_frame is nil. Is there any way how I could determine the real width of character_frame, so that I can set the width of main_flow?