How to get the width of GUI element containers?

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

How to get the width of GUI element containers?

Post by Pi-C »

I've this frame:

Code: Select all

  local char_window = gui.add({
    type = "frame",
    name = character_frame,
    caption = {"minime-GUI.gui-name-charselector-caption"},
    direction = "vertical",
    visible = true,
  })
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:

Code: Select all

  for p_index, p in pairs(global.gui_character_pages) do
    element = make_table(char_window, p_index)
  end
Below that frame there is a flow that contains a variable number of more flows:

Code: Select all

  main_flow = gui.add({
    type = "flow",
    name = bottom_flow,
    direction = "horizontal",
    visible = true,
  })
Between the flows inside main_flow, I've added empty widgets as spacers:

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
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?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: How to get the width of GUI element containers?

Post by yaim904 »

There is no way to read the height or width of an element.
Pi-C wrote:
Thu Apr 21, 2022 5:06 pm
Is there any way how I could determine the real width of character_frame, so that I can set the width of main_flow?
If you want the container sizes, you must give the inner objects a fixed size.
Pi-C wrote:
Thu Apr 21, 2022 5:06 pm
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 hope this is of help to you.
I will be on the lookout for any comments.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: How to get the width of GUI element containers?

Post by Pi-C »

yaim904 wrote:
Sun May 01, 2022 11:36 pm
There is no way to read the height or width of an element.
Yes, looks like it … :cry:
Pi-C wrote:
Thu Apr 21, 2022 5:06 pm
Is there any way how I could determine the real width of character_frame, so that I can set the width of main_flow?
If you want the container sizes, you must give the inner objects a fixed size.
The idea was that the columns in the main table may all have different width, depending on the size of the button captions. I want the flow below that table to have the same width, but as I can't know how much space I will need to display 5 columns completely side by side, I'll measure the effective width. (Something common in LaTeX: To be flexible regarding fonts etc., you don't give a fixed size, but calculate it. Just define a \savebox without printing it, measure its dimensions, and use the result to calculate the dimensions of your real box.)
I hope this is of help to you.
I will be on the lookout for any comments.
Sorry, this doesn't really bring me a step forwards. But thanks anyway, I appreciate it! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: How to get the width of GUI element containers?

Post by yaim904 »

I would like to help you, but I really don't understand what you are trying to do.

How about showing me in code what you have and a drawing of what you want??

So be a scheme like this
GUI auto-research-Status.png
GUI auto-research-Status.png (815.34 KiB) Viewed 755 times
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Post Reply

Return to “Modding help”