Problem with GUI tables
Posted: Mon Aug 29, 2016 2:57 pm
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)