pub struct Shadow { /* private fields */ }Expand description
A configurable shadow that can be rendered behind a Block.
A Shadow is rendered in an offset area relative to the block. Its Style is applied
first, then an optional cell effect can modify the affected cells, for example by filling them
with a shading symbol or dimming the existing background.
Built-in presets:
Shadow::overlayapplies only styleShadow::blockfills with full block symbolsShadow::light_shade,Shadow::medium_shade, andShadow::dark_shadefill with shade symbols
┌Popup─────┐
│content │▒
└──────────┘▒
▒▒▒▒▒▒▒▒▒▒▒§Custom effects
use ratatui::buffer::Buffer;
use ratatui::layout::{Position, Rect};
use ratatui::widgets::{Block, CellEffect, Shadow};
#[derive(Debug)]
struct Checker;
impl CellEffect for Checker {
fn apply(&self, shadow_area: Rect, base_area: Rect, buf: &mut Buffer) {
for y in shadow_area.top()..shadow_area.bottom() {
for x in shadow_area.left()..shadow_area.right() {
if base_area.contains(Position { x, y }) {
continue;
}
if (x + y) % 2 == 0 {
buf[(x, y)].set_symbol("░");
}
}
}
}
}
let shadow = Shadow::custom(Checker);
let block = Block::bordered().shadow(shadow);Implementations§
Source§impl Shadow
impl Shadow
Sourcepub fn overlay() -> Self
pub fn overlay() -> Self
Creates a shadow that only applies style to the offset area.
This leaves the existing cell symbols unchanged.
§Example
use ratatui::style::Stylize;
use ratatui::widgets::{Block, Shadow};
let shadow = Shadow::overlay().black().on_white();
let block = Block::bordered().shadow(shadow);Sourcepub fn block() -> Self
pub fn block() -> Self
Creates a shadow filled with full block symbols.
§Example
use ratatui::widgets::{Block, Shadow};
let block = Block::bordered().shadow(Shadow::block());Sourcepub fn light_shade() -> Self
pub fn light_shade() -> Self
Creates a shadow filled with light shade symbols.
§Example
use ratatui::widgets::{Block, Shadow};
let block = Block::bordered().shadow(Shadow::light_shade());Sourcepub fn medium_shade() -> Self
pub fn medium_shade() -> Self
Creates a shadow filled with medium shade symbols.
§Example
use ratatui::widgets::{Block, Shadow};
let block = Block::bordered().shadow(Shadow::medium_shade());Sourcepub fn dark_shade() -> Self
pub fn dark_shade() -> Self
Creates a shadow filled with dark shade symbols.
§Example
use ratatui::layout::Offset;
use ratatui::style::Stylize;
use ratatui::widgets::{Block, Shadow};
let block = Block::bordered().shadow(
Shadow::dark_shade()
.black()
.on_white()
.offset(Offset::new(2, 1)),
);Sourcepub fn symbol(symbol: &'static str) -> Self
pub fn symbol(symbol: &'static str) -> Self
Creates a shadow filled with the given symbol.
§Example
use ratatui::widgets::{Block, Shadow};
let shadow = Shadow::symbol("░");
let block = Block::bordered().shadow(shadow);Sourcepub fn custom<F: CellEffect + 'static>(effect: F) -> Self
pub fn custom<F: CellEffect + 'static>(effect: F) -> Self
Creates a new shadow from a custom cell effect.
The effect receives the shadow area, the original block area, and the target buffer. It is called after the shadow style has been applied.
Sourcepub fn new<F: CellEffect + 'static>(effect: F) -> Self
pub fn new<F: CellEffect + 'static>(effect: F) -> Self
Creates a new shadow from a custom cell effect.
Alias for Shadow::custom.
Trait Implementations§
impl Eq for Shadow
Auto Trait Implementations§
impl !RefUnwindSafe for Shadow
impl !Send for Shadow
impl !Sync for Shadow
impl !UnwindSafe for Shadow
impl Freeze for Shadow
impl Unpin for Shadow
impl UnsafeUnpin for Shadow
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T, U> Stylize<'_, T> for Uwhere
U: Styled<Item = T>,
impl<T, U> Stylize<'_, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
Source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta.Source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray.Source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red.Source§fn light_green(self) -> T
fn light_green(self) -> T
light_green.Source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green.Source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow.Source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow.Source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue.Source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue.Source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta.Source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta.Source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan.Source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan.Source§fn not_italic(self) -> T
fn not_italic(self) -> T
italic modifier.Source§fn underlined(self) -> T
fn underlined(self) -> T
underlined modifier.Source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
underlined modifier.Source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
slow_blink modifier.Source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
slow_blink modifier.Source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
rapid_blink modifier.Source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
rapid_blink modifier.Source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
reversed modifier.hidden modifier.hidden modifier.Source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
crossed_out modifier.Source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
crossed_out modifier.