Skip to main content

NumberlinkWidget

Struct NumberlinkWidget 

Source
pub struct NumberlinkWidget<'a> { /* private fields */ }
Expand description

An egui widget that renders an interactive Numberlink board.

Press and drag from either of a number’s two endpoints (both are always live, symmetrically — grabbing one always starts fresh from there, even if the path was originally drawn from the other end) to draw/redraw its path. Grabbing an interior cell of an already-drawn path instead truncates it to that point. Dragging back over the path’s own previous cell retracts it by one; dragging onto a different number’s path is rejected. A plain click (no drag) on an endpoint or path cell clears/ starts the path immediately, without needing to drag at all.

ⓘ
ui.add(egui_numberlink::NumberlinkWidget::new(&mut game));

Implementations§

Source§

impl<'a> NumberlinkWidget<'a>

Source

pub fn new(game: &'a mut NumberlinkGame) -> Self

Source

pub fn cell_size(self, size: f32) -> Self

Override the size (in logical pixels) of each grid cell. When not set, the cell size is computed automatically to fill the available space of the parent container.

Source

pub fn colors(self, colors: &'a [Color32]) -> Self

Per-number color, indexed by number (colors[number % colors.len()]) — the customization point for embedding apps that want to reskin the board. Defaults to DEFAULT_COLORS, a colorblind-safe palette.

§Panics

Panics if colors is empty.

Source

pub fn show_numbers(self, show: bool) -> Self

Whether each number’s digit is drawn on its two endpoint markers. Defaults to true — this is what keeps the board reading as Numberlink (numbers are the primary identifier) rather than a colors-only clone; color is a skin on top, not a replacement.

Source

pub fn win_message(self, message: impl Into<String>) -> Self

Message shown in the win banner drawn over the board once GameStatus::Won is reached. Defaults to "Solved!".

Source

pub fn interactive(self, interactive: bool) -> Self

Whether the widget responds to drags at all. Set to false to render the board read-only. Defaults to true.

Trait Implementations§

Source§

impl Widget for NumberlinkWidget<'_>

Source§

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

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

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

§

impl<'a> Freeze for NumberlinkWidget<'a>

§

impl<'a> RefUnwindSafe for NumberlinkWidget<'a>

§

impl<'a> Send for NumberlinkWidget<'a>

§

impl<'a> Sync for NumberlinkWidget<'a>

§

impl<'a> Unpin for NumberlinkWidget<'a>

§

impl<'a> UnsafeUnpin for NumberlinkWidget<'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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

fn simd_from(_simd: S, value: T) -> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.