* The right_label_tooltip seems to be offset somehow so that it simply doesn't appear ever.
* The entire width is determined incorrectly, as you can see here * The switch does not fire any events (tested on_gui_click and on_gui_switch_state_changed)
expected behavior: well,
the hitbox should be where the switch visually is at
the right_label_tooltip should pop up when hovering the right label
the width should consider both labels and the switch itself
the switch should fire events when clicked and state changed
as a comparison, a switch created using commands afterwards works as expected (see expected behavior)
Code: Select all
/c game.player.gui.screen.frame1.add{
type = "switch",
name = "sw3",
left_label_caption = "left",
left_label_tooltip = "left tooltip",
right_label_caption = "right, also with more text",
right_label_tooltip = "right tooltip",
}
reproduce:
load the example mod
create a new world
try pressing the switches
try pressing the button (which does trigger events -> game.print gets run)
try hovering the 2nd switch's lables
add the new switch with the command (see above)
try that switch (also tirggers events)
here is the code for the mod, to make it easier to see what it does:
Code: Select all
script.on_event(defines.events.on_player_created, function(event)
local player = game.get_player(event.player_index)
local frame = player.gui.screen.add{
type = "frame",
direction = "vertical",
caption = "test",
name = "frame1",
}
frame.force_auto_center()
frame.add{
type = "switch",
name = "sw_1",
}
frame.add{
type = "switch",
name = "sw_2",
switch_state = "left",
allow_none_state = false,
left_label_caption = "left",
right_label_caption = "right with more text",
left_label_tooltip = "left tooltip",
right_label_tooltip = "right tooltip",
}
frame.add{
type = "button",
name = "btn_1",
}
end)
script.on_event(defines.events.on_gui_click, function(event)
game.print("clicked " .. event.element.type .. " " .. tostring(event.element.caption or event.element.name))
end)
script.on_event(defines.events.on_gui_switch_state_changed, function(event)
game.print("switched " .. event.element.type .. " " .. tostring(event.element.caption or event.element.name))
end)