pub struct RhythmFrame { /* private fields */ }gpui only.Expand description
A container that fits fluid-width media — images, video, embeds, any content whose height follows its width instead of the rhythm — into a whole number of rhythm rows, so everything after it stays on the grid at any width.
The frame fills the parent’s width; its height is the content’s natural
height (width / ratio) snapped to whole rhythm rows, recomputed in the
layout pass whenever the width changes. ratio is width over height,
matching gpui img’s aspect-ratio convention. Content lives in a box at
its natural height: pinned to the frame’s top edge when padding, and
centered behind the frame’s clipping mask when cropping. Style the child
to fill it (.size_full(), plus .object_fit(ObjectFit::Cover) when the
image itself has a different ratio). The box reserves its height even
before an image loads — no layout shift.
By default the height rounds up and the leftover space — always under
one rhythm unit — is left below the content (pad). Choose the mode with
RhythmFrame::fit, or RhythmFrame::crop for the shorthand.
With a known width the frame is unnecessary — size the block directly
with RhythmGrid::snap_up.
The frame needs a parent that offers a definite width: a height that follows the width is unknowable under an intrinsic (min-/max-content) measurement, so the frame reports no size in that pass and contributes nothing to a shrink-to-fit parent. Give the frame’s container a resolved width — a full-width column or a sized panel — rather than asking a shrink-to-fit wrapper to derive its width from the frame.
§Examples
use std::path::PathBuf;
use gpui::{img, prelude::*, px, ObjectFit};
use rhythm_gpui::{rhythm_frame, RhythmFit, RhythmGrid};
fn figure(grid: RhythmGrid, crop: bool) -> impl IntoElement {
// Pad (default) keeps the whole image and leaves the sub-unit
// remainder below it; crop splits the clipped remainder between the
// top and bottom edges.
rhythm_frame(grid, 16. / 9.)
.fit(if crop { RhythmFit::Crop } else { RhythmFit::Pad })
.child(
img(PathBuf::from("photo.jpg"))
.size_full()
.object_fit(ObjectFit::Cover),
)
}Implementations§
Source§impl RhythmFrame
impl RhythmFrame
Sourcepub fn fit(self, fit: RhythmFit) -> Self
pub fn fit(self, fit: RhythmFit) -> Self
Choose how the height snaps to whole rhythm rows. Takes the mode as a
value, so a runtime choice needs no rebinding:
.fit(if crop { RhythmFit::Crop } else { RhythmFit::Pad }).
Sourcepub fn crop(self) -> Self
pub fn crop(self) -> Self
Shorthand for fit(RhythmFit::Crop): round the height
down instead of up, so the natural-height content overfills the frame
by less than one rhythm unit and is clipped evenly between the top and
bottom edges instead of padded.
Trait Implementations§
Source§impl IntoElement for RhythmFrame
impl IntoElement for RhythmFrame
Source§type Element = Component<RhythmFrame>
type Element = Component<RhythmFrame>
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 ParentElement for RhythmFrame
impl ParentElement for RhythmFrame
Source§fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)
Source§fn child(self, child: impl IntoElement) -> Selfwhere
Self: Sized,
fn child(self, child: impl IntoElement) -> Selfwhere
Self: Sized,
Source§fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Selfwhere
Self: Sized,
fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Selfwhere
Self: Sized,
Source§impl RenderOnce for RhythmFrame
impl RenderOnce for RhythmFrame
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 !RefUnwindSafe for RhythmFrame
impl !Send for RhythmFrame
impl !Sync for RhythmFrame
impl !UnwindSafe for RhythmFrame
impl Freeze for RhythmFrame
impl Unpin for RhythmFrame
impl UnsafeUnpin for RhythmFrame
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> 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