Skip to main content

Shimmer

Struct Shimmer 

Source
pub struct Shimmer { /* private fields */ }
Expand description

A brightness crest sweeping across one line of cells.

Pure phase arithmetic on the shared clock, like a gradient spin: the crest travels a track padded on both sides so it fully enters and exits the text instead of popping at an edge, then wraps and sweeps again. Cells away from the crest keep the authored style, its shoulders brighten, and the peak lifts further and paints bold. <text> consumes this declaratively through the shimmer property — see crate::Props::shimmer.

Implementations§

Source§

impl Shimmer

Source

pub fn new(now: Duration, period: Duration, length: u16) -> Self

Places the crest at now: one sweep across length cells (plus runway) per period.

Examples found in repository?
examples/footers.rs (line 508)
503fn draw_working(frame: &mut Frame, x: u16, y: u16, scene: &Scene) {
504	let hint = scene.charset.icon(Icon::Cancellable);
505	let length = width_of(hint)
506		.saturating_add(1)
507		.saturating_add(width_of(WORKING));
508	let shimmer = Shimmer::new(scene.elapsed, SHIMMER_PERIOD, length);
509	let mut column = x;
510	draw_shimmer(frame, &mut column, x, y, scene.right_edge(), hint, shimmer, ink(CYAN));
511	draw_shimmer(frame, &mut column, x, y, scene.right_edge(), " ", shimmer, ink(GREEN));
512	draw_shimmer(frame, &mut column, x, y, scene.right_edge(), WORKING, shimmer, ink(GREEN));
513}
514
515/// The pi flavor of the working line: the spinner and timer lead, then
516/// the shimmering narration — the band below carries no brand segment.
517fn draw_working_spin(frame: &mut Frame, x: u16, y: u16, scene: &Scene) {
518	let mut column = frame.put(x, y, scene.spinner(), ink(GREEN));
519	column = frame.put(column, y, " ", ink(GREEN));
520	column = frame.put(column, y, &scene.timer(), ink(MUTED));
521	column = frame.put(column, y, " ", ink(MUTED));
522	let shimmer = Shimmer::new(scene.elapsed, SHIMMER_PERIOD, width_of(WORKING));
523	let start = column;
524	draw_shimmer(frame, &mut column, start, y, scene.right_edge(), WORKING, shimmer, ink(GREEN));
525}
More examples
Hide additional examples
examples/chat/demo.rs (line 1366)
1355	fn draw_working(frame: &mut Frame, y: u16, elapsed: Duration, hint: &str) {
1356		if y >= frame.size().height || frame.size().width < 4 {
1357			return;
1358		}
1359		let start = u16::from(frame.size().width >= 50);
1360		let mut column = start;
1361		let length = xutf::graphemes_str(WORKING_MESSAGE)
1362			.count()
1363			.saturating_add(xutf::graphemes_str(hint).count())
1364			.saturating_add(1);
1365		let length = u16::try_from(length).unwrap_or(u16::MAX);
1366		let shimmer = Shimmer::new(elapsed, SHIMMER_PERIOD, length);
1367		let right = frame.size().width.saturating_sub(1);
1368		draw_shimmer(frame, &mut column, start, y, right, hint, shimmer, ink(CYAN));
1369		draw_shimmer(frame, &mut column, start, y, right, " ", shimmer, ink(GREEN));
1370		draw_shimmer(frame, &mut column, start, y, right, WORKING_MESSAGE, shimmer, ink(GREEN));
1371	}
Source

pub fn pick<T>(&self, cell: u16, low: T, mid: T, high: T) -> T

Picks one of three values by crest intensity at cell (zero-based from the text start): low off the crest, mid on its shoulders, high at the peak. The seam for custom palettes — Shimmer::style_at is this with the dim/base/bold derivation.

Examples found in repository?
examples/chat/demo.rs (line 111)
97fn draw_shimmer(
98	frame: &mut Frame,
99	column: &mut u16,
100	start: u16,
101	y: u16,
102	right: u16,
103	text: &str,
104	shimmer: Shimmer,
105	high: Style,
106) {
107	for grapheme in xutf::graphemes_str(text) {
108		if *column >= right {
109			return;
110		}
111		let style = shimmer.pick(*column - start, ink(FAINT), ink(MUTED), high);
112		let next = frame.put(*column, y, grapheme, style);
113		if next == *column {
114			return;
115		}
116		*column = next;
117	}
118}
More examples
Hide additional examples
examples/footers.rs (line 544)
530fn draw_shimmer(
531	frame: &mut Frame,
532	column: &mut u16,
533	start: u16,
534	y: u16,
535	right: u16,
536	text: &str,
537	shimmer: Shimmer,
538	high: Style,
539) {
540	for grapheme in xutf::graphemes_str(text) {
541		if *column >= right {
542			return;
543		}
544		let style = shimmer.pick(*column - start, ink(FAINT), ink(MUTED), high);
545		let next = frame.put(*column, y, grapheme, style);
546		if next == *column {
547			return;
548		}
549		*column = next;
550	}
551}
Source

pub fn style_at(&self, cell: u16, base: Style) -> Style

The style for cell (zero-based from the text start). Shimmer is additive: base rests unchanged off the crest, so a shimmering line matches its non-shimmering appearance except under the sweep. An RGB foreground lifts one-fifth toward white on the shoulders and two-fifths plus bold at the peak; a default or indexed foreground carries no channel data, so only the peak’s bold shows.

Trait Implementations§

Source§

impl Clone for Shimmer

Source§

fn clone(&self) -> Shimmer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Shimmer

Source§

impl Debug for Shimmer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.