Okay so the idea of tooltip is a bit fuzzy... I mean there is now real "popup window" in dfhack. We could do something fancy but i'm too tired to thing of that, so i'll show how i would do that.
function tutorial_screen:init(args)
self:addviews{
widgets.Label{text={{text="Info:"},{text=self:callback("get_tooltip")}},frame={t=1,l=1}},
widgets.List{view_id="my_list",choices={{text='a',tooltip="this is 'a'"},{text='b',tooltip="second leter of alphabet"},{text='c',tooltip="3rd choice"}},frame={t=3,l=1}},
widgets.Label{
text={{text="Exit",key="LEAVESCREEN",frame={b=1,l=1},key_sep="()",on_activate=self:callback('dismiss')}}
}
}
end
function tutorial_screen:get_tooltip()
local _,choice=self.subviews.my_list:getSelected()
return choice.tooltip
end
Again few ways to do it (even when not doing fancy stuff). This way label tries to print second part, and it checks what is in list that is currently selected. List is also modified so it has some more info for each item.
So broken down into parts:
widgets.Label{ -- a new label
text={ --text has multiple parts
{text="Info:"}, --static "Info:" part
{text=self:callback("get_tooltip")} -- and dynamic part that calls self:get_tooltip (each frame actually...)
},frame={t=1,l=1} --position stuff
},
The function in question is:
function tutorial_screen:get_tooltip()
local _,choice=self.subviews.my_list:getSelected() --this returns index and choice. We throw out index but...
return choice.tooltip --... keep the choices tooltip
end
How does that "my_list" happen or why choice has "tooltip" field? By magic of lua ofcourse:
widgets.List{ -- again new list
view_id="my_list", --this is named widget, we can get it by using "self.subviews[name]" format
choices={ --now we had simple choices, just text, but we can have as complicated as we want (as long as there is "text" field to display)
{text='a',tooltip="this is 'a'"},
{text='b',tooltip="second leter of alphabet"},
{text='c',tooltip="3rd choice"}
},frame={t=3,l=1}
},
Hope this makes everything clearer. And now i'm going to sleep like dead