fyne
fyne copied to clipboard
Add tooltip
It would be nice to add a tooltip for certain widgets, mainly: a button and a label (or better, make it a part of the basewidget)
may be related: #155
Tooltip is probably something that we could find a way to support on all widgets somehow. Good request. Not sure it should be in BaseWidget, however, probably something that widgets would opt-in to?
As Fyne is a cross-platform toolkit, we need to consider how this would work across the supported platforms. Tooltips work well on desktop, where there is a mouse to hover over elements. However, they do not work on mobile and result in content not being accessible or discoverable.
If you are only targeting desktop then you can create a custom widget that displays a popup when the user hovers over it.
Material seems to suggest on long-press for mobile. So we could do that using a hover event on desktop and perhaps code into mobile driver that long-press triggers tooltip. This certainly does need thought before we go ahead and build the functionality.
In a recent call we discussed the idea of overlaying the ?
icon onto top-right of widgets that have tooltips. This could be an interesting direction.
MenuItems would also benefit from a tooltip.
Perhaps, though it seems less important there as menu items are already textual in nature...
Was this ever implemented?
As this is still open, it hasn’t been implemented here yet. However, it is of course possible to create your own solution for custom widgets.
I've been thinking about how tooltips could be designed into the Fyne API. I think a lot of apps would really benefit from them, mine included, but building out a custom solution is highly cumbersome.
I propose adding a new interface:
package widget
type ToolTippable interface {
ToolTip() string
}
Widgets implement this interface if it is meaningful for them to have tool tips. This also allows app developers to easily extend builtin widgets to add or modify tooltips. Many builtin widgets may want to add a SetToolTip
function to allow developers to set a tool tip without extending, or even just expose a ToolTip string
property on the widget struct (though that naming conflicts with the interface function name.
How the tooltips are displayed is handled by the driver. On desktop a tool tip should be shown when the widget is hovered for a short time. This can happen even if the widget additionally implements Mouseable
and has its own hover logic. On mobile, the tool tip should be shown on long press (secondary tap) IF the widget does NOT implement SecondaryTappable
itself. Using long-press to show tooltips on mobile is the closest thing to a standard behavior according to Wikipedia. The responsibility is on app developers to not design a mobile interface that needs tool tips to be shown on widgets that are secondary tappable. Though there could also be a public function on the Driver
interface ShowToolTipForWidget(w widget.ToolTippable)
to allow developers to bind some other action to showing the tool tip, or build some kind of app tutorial workflow that programmatically shows tool tips for the widgets in a predefined order on first launch.
Thanks for a good summary, but the statement "The responsibility is on app developers to not design a mobile interface that needs tool tips to be shown on widgets that are secondary tappable." Makes me quite nervous. I don't think we can put in app developers to avoid some features if they want to use others for certain platforms.
I'm not too sure why rendering them in the driver is right, I had considered making a Tooltip widget that standard widgets can make use of, or custom widgets could call directly...
I had considered making a Tooltip widget that standard widgets can make use of, or custom widgets could call directly...
This could be a good idea too - even just an option on the existing PopUp widget for it to ignore all input (so MouseOut isn't immediately called if a widget tried to show a tooltip using PopUp) would make a custom tooltip solution a whole lot easier.
I guess showing tooltip on long press regardless if the widget does something else with long press could work on mobile, but it potentially leads to the scenario where two things are shown at once e.g. the tooltip plus a context menu that the widget displays on long press.
I guess showing tooltip on long press regardless if the widget does something else with long press could work on mobile, but it potentially leads to the scenario where two things are shown at once e.g. the tooltip plus a context menu that the widget displays on long press.
Indeed, I don't think we can do both. Which is why the contributor discussions have leaned towards a small "tooltip button" attached to widgets on mobile when a tooltip is available. Like a small help option.
需要一个这样的功能,有什么方法实现吗?
Translated by Apple:
Such a function is needed. Is there any way to realise it?