Skip to content

Commit

Permalink
Show tooltip doc example in multiple places
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 19, 2024
1 parent 22fbb9c commit 4e38992
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
25 changes: 23 additions & 2 deletions widget/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,29 @@ where
/// Creates a new [`Tooltip`] for the provided content with the given
/// [`Element`] and [`tooltip::Position`].
///
/// [`Tooltip`]: crate::Tooltip
/// [`tooltip::Position`]: crate::tooltip::Position
/// Tooltips display a hint of information over some element when hovered.
///
/// # Example
/// ```no_run
/// # mod iced { pub mod widget { pub use iced_widget::*; } }
/// # pub type State = ();
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// use iced::widget::{container, tooltip};
///
/// enum Message {
/// // ...
/// }
///
/// fn view(_state: &State) -> Element<'_, Message> {
/// tooltip(
/// "Hover me to display the tooltip!",
/// container("This is the tooltip contents!")
/// .padding(10)
/// .style(container::rounded_box),
/// tooltip::Position::Bottom,
/// ).into()
/// }
/// ```
pub fn tooltip<'a, Message, Theme, Renderer>(
content: impl Into<Element<'a, Message, Theme, Renderer>>,
tooltip: impl Into<Element<'a, Message, Theme, Renderer>>,
Expand Down
46 changes: 45 additions & 1 deletion widget/src/tooltip.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
//! Display a widget over another.
//! Tooltips display a hint of information over some element when hovered.
//!
//! # Example
//! ```no_run
//! # mod iced { pub mod widget { pub use iced_widget::*; } }
//! # pub type State = ();
//! # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
//! use iced::widget::{container, tooltip};
//!
//! enum Message {
//! // ...
//! }
//!
//! fn view(_state: &State) -> Element<'_, Message> {
//! tooltip(
//! "Hover me to display the tooltip!",
//! container("This is the tooltip contents!")
//! .padding(10)
//! .style(container::rounded_box),
//! tooltip::Position::Bottom,
//! ).into()
//! }
//! ```
use crate::container;
use crate::core::event::{self, Event};
use crate::core::layout::{self, Layout};
Expand All @@ -13,6 +35,28 @@ use crate::core::{
};

/// An element to display a widget over another.
///
/// # Example
/// ```no_run
/// # mod iced { pub mod widget { pub use iced_widget::*; } }
/// # pub type State = ();
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// use iced::widget::{container, tooltip};
///
/// enum Message {
/// // ...
/// }
///
/// fn view(_state: &State) -> Element<'_, Message> {
/// tooltip(
/// "Hover me to display the tooltip!",
/// container("This is the tooltip contents!")
/// .padding(10)
/// .style(container::rounded_box),
/// tooltip::Position::Bottom,
/// ).into()
/// }
/// ```
#[allow(missing_debug_implementations)]
pub struct Tooltip<
'a,
Expand Down

0 comments on commit 4e38992

Please sign in to comment.