pub struct Pairing<'a> { /* private fields */ }Expand description
A widget that lets users connect items in two lists with 1:1 pairings, drawn as bezier curves between ports on each node.
§Interaction
- Click a port to enter pairing mode — a dashed ghost line follows the cursor.
- Click an opposite-side port to complete the pairing. If that target was already paired, its previous pairing is broken first (swap).
- Hover an opposite-side node while pairing and the ghost line latches to that node’s port.
- Click a paired node to break its connection and immediately start a new pairing from it, so reconnecting is a single click.
- Click a pair’s line to remove it.
- Escape or click the background cancels a pending selection.
§State
Pairings are stored in the caller-owned Vec<(String, String)> passed to
Pairing::new. Each element is (left_id, right_id). The transient
selection state is stored in egui memory keyed by the widget’s id_salt.
§Limits
Each side supports up to 64 items. Exceeding this panics — the widget
uses fixed-size stack buffers for zero-allocation layout. For larger
data sets, split the lists across multiple Pairing widgets.
§Example
let clients = vec![
PairItem::new("c1", "worker-pool-a").detail("24 instances"),
PairItem::new("c2", "edge-proxy-01").detail("8 instances"),
];
let servers = vec![
PairItem::new("s1", "api-east-01").detail("10.0.1.5 · us-east"),
PairItem::new("s2", "api-west-01").detail("10.0.2.4 · us-west"),
];
let mut pairs: Vec<(String, String)> = vec![];
Pairing::new("client-server", &clients, &servers, &mut pairs)
.left_label("Clients")
.right_label("Servers")
.show(ui);Implementations§
Source§impl<'a> Pairing<'a>
impl<'a> Pairing<'a>
Sourcepub fn new(
id_salt: impl Hash,
left: &'a [PairItem],
right: &'a [PairItem],
pairs: &'a mut Vec<(String, String)>,
) -> Self
pub fn new( id_salt: impl Hash, left: &'a [PairItem], right: &'a [PairItem], pairs: &'a mut Vec<(String, String)>, ) -> Self
Create a new pairing widget.
id_salt— a stable salt for this widget’s memory state. DifferentPairingwidgets on the same window must use distinct salts.left,right— items shown in each column.pairs— the caller-owned list of(left_id, right_id)tuples. It is mutated when the user creates or removes a pairing.
Sourcepub fn left_label(self, label: impl Into<String>) -> Self
pub fn left_label(self, label: impl Into<String>) -> Self
Set the label shown above the left column.
Sourcepub fn right_label(self, label: impl Into<String>) -> Self
pub fn right_label(self, label: impl Into<String>) -> Self
Set the label shown above the right column.
Sourcepub fn height(self, height: f32) -> Self
pub fn height(self, height: f32) -> Self
Override the total widget height. By default the widget sizes itself to fit the longer of the two columns.
Sourcepub fn align_left(self) -> Self
pub fn align_left(self) -> Self
Auto-arrange the left column so every pairing renders as a straight horizontal line. The right column keeps its caller-given order; unpaired items on the left fill the remaining slots in input order.
Sourcepub fn align_right(self) -> Self
pub fn align_right(self) -> Self
Auto-arrange the right column so every pairing renders as a straight horizontal line. The left column keeps its caller-given order; unpaired items on the right fill the remaining slots in input order.