*

sors

  • *
  • 13
    • View Profile
0.8 Button ToolTips
« on: 30 September 2018, 15:50:07 »
Hi, why does this code give an error ?
Code: [Select]
    tgui::Button::Ptr button{tgui::Button::create("MyButton")};
    button->getToolTip()->setText("Hello world");
Quote
error: 'tgui::Widget::Ptr {aka class std::shared_ptr<tgui::Widget>}' has no member named 'setText'|

*

texus

  • *****
  • 1272
    • View Profile
    • Texus's Blog
Re: 0.8 Button ToolTips
« Reply #1 on: 30 September 2018, 15:59:00 »
The tooltip can be anything, not just a label. You have to create the label yourself and pass it to setToolTip.
See https://tgui.eu/tutorials/v0.7/tool-tips/ (it's a tutorial for 0.7 but I don't think I made any changes to this in 0.8, I'll copy the tutorial to the 0.8 tutorial page on my website later today).

If you must change the text later (i.e. if the text is variable) then you first have to cast the widget to the right type:
button->getToolTip()->cast<tgui::Label>()->setText("Hello world");

But doing that before calling setToolTip will result in a crash as getToolTip would return a nullptr.

*

sors

  • *
  • 13
    • View Profile
Re: 0.8 Button ToolTips
« Reply #2 on: 30 September 2018, 16:04:14 »
Thanks for the answer.
i have ToolTips in .txt gui file:
Code: [Select]
    Button."Delete" {
        Position = (0, 0);
        Size = (64, 64);
        Text = "";
        TextSize = 20;

Renderer {
textcolor = rgb(190, 190, 190);
textcolorhover = rgb(250, 250, 250);

texture = "data/gui/tiles/panels/ZonesPanel.png" Part(384, 0, 64, 64);
texturedown = "data/gui/tiles/panels/ZonesPanel.png" Part(384, 64, 64, 64);
texturefocused =  "data/gui/tiles/panels/ZonesPanel.png" Part(384, 0, 64, 64);
texturehover = "data/gui/tiles/panels/ZonesPanel.png" Part(384, 128, 64, 64);
}

        ToolTip {
            DistanceToMouse = (5,20);
            TimeToDisplay = 0.5;
       
            Label {
                AutoSize = true;
                Size = (0, 0);
                Text = "Tooltip text";
                TextSize = 13;
           
                Renderer {
                    backgroundcolor = #00000000;
                    bordercolor = #3C3C3C;
                    borders = (0, 0, 0, 0);
                    textcolor = #3C3C3C;
                }
            }
        }
    }
Then I will not need to assign a button ToolTips ?
setToolTip 

*

texus

  • *****
  • 1272
    • View Profile
    • Texus's Blog
Re: 0.8 Button ToolTips
« Reply #3 on: 30 September 2018, 16:12:22 »
Indeed, setToolTip will automatically be called when loading the button from that text file.
So you just need to do the cast to tgui::Label if you want to change its text after loading it.

*

sors

  • *
  • 13
    • View Profile
Re: 0.8 Button ToolTips
« Reply #4 on: 30 September 2018, 16:21:36 »
tnx!