Add support for tooltips

This commit is contained in:
david-swift 2024-02-26 12:55:41 +01:00
parent cf0b4b4a5c
commit 24fc372849
2 changed files with 9 additions and 0 deletions

View File

@ -166,4 +166,11 @@ extension View {
} }
} }
/// Add a tooltip to the widget.
/// - Parameter tooltip: The tooltip text.
/// - Returns: A view.
public func tooltip(_ tooltip: String) -> View {
inspect { gtk_widget_set_tooltip_markup($0.pointer?.cast(), tooltip) }
}
} }

View File

@ -108,6 +108,7 @@ struct Demo: App {
.topToolbar { .topToolbar {
HeaderBar { HeaderBar {
Toggle(icon: .default(icon: .sidebarShow), isOn: $sidebarVisible) Toggle(icon: .default(icon: .sidebarShow), isOn: $sidebarVisible)
.tooltip("Toggle Sidebar")
} end: { } end: {
if sidebarVisible { if sidebarVisible {
Text("") Text("")
@ -148,6 +149,7 @@ struct Demo: App {
} }
} }
.primary() .primary()
.tooltip("Main Menu")
} }
} }