Problem with GUI tables

Place to get help with not working mods / modding interface.
CrazyCasta
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Aug 29, 2016 2:54 pm
Contact:

Problem with GUI tables

Post by CrazyCasta »

I have created a GUI using a table. The table includes a first column of flows of labels (some have multiple labels to make multiple lines within the same cell). It all looks good when it's loaded the first time, however when I try to remake the GUI after say a gui click or a tick event it add some horizontal space that I don't like. I don't understand why it isn't the same the when it gets remade. Also, I can remake it in the on_player_join event and it will still work properly, it's not until the game gets properly "started" that it starts creating the GUI wrong. Here's my code, please see if you can explain what's wrong with it:

Code: Select all

script.on_event(defines.events.on_player_joined_game, function(event)
    local player = game.players[event.player_index]

    create_all_guis()
    create_all_guis()
end)

function create_gui(player)
    if player.gui.top.frame then
        player.gui.top.frame.destroy()
    end

    local frame = player.gui.top.add{type="frame",
                                     name="frame",
                                     direction="vertical"}
    local flow = frame.add{type="flow",
                           name="flow",
                           direction="vertical",
                           style="description_flow_style"}

    local table = flow.add{type="table", name="table", colspan=2}
    table.style.horizontal_spacing = 0

    local label_flow = table.add{type="frame",
                                       name="label_flow_1",
                                       direction="vertical",
                                       style="inner_frame_style"}
    local label = label_flow.add{type="label",
                                 name="row_label_1_1",
                                 caption="a"}

    local button = table.add{type="button",
                             name="button_1",
                             caption="Button"}
    button.style.font = "default"
    button.style.top_padding = 0
    button.style.bottom_padding = 0

    local label_flow = table.add{type="frame",
                                       name="label_flow_2",
                                       direction="vertical",
                                       style="inner_frame_style"}
    local label = label_flow.add{type="label",
                                 name="row_label_2_1",
                                 caption="b"}

    local button = table.add{type="button",
                             name="button_2",
                             caption="Button"}
    button.style.font = "default"
    button.style.top_padding = 0
    button.style.bottom_padding = 0

    local label_flow = table.add{type="frame",
                                       name="label_flow_3",
                                       direction="vertical",
                                       style="inner_frame_style"}
    local label = label_flow.add{type="label",
                                 name="row_label_3_1",
                                 caption="c"}
    local label = label_flow.add{type="label",
                                 name="row_label_3_2",
                                 caption="d"}

    local button = table.add{type="button",
                             name="button_3",
                             caption="Button"}
    button.style.font = "default"
    button.style.top_padding = 0
    button.style.bottom_padding = 0
end

script.on_event(defines.events.on_player_created, function(event)
    local player = game.players[event.player_index]
    create_all_guis()
    create_all_guis()
end)

function create_all_guis()
    for _, player in pairs(game.players) do
        create_gui(player)
    end
end

script.on_init(function()
    create_all_guis()
    create_all_guis()
end)

function string.starts_with(s, start)
    return string.sub(s, 1, string.len(start)) == start
end

script.on_event(defines.events.on_tick, function()
    if game.tick == 60 then
        create_all_guis()
    end
end)
CrazyCasta
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Aug 29, 2016 2:54 pm
Contact:

Re: Problem with GUI tables

Post by CrazyCasta »

P.S. Forgot to mention, it has something to do with the frame in the table. If I take that out and only use labels it doesn't do the stupid stuff.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Problem with GUI tables

Post by aubergine18 »

It's possibly a bug in GUI API. Are you able to replicate the issue using a simplified layout? If so, would be worth reporting to devs.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
CrazyCasta
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Aug 29, 2016 2:54 pm
Contact:

Re: Problem with GUI tables

Post by CrazyCasta »

What's there IS a pretty simple GUI layout. It's a table in a flow in a frame. The table has 6 elements in it. The left elements have a frame and a label/labels inside that (that frame is what seems to cause it, doesn't break w/o that).

P.S. I don't mean to sound snarky or anything, I understand the concept of a MCVE. That being said, I used 3 rows because it was easiest to see the problem that way. (And the inner frames are necessary to cause the problem).
Post Reply

Return to “Modding help”