How to have tooltips for buttons / sliders / text on mouse-hover-over on lua gui?

how do i set up tooltips for buttons, text, sliders or any lua gui objects? so hover mouse over something and you get a line of text shown?

according to chatgpt;

" In Renoise’s Lua API, you can’t directly create traditional “tooltips” (like those in other UI frameworks) that appear when hovering over a GUI element. However, you can simulate this behavior by using a label or text element that updates its content when the mouse hovers over specific UI elements.

To create this behavior, you typically need to listen for mouse events and update a designated text field with the “tooltip” content.

Simulating Tooltips in Renoise Lua API

Here’s how you can simulate tooltips in Renoise:

  1. Create a Text Field for the Tooltip: Add a text field to your UI where the tooltip message will be displayed.
  2. Detect Mouse Hover: Update the tooltip text when the mouse hovers over a button or another UI element.

Example Code:

lua

Code kopiëren

local vb = renoise.ViewBuilder()

-- Tooltip text field
local tooltip_label = vb:text{
  text = "",
  width = 300
}

-- Function to update tooltip
local function update_tooltip(text)
  tooltip_label.text = text
end

-- Button with simulated tooltip
local button = vb:button{
  text = "Hover over me",
  width = 100,
  pressed = function() 
    update_tooltip("") -- Clear tooltip when clicked
  end,
  notifier = function()
    update_tooltip("This is a tooltip for the button.")
  end
}

-- Layout
local dialog_content = vb:column{
  button,
  tooltip_label
}

renoise.app():show_custom_dialog("Tooltip Example", dialog_content)

Explanation:

  1. tooltip_label: This is a text element where the tooltip content will be shown.
  2. update_tooltip(text): A helper function to change the text of the tooltip_label.
  3. button: A simple button. When you hover over it, it updates the tooltip_label to show a tooltip message.

Displaying the Tooltip:

  • You can call update_tooltip("Your message") when the mouse is over the element, typically in the notifier or released function.
  • The tooltip clears when the button is clicked or when you want to reset the text.

Limitations:

  • No true hover detection: Renoise’s API doesn’t provide true hover detection, so you must simulate it by using UI events like pressed, released, or custom mouse detection logic.
  • Placement: Tooltips won’t automatically follow the mouse; they stay in a fixed UI element.

This approach allows you to give users contextual help, similar to a tooltip, using the tools available in the Renoise Lua API."

Is it full of shit?

just type tooltip=‘my tooltip’ to viewbuilder object.

local button = vb:button{
  text = "Hover over me",
  width = 100,
  tooltip='I am tooltip',
}
1 Like

@martblek thanks - however, what about vb:switch, vb:slider, vb:minislider, vb:text ?

ok worked nicely for buttons

Screenshot 2024-08-10 at 23.34.53
and for popup

couldn’t get one to show up for vb:text, weirdly enough

Many objects of viewbuilder accept the tooltip property.
However, if you find an object that does not accept it, you can wrap it with a row or column, which does accept tooltip (define the tooltip property in the row/column).

2 Likes

It seems that you have found an API bug. Report it!
Text accepts the tooltip property. It just doesn’t work, and it’s a bug that’s creeping up version after version.

For now, you can use the trick I mentioned above.

reported.

I guess chatgpt has interpreted “create” instead of “show”. Because it’s strange that I answer all that.
If the AI ​​differentiates between creating and displaying, that’s great.

The tooltip in a text view currently is automatically managed by the text view to show the full text as tooltip when the text does not fit into the view.

2 Likes

thanks for explaining!

to be fair, I didn’t give it sufficient input. I bet if I would have provided the correct api documentation to study it would have given a better answer :slight_smile: