Skip to main content

Lightning

Struct Lightning 

Source
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

Source

pub fn new(id_source: impl Hash + Debug) -> Self

Creates a new lightning effect with a unique ID.

Source

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.

Source

pub fn color(self, color: Color32) -> Self

Sets the bolt and flash color.

Source

pub fn bolt_count(self, bolt_count: usize) -> Self

Sets how many bolts a strike draws.

Source

pub fn branch_depth(self, branch_depth: u32) -> Self

Sets the branch recursion depth (0 draws the trunk only).

Source

pub fn thickness(self, thickness: f32) -> Self

Sets the bright core stroke thickness in pixels.

Source

pub fn jitter(self, jitter: f32) -> Self

Sets the midpoint-displacement jitter as a fraction of segment length.

Source

pub fn flash_intensity(self, intensity: f32) -> Self

Sets the peak alpha of the full-area flash in 0.0..=1.0.

Source

pub fn duration_ms(self, duration_ms: f32) -> Self

Sets the strike duration in milliseconds.

Source

pub fn ambient_interval_secs(self, secs: f32) -> Self

Sets the ambient interval in seconds (0.0 disables the scheduler).

Source

pub fn on_top(self) -> Self

Places the lightning on the Debug layer (on top of everything).

Source

pub fn on_foreground(self) -> Self

Places the lightning on the Foreground layer.

Source

pub fn on_background(self) -> Self

Places the lightning on the Background layer.

Source

pub fn layer(self, layer_id: LayerId) -> Self

Provides full control over the rendering layer.

This overrides on_top, on_foreground, and on_background.

Source

pub fn area(self, area: Rect) -> Self

Restricts the lightning effect to a specific area.

If not set, it defaults to ctx.content_rect().

Source

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.

Source

pub fn show(self, ctx: &Context)

Updates and renders the lightning effect.

Call this every frame. While a strike animates it requests a repaint; when idle it requests nothing (ambient off) or wakes exactly for the next ambient strike, so an idle effect costs the host no frames.

Trait Implementations§

Source§

impl Debug for Lightning

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<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.