pub struct RhythmOverlay { /* private fields */ }gpui only.Expand description
A draw-rhythms debug overlay: every other grid row in one color.
Place it as the last child of the container it should cover; it fills that
container and ignores mouse events. An ordinary gpui container already uses
relative positioning by default, so no extra .relative() call is needed,
and this element does not alter the container’s position style.
The stripes start at the container’s top edge. If the content scrolls a
container, put the overlay inside the scrolled wrapper so the grid moves
with the text; a renderer that scrolls by painting content at a computed
signed Y offset instead passes that same offset to phase.
Either way only rows intersecting the visible region (the current content
mask) are painted, and each is clipped to the overlay’s own bounds, so
covering a document far taller than the viewport costs
O(viewport height / grid size) per frame and never paints outside the
container it covers. Custom elements whose offset settles during prepaint
can call paint with a freshly phased value during their
paint stage instead of capturing stale state during render.
Implementations§
Source§impl RhythmOverlay
impl RhythmOverlay
Sourcepub fn phase(self, offset: Pixels) -> Self
pub fn phase(self, offset: Pixels) -> Self
Translate the stripes by the same signed Y offset used to paint the
content, for renderers that scroll without moving a scroll container.
A negative offset moves both content and grid origin above the
element; a positive offset moves them below it. In particular,
ScrollHandle::offset().y can be passed through directly.
This has the effect of translating the overlay with the content — without a wrapper element, and without an ancestor to clip it, since stripes are clipped to the overlay’s own bounds.
§Panics
Panics when offset is not finite.
Sourcepub fn paint(&self, bounds: Bounds<Pixels>, window: &mut Window)
pub fn paint(&self, bounds: Bounds<Pixels>, window: &mut Window)
Paint the configured stripes directly into window within bounds.
This is the paint-stage counterpart to using the overlay as an element.
It is intended for custom renderers whose signed content translation is
not final until another element’s prepaint has settled layout. Read that
application-owned value during paint, apply it to a temporary overlay
with phase, then call this method; the crate stores no
callback or mutable scroll state.
bounds takes the covered container’s role, which the element form
fills in from the parent: stripe row 0 starts at bounds.origin.y plus
the phase, and nothing paints outside the box. The
current content mask is applied exactly as for the element form, and
only visible stripes are visited. Call this after painting the content
the stripes should cover.
use gpui::{Bounds, Pixels, Window, px, rgba};
use rhythm_gpui::RhythmGrid;
fn paint_grid(
bounds: Bounds<Pixels>,
content_offset_y: Pixels,
window: &mut Window,
) {
RhythmGrid::new(px(8.))
.overlay(rgba(0xff78783f))
.phase(content_offset_y)
.paint(bounds, window);
}Trait Implementations§
Source§impl From<RhythmGrid> for RhythmOverlay
A bare grid converts to its default debug appearance — the classic
translucent red (0xff78783f), zero phase — which is what lets
RhythmStyled::rhythm_debug_overlay accept the grid directly.
impl From<RhythmGrid> for RhythmOverlay
A bare grid converts to its default debug appearance — the classic
translucent red (0xff78783f), zero phase — which is what lets
RhythmStyled::rhythm_debug_overlay accept the grid directly.
Source§fn from(grid: RhythmGrid) -> Self
fn from(grid: RhythmGrid) -> Self
Source§impl IntoElement for RhythmOverlay
impl IntoElement for RhythmOverlay
Source§type Element = Component<RhythmOverlay>
type Element = Component<RhythmOverlay>
Source§fn into_element(self) -> Self::Element
fn into_element(self) -> Self::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl RenderOnce for RhythmOverlay
impl RenderOnce for RhythmOverlay
Source§fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement
Render::render() method
which takes a mutable reference.Auto Trait Implementations§
impl Freeze for RhythmOverlay
impl RefUnwindSafe for RhythmOverlay
impl Send for RhythmOverlay
impl Sync for RhythmOverlay
impl Unpin for RhythmOverlay
impl UnsafeUnpin for RhythmOverlay
impl UnwindSafe for RhythmOverlay
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
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
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
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 more