<<<<<<< HEAD
univis_ui
A layout engine built on pure ECS using Bevy
🎨 Univis UI
Univis is a "hybrid" (Hybrid) framework for user interfaces in the Bevy engine.
The library acts as a bridge between the ease of traditional 2D UI layouts and the power of 3D world objects. With Univis, you write standard ECS code using Flexbox and Grid layouts, but the result is drawn as meshes supported by SDF technology within the game world.
No pixelation. No separate drawing stages. Just pure Bevy ECS entities.
🧬 The Hybrid Advantage
Univis is designed for developers looking for a development experience (DX) similar to UI libraries, with the visual quality of game meshes.
1. Writing as a User Interface...
Layout is defined using familiar concepts like Padding, Margin, Flex, and Grid.
2. ...Rendered as a 3D Mesh
Behind the scenes, each element is a Mesh2d with a custom SDF shader. This means:
- ✨ Infinite resolution - Sharp edges no matter how close the camera
- 💡 Lighting interaction - Responsive to 3D lighting and effects (Bloom & Glow)
- 🌍 Native world presence - Lives naturally in World Space
- 🦾 Physics interaction - Compatible with RigidBodies and Colliders
- ⚡ Native to Bevy - 100% compatible with ECS
⚡ 100% Native to Bevy and ECS
No "Shadow DOM" or complex external state:
- Entities: Every button, text, or container is a regular Bevy entity
- Components: Layouts through components (
UNode,UBorder,ULayout) - Systems: Layout solving via standard Bevy systems
- Queryable: Querying
&mut UNodejust likeTransform
✨ Key Features
📐 Advanced Layout Engine
A solver system supporting multiple layout styles:
| Style | Description | Ideal Use Case |
|---|---|---|
| Flex | Flexible row/column layout | Lists, bars, traditional layouts |
| Grid | Grid with fixed columns | Image galleries, dashboards |
| Radial | Circular distribution | Weapon lists, sci-fi reactors |
| Masonry | Height-based tiling | Pinterest layouts |
| Stack | Stacking on top of each other | Nested layers |
// Example: Three-column Grid
ULayout
🎨 SDF Rendering
Round corners, soft shadows, and mathematically calculated borders for each pixel with extreme precision:
UNode
🖱️ Built-in Interaction System
Precise picking with meshes:
commands.spawn
.observe;
📝 Automatic Sizing
Text and containers adapt dynamically to content:
UNode
🚀 Quick Start
Installation
[]
= "0.17.3"
= "0.1.0"
Simple Example
use *;
use *;
📂 Examples
The library includes a set of illustrative examples:
# Basic Example
# Dashboard with Grid
# Sci-fi UI with Radial
All examples are available in the examples/ folder in the repository.
🆚 Comparison: Univis vs Bevy UI
| Feature | Bevy UI | Univis UI |
|---|---|---|
| Rendering Technology | Rasterized (blurs in 3D) | SDF Shaders (infinite precision) |
| Space | Screen Space / 2D layer | World Space / 3D objects |
| Lighting | Not lit | Responds to 3D lighting |
| Physics | No interaction | Compatible with Colliders |
| Layout | Flexbox only (Taffy) | Flex + Grid + Radial + Masonry |
| Corners | Uniform | Independent corners |
✅ Univis is suitable for:
- Sci-fi HUDs, holograms, cockpit displays
- Interfaces requiring tilting, rotation, or physics interaction
- Need for sharp and smooth rounded corners even at high zoom levels
- Diegetic UIs (in-world screens)
❌ Bevy UI is better for:
- Traditional main menus, inventory grids, development tools
- Complex scrollable lists (Univis is still working on this)
- Pure 2D interfaces not requiring 3D interaction
⚠️ Project Status: Alpha v0.1.0
Univis is powerful but experimental right now. It's designed for specific use cases (HUDs, in-game screens) and not for building general-purpose complex applications.
| Feature | Status | Notes |
|---|---|---|
| Flex/Grid/Radial Layouts | ✅ Stable | Strong and fast |
| SDF Rendering | ✅ Stable | Infinite precision |
| Text Labels | ✅ Stable | Wrapper around Bevy Text2d |
| Clipping (Scroll Views) | 🚧 In Progress | Work in progress with shader clipping |
| Text Input | 🚧 In Progress | Planned for future updates |
🛠️ Advanced Sizing Modes
Univis supports smart, flexible sizing modes:
// Fixed pixels
Px
// Percentage of parent
Percent // 50%
// Content-based sizing
Content // Based on children
// Auto - fills available space
Auto
// Flexible - takes a share of remaining space
Flex
Example: Flexible Layout
commands.spawn
.with_children;
🌍 UI in 3D Space
Easily create interfaces in 3D space:
commands.spawn
.with_children;
Now the interface:
- ✅ Responds to lighting
- ✅ Can be tilted and rotated
- ✅ Can have Colliders added
- ✅ Renders with high precision from any angle
🎨 Advanced Design
Borders
UBorder
Margins & Padding
all // All sides
axes // Horizontal, Vertical
row // Left and right only
column // Top and bottom only
Absolute Positioning
USelf
🤝 Contributing
Contributions are welcome! Especially in:
- Clipping support (Scroll Views)
- Image support
- Performance improvements
- New examples
To contribute:
- Fork the repository
- Create a feature branch
- Commit changes
- Push and create a pull request
📄 License
Licensed under MIT and Apache 2.0.
🔗 Useful Links
Built with ❤️ for the Bevy Community
⭐ Star on GitHub | 📖 Read the Documentation | 💬 Join the Discussions