pub struct WindowStateDetector { /* private fields */ }Expand description
Tracks the current WindowState based on incoming winit WindowEvents.
The detector maps raw winit events to high-level window states and exposes
helpers for render-loop decisions ([should_render], [control_flow]).
§Usage
use cvkg_render_native::{WindowStateDetector, WindowState};
let mut detector = WindowStateDetector::new();
// In your event loop:
// if let Some(new_state) = detector.update_from_event(&event) { ... }Implementations§
Source§impl WindowStateDetector
impl WindowStateDetector
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new detector initialized to WindowState::Normal.
Sourcepub fn state(&self) -> WindowState
pub fn state(&self) -> WindowState
Returns the current window state.
Sourcepub fn update_from_event(&mut self, event: &WindowEvent) -> Option<WindowState>
pub fn update_from_event(&mut self, event: &WindowEvent) -> Option<WindowState>
Updates the internal state based on a winit WindowEvent.
Returns Some(WindowState) if the state changed, None otherwise.
§State mapping
| winit event | resulting state |
|---|---|
Occluded(true) | Occluded |
Focused(true) | updates is_key; checks fullscreen |
Focused(false) | updates is_key |
| Default | Normal |
Note: Minimized and Fullscreen detection requires querying the
winit Window directly (see [update_from_window]).
Sourcepub fn update_from_window(&mut self, window: &Window) -> Option<WindowState>
pub fn update_from_window(&mut self, window: &Window) -> Option<WindowState>
Updates the state by querying the winit Window directly.
This should be called once per frame to detect states that winit does not emit as events (minimized, fullscreen).
Returns Some(WindowState) if the state changed, None otherwise.
Sourcepub fn should_render(&self) -> bool
pub fn should_render(&self) -> bool
Returns true if the window should render a frame in the current state.
Returns false for WindowState::Occluded, WindowState::Minimized,
and WindowState::Hidden.
Sourcepub fn control_flow(&self) -> ControlFlow
pub fn control_flow(&self) -> ControlFlow
Returns the appropriate ControlFlow for the current state.
Non-rendering states get ControlFlow::Wait (save CPU cycles);
rendering states get ControlFlow::Poll for maximum responsiveness.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WindowStateDetector
impl RefUnwindSafe for WindowStateDetector
impl Send for WindowStateDetector
impl Sync for WindowStateDetector
impl Unpin for WindowStateDetector
impl UnsafeUnpin for WindowStateDetector
impl UnwindSafe for WindowStateDetector
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> 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
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().