Page 1 of 1

[1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Wed Oct 18, 2023 7:52 pm
by Regular9
Backround:
Earendel's Informatron mod uses custom GUI elements to display text information, however more than a single line of text will result in a tooltip that repeats the text. With large sections, the tooltip blocks half the screen.

The mod adds custom GUI elements by a variation of:

Code: Select all

if page_name == "name" then
    element.add{type="label", name="text_1", caption={"mod_name.text_1"}}
end
Bug:
The Factorio Runtime API docs list 'tooltip' as a member of the GuiElement class, and describes it as:
tooltip :: LocalisedString Read/Write
The text to display when hovering over this element. Writing "" will disable the tooltip, while writing nil will set it to "nil".
I modified the code that adds the custom GUI elements two different ways, adding parts to disable the tooltip using the empty string.

Code: Select all

if page_name == "name" then
    element.add{type="label", name="text_1", caption={"mod_name.text_1"}, tooltip=""}
end
and

Code: Select all

if page_name == "name" then
    element.add{type="label", name="text_1", caption={"mod_name.text_1"}}
    element.text_1.tooltip=""
end
Neither version disabled the tooltip. Instead, the standard tooltip of the entire text was displayed.

Adding text to the tooltip string like:

Code: Select all

if page_name == "name" then
    element.add{type="label", name="text_1", caption={"mod_name.text_1"}, tooltip="Some text here"}
end
or

Code: Select all

if page_name == "name" then
    element.add{type="label", name="text_1", caption={"mod_name.text_1"}}
    element.text_1.tooltip="Some text here"
end
would display the tooltip "Some text here" as expected.

I wrote a basic mod called InformatronBugTest to test the tooltip, found here. The relevant code is found in scripts\interface.lua and contains some further examples commented out. Included in this post is a savegame with only my test mod and the Informatron mod installed. The Informatron can be opened with the I key or by clicking the icon in the top left of the screen.
InformatronTooltipTest.zip
(2.71 MiB) Downloaded 26 times

My conclusion is that either this is a bug in the tooltip LuaGuiElement or a mistake in the API docs.

Re: [1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Wed Oct 18, 2023 8:21 pm
by Rseding91
Thanks for the report however I can't reproduce what you describe. When I test, it works perfectly. Setting tooltip="" in the call to add results in no tooltip. Writing element.tooltip = "" results in no tooltip. Writing element.tooltip = nil results in "nil" in the tooltip.

Do you have some basic example code I can run in the console?

Re: [1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Wed Oct 18, 2023 9:03 pm
by Regular9
I used a mod that I wrote for testing called InformatronBugTest https://mods.factorio.com/mod/InformatronBugTest. Disclaimer that I'm not proficient at coding, this is adapted from an Earendel template.

The tooltip only appears when the text is long enough (longer than a line in the Informatron display, or about 25 words).

Below is the contents of the interface.lua file in the test mod

Code: Select all

remote.add_interface("InformatronBugTest", {
  informatron_menu = function(data)
    return InformatronBugTest_menu(data.player_index)
  end,
  informatron_page_content = function(data)
    return InformatronBugTest_page_content(data.page_name, data.player_index, data.element)
  end
})

function InformatronBugTest_menu(player_index)
  return {
    withtooltip=1,
    withouttooltip=1
  }
end

function InformatronBugTest_page_content(page_name, player_index, element)
  -- main page
  if page_name == "InformatronBugTest" then
    element.add{type="label", name="text_1", caption={"InformatronBugTest.page_InformatronBugTest_text_1"}}
  end

  if page_name == "withtooltip" then
    element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}}
  end

  if page_name == "withouttooltip" then
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}}                               --standard format--
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}, tooltip={""}}                 --displays normal tooltip--
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}, tooltip={false}}              --displays 'Unknown key: "false"'--
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}, tooltip={"", "tooltip here"}} --displays 'tooltip here'--
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}, tooltip={"", ""}}             --displays normal tooltip--
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}, tooltip={"", false}}          --displays 'false'--
    element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}, tooltip=""}                   --displays normal tooltip--

    --enable element.add only when using .tooltip below--
    --element.add{type="label", name="text_1", caption={"InformatronBugTest.text_1"}}
    --element.text_1.tooltip=false            --displays 'false'--
    --element.text_1.tooltip={""}             --displays normal tooltip--
    --element.text_1.tooltip=""               --displays normal tooltip--
    --element.text_1.tooltip={"", ""}         --displays normal tooltip--
    --element.text_1.tooltip="tooltip here"   --displays 'tooltip here'--
  end
end

Re: [1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Wed Oct 18, 2023 11:07 pm
by Rseding91
I see now where the confusion comes from. Writing an empty string removes the *mod set* tooltip. It doesn't disable the auto-generated one from the engine side.

However in this case the auto-generated one shouldn't be showing either. It's only meant to show when the text doesn't fit natively in the GUI but it seems to be showing regardless in this case.

Re: [1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Thu Oct 19, 2023 1:42 pm
by Regular9
I've noticed the tooltip only appears when the text wraps onto a second line. This might be triggering a 'text doesn't fit, make a tooltip' sort of check before then wrapping the text onto the next line obviating the need for the tooltip

Re: [1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Tue Apr 09, 2024 2:57 pm
by Rseding91
I looked into this more and it's now fixed for 2.0.

Re: [1.1.93] Empty string "" doesn't disable LuaGuiElement tooltip

Posted: Tue Apr 09, 2024 3:14 pm
by Regular9
Great to hear! :)