#bevy-ui #bevy-plugin #ui

bevy_ui_anchor

A small bevy plugin for anchoring UI elements to specific points or entities in the world

19 releases (8 breaking)

0.10.0 Oct 1, 2025
0.8.0 Aug 5, 2025
0.7.1 Jul 1, 2025
0.5.1 Mar 20, 2025
0.3.0 Nov 30, 2024

#931 in Game dev

Download history 78/week @ 2025-10-03 59/week @ 2025-10-10 93/week @ 2025-10-17 70/week @ 2025-10-24 62/week @ 2025-10-31 57/week @ 2025-11-07 28/week @ 2025-11-14 25/week @ 2025-11-21 13/week @ 2025-11-28 3/week @ 2025-12-05 35/week @ 2025-12-12 39/week @ 2025-12-19 18/week @ 2025-12-26 30/week @ 2026-01-02 78/week @ 2026-01-09 82/week @ 2026-01-16

212 downloads per month

MIT license

3MB
273 lines

bevy_ui_anchor

crates.io docs.rs License

A Rust crate for anchoring UI elements to specific points or entities in the world using the Bevy game engine.

Features

Provides an AnchorUiNode component that:

  • Anchor UI nodes to world positions or entities.
  • Supports horizontal and vertical anchoring.
  • Compatible with Bevy's ECS architecture.
Bevy version Crate version
0.17 0.10
0.16 0.6 - 0.9
0.15 0.3 - 0.5
0.14 0.1 - 0.2

Example

//! Demonstrates how to work with Cubic curves.
use bevy::{
    color::palettes::css::{ORANGE, SILVER, WHITE},
    prelude::*,
};

use bevy_ui_anchor::{AnchorPoint, AnchorUiConfig, AnchorUiPlugin, AnchoredUiNodes};

#[derive(Component)]
/// We need a marker for the camera, so the plugin knows which camera to perform position
/// calculations towards
pub struct UiCameraMarker;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        // We need to define, which camera the anchorplugin will be anchored to
        .add_plugins(AnchorUiPlugin::<UiCameraMarker>::new())
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    // The camera
    commands.spawn((
        // mark it
        UiCameraMarker,
        IsDefaultUiCamera,
        Camera3d::default(),
        Transform::from_xyz(0., 6., 12.).looking_at(Vec3::new(0., 3., 0.), Vec3::Y),
        DirectionalLight::default(),
    ));

    // Spawning a cube with anchored UI, using bevy relations
    commands.spawn((
        Mesh3d(meshes.add(Cuboid::new(0.3, 0.3, 0.3))),
        MeshMaterial3d(materials.add(Color::from(ORANGE))),
        Transform::from_translation([0.0, 0.5, 0.0].into()),
        // Define the anchor relationship
        AnchoredUiNodes::spawn_one((
            AnchorUiConfig {
                anchorpoint: AnchorPoint::bottomleft(),
                offset: Some(Vec3::new(0.0, 0.5, 0.0)),
                ..Default::default()
            },
            Node {
                border: UiRect::all(Val::Px(2.)),
                ..Default::default()
            },
            BorderColor::all(WHITE),
            BorderRadius::all(Val::Px(2.)),
            Outline::default(),
            Children::spawn_one(
                // text
                Text("Text Anchored in bottom left".into()),
            ),
        )),
    ));

    // ground plane
    commands.spawn((
        Mesh3d(meshes.add(Plane3d::default().mesh().size(50., 50.))),
        MeshMaterial3d(materials.add(Color::from(SILVER))),
    ));
}

Dependencies

~58–77MB
~1.5M SLoC