Crate bevy_nested_tooltips

Crate bevy_nested_tooltips 

Source
Expand description

§Bevy Nested Tooltips

§Features

This library strives to handle the logic behind common tooltip features, while you focus on your unique data and design needs.

  • Tooltips can be spawned by hovering or by user pressing the middle mouse button, your choice which and you can change at runtime.
  • Nesting to arbitrary levels, the only limitation is memory.
  • Despawns if the user hasn’t interacted with them in a configurable time period, or they mouse away after interacting with them.
  • Locking by pressing of the middle mouse button. using observers you can implement your specific design to inform your users.
  • Highlight other Entites using a linked text, highlight designs are up to you.

§Usage

§Import the prelude

use bevy_nested_tooltips::prelude::*;

§Add the plugin

        .add_plugins((
            NestedTooltipPlugin,
        ))

§(Optional) Configure tooltips

    commands.insert_resource(TooltipConfiguration {
        activation_method: ActivationMethod::MiddleMouse,
        ..Default::default()
    });

§Load your tooltips

    let mut tooltip_map = TooltipMap {
        map: HashMap::new(),
    };

    tooltip_map.insert(
        "tooltip".into(),
        ToolTipsData::new(
            "ToolTip",
            vec![
                TooltipsContent::String("A way to give users infomation can be ".into()),
                TooltipsContent::Term("recursive".into()),
                TooltipsContent::String(" Press middle mouse button to lock me. ".into()),
            ],
        ),
    );

    tooltip_map.insert(
        "recursive".into(),
        ToolTipsData::new(
            "Recursive",
            vec![
                TooltipsContent::String("Tooltips can be ".into()),
                TooltipsContent::Term("recursive".into()),
                TooltipsContent::String(
                    " You can highlight specific ui panels with such as the ".into(),
                ),
                TooltipsContent::Highlight("sides".into()),
                TooltipsContent::String(" Press middle mouse button to lock me. ".into()),
            ],
        ),
    );
TooltipHighlight("sides".into()),

Or

 TooltipTermLink::new("tooltip"),

§Style your tooltips

Create an observer with at least these parameters.

fn style_tooltip(
    new_tooltip: On<TooltipSpawned>,
    tooltip_info: TooltipEntitiesParam,
    mut commands: Commands,
)

Fetch the data.

    let tooltip_info = tooltip_info
        .tooltip_child_entities(new_tooltip.entity)
        .unwrap();

Use the entities to style your node using commands or mutatable queries!

    commands
        .get_entity(tooltip_info.title_node)
        .unwrap()
        .insert(Node {
            display: Display::Flex,
            justify_content: JustifyContent::Center,
            width: Val::Percent(100.),
            ..Default::default()
        });
§React to changes.
// When highlighted change the colour, how you highlight is up to you
// maybe fancy animations
fn add_highlight(side: On<Add, TooltipHighlighting>, mut commands: Commands) {
    commands
        .get_entity(side.entity)
        .unwrap()
        .insert(BackgroundColor(GREEN.into()));
}

// remove highlighting
fn remove_highlight(side: On<Remove, TooltipHighlighting>, mut commands: Commands) {
    commands
        .get_entity(side.entity)
        .unwrap()
        .insert(BackgroundColor(BLUE.into()));
}

Modules§

events
The events that are intended to be read by the user to react to are stored here.
highlight
Highlighting logic and components are stored here. What highlighting actually does is up to the user.
layout
Components you can query or observer in order to change appearance of the tooltips, can be used in queries when obeserving the crate::TooltipSpawned event.
prelude
An easy way to import commonly used types.
query
Contains the convenienece queries and systemparams to easily get the entities for each part of a single crate::Tooltip.
term
Terms is how tooltips find out what to display given a word to link.
text_observer
TextSpan’s do not currently support observers so this file is here to read hovers on text and to narrow it down to the actual textspan.

Structs§

NestedTooltipPlugin
This plugin adds systems and resources that makes the logic work.
Tooltip
Indicates this entity is a tooltip and stores what spawned it The entity that spawned it is blocked from spawning another tooltip until this one is finished to prevent tooltip jumping around.
TooltipConfiguration
Resource that configures the behaviour of tooltips.
TooltipLinkTimer
Timer added on creating a Tooltip, if the user does not mouseover the tooltip in that time then it will be despawned.
TooltipMap
The data of your tooltips. When a TooltipTermLink is activated the string inside of it will be used as key for the hashmap and its result will populate the tooltip.
TooltipReference
Default node for the Tooltip node use this to layout your tooltips without accidentally moving it’s position. This resource is initialised on adding plugin.
TooltipSpawned
This is sent when a Tooltip is spawned.
TooltipWaitForHover
If the user hasn’t hovered on the tooltip in the specified time despawn it time is configured in TooltipConfiguration.
TooltipsData
What is to be included in the Tooltip.
TooltipsNested
Tooltip that spawned nested from this one.
TooltipsNestedOf
This Tooltip is nested under the entities Tooltip.

Enums§

ActivationMethod
How a tooltip is triggered by default this is done via hovering Hovering can be further customised.
TooltipsContent
This makes up a part of the tooltips text content. Each variant outputs text but with different behaviours See each variants documenation for details.