Skip to main content

Pairing

Struct Pairing 

Source
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>

Source

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. Different Pairing widgets 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.
Source

pub fn left_label(self, label: impl Into<String>) -> Self

Set the label shown above the left column.

Source

pub fn right_label(self, label: impl Into<String>) -> Self

Set the label shown above the right column.

Source

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.

Source

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.

Source

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.

Source

pub fn show(self, ui: &mut Ui) -> Response

Render the widget and handle interaction.

Trait Implementations§

Source§

impl<'a> Debug for Pairing<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Pairing<'a>

§

impl<'a> RefUnwindSafe for Pairing<'a>

§

impl<'a> Send for Pairing<'a>

§

impl<'a> Sync for Pairing<'a>

§

impl<'a> Unpin for Pairing<'a>

§

impl<'a> UnsafeUnpin for Pairing<'a>

§

impl<'a> !UnwindSafe for Pairing<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.