pub struct Lightning { /* private fields */ }Expand description
A configurable lightning effect for egui.
Lightning paints a jagged bolt plus a full-area flash — the “room lighting
up” — on an egui layer. It maintains its state between frames using egui’s
temporary data storage and never disturbs the host layout.
A strike is episodic: it lives for duration_ms and
flickers through several sub-flashes. Queue one immediately with
strike (the tuned host-triggered path) or let the ambient
scheduler fire on its own through ambient_interval_secs.
Implementations§
Source§impl Lightning
impl Lightning
Sourcepub fn new(id_source: impl Hash + Debug) -> Self
pub fn new(id_source: impl Hash + Debug) -> Self
Creates a new lightning effect with a unique ID.
Sourcepub fn from_settings(
id_source: impl Hash + Debug,
settings: &LightningSettings,
) -> Self
pub fn from_settings( id_source: impl Hash + Debug, settings: &LightningSettings, ) -> Self
Builds a lightning effect from LightningSettings.
Use the same id_source for show and
strike so both address one state.
Sourcepub fn bolt_count(self, bolt_count: usize) -> Self
pub fn bolt_count(self, bolt_count: usize) -> Self
Sets how many bolts a strike draws.
Sourcepub fn branch_depth(self, branch_depth: u32) -> Self
pub fn branch_depth(self, branch_depth: u32) -> Self
Sets the branch recursion depth (0 draws the trunk only).
Sourcepub fn thickness(self, thickness: f32) -> Self
pub fn thickness(self, thickness: f32) -> Self
Sets the bright core stroke thickness in pixels.
Sourcepub fn jitter(self, jitter: f32) -> Self
pub fn jitter(self, jitter: f32) -> Self
Sets the midpoint-displacement jitter as a fraction of segment length.
Sourcepub fn flash_intensity(self, intensity: f32) -> Self
pub fn flash_intensity(self, intensity: f32) -> Self
Sets the peak alpha of the full-area flash in 0.0..=1.0.
Sourcepub fn duration_ms(self, duration_ms: f32) -> Self
pub fn duration_ms(self, duration_ms: f32) -> Self
Sets the strike duration in milliseconds.
Sourcepub fn ambient_interval_secs(self, secs: f32) -> Self
pub fn ambient_interval_secs(self, secs: f32) -> Self
Sets the ambient interval in seconds (0.0 disables the scheduler).
Sourcepub fn on_foreground(self) -> Self
pub fn on_foreground(self) -> Self
Places the lightning on the Foreground layer.
Sourcepub fn on_background(self) -> Self
pub fn on_background(self) -> Self
Places the lightning on the Background layer.
Sourcepub fn layer(self, layer_id: LayerId) -> Self
pub fn layer(self, layer_id: LayerId) -> Self
Provides full control over the rendering layer.
This overrides on_top, on_foreground, and on_background.
Sourcepub fn area(self, area: Rect) -> Self
pub fn area(self, area: Rect) -> Self
Restricts the lightning effect to a specific area.
If not set, it defaults to ctx.content_rect().
Sourcepub fn strike(self, ctx: &Context)
pub fn strike(self, ctx: &Context)
Queues a strike immediately and requests a repaint.
This is the host-triggered path; Lightning::from_settings(id, &settings).strike(ctx)
is the tuned one. strike uses the same id_source as show,
so both must be constructed with the same id for the queued strike to be
painted. A degenerate area is a no-op.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Lightning
impl RefUnwindSafe for Lightning
impl Send for Lightning
impl Sync for Lightning
impl Unpin for Lightning
impl UnsafeUnpin for Lightning
impl UnwindSafe for Lightning
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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