pub struct RhythmDropCap { /* private fields */ }gpui only.Expand description
A drop cap bound to the grid: the cap face at the size solved by
FontRhythm::drop_cap, plus the inset anchoring its baseline. Apply with
RhythmStyled::rhythm_drop_cap; for wrap-around text, measure the letter
with shape_line (see drop_cap_paragraph in the recipes example).
§Examples
use gpui::{div, font, prelude::*, px, FontWeight, TextSystem};
use rhythm_gpui::{RhythmDropCap, RhythmFont, RhythmGrid, RhythmStyled};
fn drop_cap_block(text_system: &TextSystem) -> impl IntoElement {
let grid = RhythmGrid::new(px(8.));
let body = RhythmFont::resolve(text_system, font("Georgia"), px(16.), 3, grid);
let mut bold = font("Georgia");
bold.weight = FontWeight::BOLD;
let cap = RhythmDropCap::resolve(text_system, bold, &body, 3);
div()
.flex()
.items_start()
.gap(px(12.))
.child(div().rhythm_drop_cap(&cap).child("W"))
.child(div().flex_1().min_w_0().rhythm_font(&body).child("hen…"))
}Implementations§
Source§impl RhythmDropCap
impl RhythmDropCap
Sourcepub fn resolve(
text_system: &TextSystem,
font: Font,
body: &RhythmFont,
lines: u32,
) -> Self
pub fn resolve( text_system: &TextSystem, font: Font, body: &RhythmFont, lines: u32, ) -> Self
Resolve font as a drop cap sunk lines lines deep into body text.
The solved size spans the capital from the first line’s cap top down to
the lines-th baseline. The baseline anchor is exact even when a
missing cap height falls back to the 0.7 em approximation; the fallback
only affects the visual top. See FontRhythm::drop_cap for the math.
§Panics
Panics when lines is zero or lines × body.metrics().line_rhythms()
overflows u32.
Sourcepub const fn font(&self) -> &RhythmFont
pub const fn font(&self) -> &RhythmFont
The cap face at the solved size; its line box spans the sunk lines.
Sourcepub const fn top(&self) -> Pixels
pub const fn top(&self) -> Pixels
Relative top inset landing the cap’s baseline on the last sunk line’s
baseline. An inset rather than a margin on purpose: cap-heavy faces
(cap height exceeding ascent − descent, e.g. Merriweather) need a
downward shift, and a positive margin would grow the flex row’s cross
size and push everything below off the grid.
Trait Implementations§
Source§impl Clone for RhythmDropCap
impl Clone for RhythmDropCap
Source§fn clone(&self) -> RhythmDropCap
fn clone(&self) -> RhythmDropCap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RhythmDropCap
impl RefUnwindSafe for RhythmDropCap
impl Send for RhythmDropCap
impl Sync for RhythmDropCap
impl Unpin for RhythmDropCap
impl UnsafeUnpin for RhythmDropCap
impl UnwindSafe for RhythmDropCap
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> 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