Bidmaron
July 21st, 2018, 17:05
I think I have some kind of a conceptual error regarding button controls. I always struggle to get tooltips to work properly. My current dilemma:
I have an Export button that is modal (you press it so you can export one or more tables and press it again when you are done exporting). The button permits you to either enter an export mode where you can select tables or generators in the list and export them one-at-a-time, or, if you push the Alt key when you click the export button, you can mark tables for exporting into one file with multiple tables. Then when you click the export button again, all the marked tables get exported.
So, the tooltip needs to have one of three values:
When the button is not pressed:
"gen_export_button_up" = Depress to export tables or generators one at a time (<alt> to mark multiple items for export)
When the button has been pressed w/o the Alt key:
"gen_export_button_down"=Click to exit export mode
When the button has been depressed with the Alt key:
"alt_gen_export_button_down"=Click to export marked items
Here is the export button declaration:
<template name="button_export">
<buttoncontrol>
<anchored to="buttonanchor" width="50" height="20">
<top />
<left anchor="right" relation="relative" offset="5" />
</anchored>
<pressed name="buttondown" offset="2,2,2,2" nobaseframe="true" />
<font>button-white</font>
<textres>gen_export</textres>
<state tooltipres="gen_export_button_up" frame="buttonup" frameoffset="2,2,2,2"/>
<state tooltipres="gen_export_button_down" frame="buttondown" frameoffset="2,2,2,2"/>
<script file="export_table_generator.lua" />
</buttoncontrol>
</template>
Here is the code that sets the tooltip based upon the button state and the status of the Alt key (and this code is invoked when the button is depressed, in addition to when hovering):
function onHover(state)
--if state then
if getValue()==0 then
setTooltipText(Interface.getString("gen_export_button_up"));
elseif bAlternate then
setTooltipText(Interface.getString("alt_gen_export_button_down"));
else
if getTooltipText()~=Interface.getString("gen_export_button_down") then
Debug.chat("setting tooltip text");
end
setTooltipText(Interface.getString("gen_export_button_down"));
end
--end
end
Note that, in the code above, bAlternate is a variable in the script block that is set according to the alt key status when the button is depressed.
So, when you hover on the button before pushing it, the screen has the appearance of the first screen shot below, but when you hover over it once it is pressed, there is never a tooltip displayed, regardless of the alternate key status when the button was pushed, as you can see from the second screenshot. When you push export again to return to normal mode, the original tooltip for button up will be displayed.
24034
We know that the onHover code is working, because the debug shows up in the chat window.
(Note that the control that appeared to the right of the export button is where any module dependency would appear, and note that the export icons on each line get added when Export is clicked)
I have an Export button that is modal (you press it so you can export one or more tables and press it again when you are done exporting). The button permits you to either enter an export mode where you can select tables or generators in the list and export them one-at-a-time, or, if you push the Alt key when you click the export button, you can mark tables for exporting into one file with multiple tables. Then when you click the export button again, all the marked tables get exported.
So, the tooltip needs to have one of three values:
When the button is not pressed:
"gen_export_button_up" = Depress to export tables or generators one at a time (<alt> to mark multiple items for export)
When the button has been pressed w/o the Alt key:
"gen_export_button_down"=Click to exit export mode
When the button has been depressed with the Alt key:
"alt_gen_export_button_down"=Click to export marked items
Here is the export button declaration:
<template name="button_export">
<buttoncontrol>
<anchored to="buttonanchor" width="50" height="20">
<top />
<left anchor="right" relation="relative" offset="5" />
</anchored>
<pressed name="buttondown" offset="2,2,2,2" nobaseframe="true" />
<font>button-white</font>
<textres>gen_export</textres>
<state tooltipres="gen_export_button_up" frame="buttonup" frameoffset="2,2,2,2"/>
<state tooltipres="gen_export_button_down" frame="buttondown" frameoffset="2,2,2,2"/>
<script file="export_table_generator.lua" />
</buttoncontrol>
</template>
Here is the code that sets the tooltip based upon the button state and the status of the Alt key (and this code is invoked when the button is depressed, in addition to when hovering):
function onHover(state)
--if state then
if getValue()==0 then
setTooltipText(Interface.getString("gen_export_button_up"));
elseif bAlternate then
setTooltipText(Interface.getString("alt_gen_export_button_down"));
else
if getTooltipText()~=Interface.getString("gen_export_button_down") then
Debug.chat("setting tooltip text");
end
setTooltipText(Interface.getString("gen_export_button_down"));
end
--end
end
Note that, in the code above, bAlternate is a variable in the script block that is set according to the alt key status when the button is depressed.
So, when you hover on the button before pushing it, the screen has the appearance of the first screen shot below, but when you hover over it once it is pressed, there is never a tooltip displayed, regardless of the alternate key status when the button was pushed, as you can see from the second screenshot. When you push export again to return to normal mode, the original tooltip for button up will be displayed.
24034
We know that the onHover code is working, because the debug shows up in the chat window.
(Note that the control that appeared to the right of the export button is where any module dependency would appear, and note that the export icons on each line get added when Export is clicked)