egui-map
An egui widget that renders an interactive 2D map and displays information about it.
Features
- Pan with click & drag, and zoom with the mouse wheel (hold
Ctrl— orCmdon macOS — to zoom faster) or the built-in slider. - Spatial indexing via kd-tree: only the nodes inside the viewport are painted each frame.
- Node names with configurable visibility rules (always / on hover / hidden).
- Connection lines between nodes and free-floating text labels.
- Pulsing notification effects and blinking markers attached to nodes.
- Custom node rendering and right-click context menus through the
NodeTemplateandContextMenuManagertraits. - Built-in light and dark themes, customizable through
MapSettings.
Usage
Add the dependency:
[]
= "0.0"
Feed the map a set of nodes and add it to your UI:
use Map;
use ;
use HashMap;
// Build the node set, keyed by node id.
let mut points: = new;
points.insert;
points.insert;
let mut map = new;
map.add_hashmap_points;
// Then, on every frame of your egui update loop:
// ui.add(&mut map);
Connecting nodes with lines
Lines are wired in three steps: create the nodes, register a unique connection id in the connections of both endpoints, and load the line geometry keyed by that same id:
use ;
use HashMap;
let mut points: = new;
points.insert;
points.insert;
// Register the connection id on both endpoints.
for id in
map.add_hashmap_points;
// Line geometry, keyed by the same connection id.
let mut lines: = new;
lines.insert;
map.add_lines;
A line is only drawn while the zoom level is above MapSettings::line_visible_zoom and at least one of its endpoints is inside the viewport.
Custom node rendering and animations
Implement NodeTemplate to take over how nodes, selection highlights, notifications and markers are drawn — including the name labels, which the widget no longer paints once a template is installed:
use ;
use ;
use Instant;
;
map.set_node_template;
See the NodeTemplate rustdoc for a complete example with a custom node shape and an animated notification.
Crate features
puffin: instruments the widget's hot paths with thepuffinprofiler.
License
MIT. See LICENSE.md.