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
impl Shimmer
Sourcepub fn new(now: Duration, period: Duration, length: u16) -> Self
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?
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
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 }Sourcepub fn pick<T>(&self, cell: u16, low: T, mid: T, high: T) -> T
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?
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
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}Sourcepub fn style_at(&self, cell: u16, base: Style) -> Style
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§
Auto Trait Implementations§
impl Freeze for Shimmer
impl RefUnwindSafe for Shimmer
impl Send for Shimmer
impl Sync for Shimmer
impl Unpin for Shimmer
impl UnsafeUnpin for Shimmer
impl UnwindSafe for Shimmer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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