Skip to content

Commit

Permalink
Arrange Tooltip docs in a more intuitive way
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Aug 21, 2024
1 parent 85d2a37 commit 5a19163
Showing 1 changed file with 60 additions and 60 deletions.
120 changes: 60 additions & 60 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,38 +187,38 @@ impl PrimaryTooltip {
reflect(Component)
)]
pub struct Tooltip {
/// The tooltip content to display.
pub content: TooltipContent,
/// How the tooltip will be positioned.
pub placement: TooltipPlacement,
/// The conditions for activating the tooltip.
pub activation: TooltipActivation,
/// The conditions for dismissing the tooltip.
pub dismissal: TooltipDismissal,
/// The conditions for skipping the next tooltip's activation delay.
pub transfer: TooltipTransfer,
/// How the position of the tooltip entity will be determined.
pub placement: TooltipPlacement,
/// The tooltip entity and content to be displayed.
pub content: TooltipContent,
}

impl Tooltip {
/// Create a new fixed `Tooltip`.
pub fn fixed(placement: Anchor, content: impl Into<TooltipContent>) -> Self {
Self {
content: content.into(),
placement: placement.into(),
activation: TooltipActivation::IMMEDIATE,
dismissal: TooltipDismissal::NONE,
transfer: TooltipTransfer::SHORT,
placement: placement.into(),
content: content.into(),
}
}

/// Create a new cursor `Tooltip`.
pub fn cursor(content: impl Into<TooltipContent>) -> Self {
Self {
content: content.into(),
placement: TooltipPlacement::CURSOR,
activation: TooltipActivation::IDLE,
dismissal: TooltipDismissal::ON_CLICK,
transfer: TooltipTransfer::NONE,
placement: TooltipPlacement::CURSOR,
content: content.into(),
}
}

Expand All @@ -233,6 +233,12 @@ impl Tooltip {
self
}

/// Set a custom [`TooltipPlacement`].
pub fn with_placement(mut self, placement: impl Into<TooltipPlacement>) -> Self {
self.placement = placement.into();
self
}

/// Set a custom [`TooltipActivation`].
pub fn with_activation(mut self, activation: impl Into<TooltipActivation>) -> Self {
self.activation = activation.into();
Expand All @@ -250,11 +256,51 @@ impl Tooltip {
self.transfer = transfer.into();
self
}
}

/// Set a custom [`TooltipPlacement`].
pub fn with_placement(mut self, placement: impl Into<TooltipPlacement>) -> Self {
self.placement = placement.into();
self
/// Tooltip content to be displayed.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub enum TooltipContent {
/// Display the primary tooltip with custom [`Text`].
Primary(Text),
/// Display a fully custom entity as the tooltip.
Custom(Entity),
}

impl From<&str> for TooltipContent {
fn from(value: &str) -> Self {
Self::Primary(Text::from_section(value.to_string(), TextStyle::default()))
}
}

impl From<String> for TooltipContent {
fn from(value: String) -> Self {
Self::Primary(Text::from_section(value, TextStyle::default()))
}
}

impl From<TextSection> for TooltipContent {
fn from(value: TextSection) -> Self {
Self::Primary(Text::from_section(value.value, value.style))
}
}

impl From<Vec<TextSection>> for TooltipContent {
fn from(value: Vec<TextSection>) -> Self {
Self::Primary(Text::from_sections(value))
}
}

impl From<Text> for TooltipContent {
fn from(value: Text) -> Self {
Self::Primary(value)
}
}

impl From<Entity> for TooltipContent {
fn from(value: Entity) -> Self {
Self::Custom(value)
}
}

Expand Down Expand Up @@ -361,9 +407,9 @@ impl Default for TooltipDismissal {
}
}

/// The tooltip transfer conditions.
/// Tooltip transfer conditions.
///
/// When a transfer occurs, the next tooltip's activation delay will be skipped.
/// When a transfer occurs, the next tooltip's [activation delay](TooltipActivation::delay) will be skipped.
///
/// Defaults to [`Self::NONE`].
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -414,52 +460,6 @@ impl Default for TooltipTransfer {
}
}

/// The tooltip entity and content to be displayed.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub enum TooltipContent {
/// Use the primary tooltip entity with custom [`Text`].
Primary(Text),
/// Use a fully custom entity as the tooltip.
Custom(Entity),
}

impl From<&str> for TooltipContent {
fn from(value: &str) -> Self {
Self::Primary(Text::from_section(value.to_string(), TextStyle::default()))
}
}

impl From<String> for TooltipContent {
fn from(value: String) -> Self {
Self::Primary(Text::from_section(value, TextStyle::default()))
}
}

impl From<TextSection> for TooltipContent {
fn from(value: TextSection) -> Self {
Self::Primary(Text::from_section(value.value, value.style))
}
}

impl From<Vec<TextSection>> for TooltipContent {
fn from(value: Vec<TextSection>) -> Self {
Self::Primary(Text::from_sections(value))
}
}

impl From<Text> for TooltipContent {
fn from(value: Text) -> Self {
Self::Primary(value)
}
}

impl From<Entity> for TooltipContent {
fn from(value: Entity) -> Self {
Self::Custom(value)
}
}

/// A [`SystemSet`] for tooltip systems.
#[derive(SystemSet, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum TooltipSet {
Expand Down

0 comments on commit 5a19163

Please sign in to comment.