pub struct RhythmBlockMetrics { /* private fields */ }Expand description
A text block on the rhythm grid as pure geometry: one line’s metrics plus
baseline or ink-top anchors, with both fragment geometry and the exact row
arithmetic a virtualized renderer needs. new is the pure
form of rhythm_block; ink_anchored pairs an ink
opening with its whole-row close.
Either mode spans a whole number of rhythm rows for any number of lines, so
blocks and fragments compose without breaking the page rhythm.
§Fragments
A block split at visual-line boundaries keeps its rhythm phase because
every line advances by whole rows. The first / middle / last height
methods expose concrete fragment geometry, while first_rows,
middle_rows, and last_rows expose
exact i32 cursor deltas. A virtualizer can accumulate those deltas in an
i64, rebase near the viewport, then derive only a visible fragment’s
baseline with baseline_at_row and line-box top
with RhythmLineMetrics::paint_origin_for.
§Examples
use rhythm_gpui::{Rhythm, RhythmBlockMetrics, RhythmLineMetrics};
let grid = Rhythm::new(8.0);
// Georgia-like 16px body on a 3-unit (24px) line.
let line = RhythmLineMetrics::new(14.67, 3.51, 3, grid);
let block = RhythmBlockMetrics::new(line, 3, 1);
// Five wrapped lines cover sixteen whole rhythm rows…
assert_eq!(block.rows(5), 3 + 1 + 4 * 3);
// …and the first baseline sits `top` grid lines below the block top.
assert_eq!(block.first_baseline(), grid.height(3));
let origin_y = line.paint_origin_for(block.first_baseline());
assert!((origin_y + line.baseline_above() - grid.height(3)).abs() < 1e-4);Implementations§
Source§impl RhythmBlockMetrics
impl RhythmBlockMetrics
Sourcepub const fn new(line: RhythmLineMetrics, top: i32, bottom: i32) -> Self
pub const fn new(line: RhythmLineMetrics, top: i32, bottom: i32) -> Self
A block opening top rhythm units above the first baseline and
closing bottom units below the last. Negative counts are meaningful
for margin-style layouts, matching baseline_top / baseline_bottom.
Sourcepub fn ink_anchored(
line: RhythmLineMetrics,
ink_ascent: f32,
top: i32,
bottom: i32,
) -> Self
pub fn ink_anchored( line: RhythmLineMetrics, ink_ascent: f32, top: i32, bottom: i32, ) -> Self
An ink-anchored block: opens top rhythm units above the anchored ink
top and closes with the paired trimmed space, retaining that ink phase
across fragments while the whole block still spans integer rows.
ink_ascent is the anchored ink’s height above the baseline: pass a
Latin cap height, or a caller-supplied CJK ICF ascent to anchor the
ideographic character face instead.
§Panics
Panics when ink_ascent is zero, negative, or non-finite.
Sourcepub const fn line(&self) -> RhythmLineMetrics
pub const fn line(&self) -> RhythmLineMetrics
The line metrics the block is set in.
Sourcepub const fn top_rhythms(&self) -> i32
pub const fn top_rhythms(&self) -> i32
Opening rhythm units above the anchor (baseline or ink top). A row
count, not a length — opening is the pixel spacing
it produces.
Sourcepub const fn bottom_rhythms(&self) -> i32
pub const fn bottom_rhythms(&self) -> i32
Closing rhythm units below the last baseline, or the paired ink close.
A row count, not a length; see closing.
Sourcepub fn opening(&self) -> f32
pub fn opening(&self) -> f32
Space from the block’s top edge down to its first line box. Negative values are meaningful as margins rather than padding.
Sourcepub fn closing(&self) -> f32
pub fn closing(&self) -> f32
Space from the last line box down to the block’s whole-row bottom edge.
Sourcepub fn first_baseline(&self) -> f32
pub fn first_baseline(&self) -> f32
Distance from the block’s top edge down to the first baseline: top
whole rhythm units for baseline anchors, plus the ink ascent for
ink anchors. Applies to first and single fragments; in a middle/last
fragment the first baseline sits
RhythmLineMetrics::baseline_above below the fragment top.
Sourcepub fn first_height(&self, lines: u32) -> f32
pub fn first_height(&self, lines: u32) -> f32
Sourcepub fn middle_height(&self, lines: u32) -> f32
pub fn middle_height(&self, lines: u32) -> f32
Sourcepub fn last_height(&self, lines: u32) -> f32
pub fn last_height(&self, lines: u32) -> f32
Height of a last fragment: lines whole line boxes plus the closing.
§Panics
Panics when lines is zero.
Sourcepub fn rows(&self, lines: u32) -> i32
pub fn rows(&self, lines: u32) -> i32
The whole number of rhythm rows a single-fragment block of lines
visual lines covers, as exact integer arithmetic:
top + bottom + (lines − 1) × line_rhythms for baseline anchors, or
top + bottom + lines × line_rhythms for ink anchors. The block’s
height in pixels is grid.height(rows(lines)).
§Panics
Panics when lines is zero or the resulting row count does not fit in
i32.
Sourcepub fn first_rows(&self, lines: u32) -> i32
pub fn first_rows(&self, lines: u32) -> i32
Row-cursor delta from the block top to the baseline immediately after a
first fragment of lines visual lines. Add it to the block’s starting
row, then pass the result to baseline_at_row
to place the first line of the next fragment.
This and its two siblings partition rows exactly:
first_rows(a) + middle_rows(b) + last_rows(c) == rows(a + b + c).
These values are cursor transitions, not fragment heights converted to
rows: continuation fragments start at a line-box top, generally between
grid lines. Keeping the cursor as rows and deriving only the visible
fragment’s baseline prevents accumulated floating-point drift.
§Examples
use rhythm_gpui::{Rhythm, RhythmBlockMetrics, RhythmLineMetrics};
let grid = Rhythm::new(8.0);
let line = RhythmLineMetrics::new(14.67, 3.51, 3, grid);
let block = RhythmBlockMetrics::new(line, 3, 1);
// A nine-line block split 2 / 4 / 3 across three viewport pages: the
// middle fragment starts two line advances below the first line box.
let first_origin = line.paint_origin_for(block.first_baseline());
let mut cursor = i64::from(block.first_rows(2));
let middle_origin = line.paint_origin_for(block.baseline_at_row(cursor));
assert!((middle_origin - (first_origin + 2.0 * line.line_height())).abs() < 1e-3);
cursor = cursor.checked_add(i64::from(block.middle_rows(4))).unwrap();
cursor = cursor.checked_add(i64::from(block.last_rows(3))).unwrap();
assert_eq!(cursor, i64::from(block.rows(9)));§Panics
Panics when lines is zero or the row count does not fit in i32.
Sourcepub fn middle_rows(&self, lines: u32) -> i32
pub fn middle_rows(&self, lines: u32) -> i32
Row-cursor delta across a middle fragment of lines visual lines:
lines × line_rhythms. The cursor points to the fragment’s first
baseline before this delta and the following fragment’s first baseline
after it. See first_rows for the full contract.
§Panics
Panics when lines is zero or the row count does not fit in i32.
Sourcepub fn baseline_at_row(&self, row: i64) -> f32
pub fn baseline_at_row(&self, row: i64) -> f32
The baseline at an accumulated i64 grid-row cursor. Baseline-anchored
blocks land on row × grid size; ink-anchored blocks retain their ink
phase.
Keep the cursor as exact integer rows and rebase it near the viewport
before this conversion. The returned coordinate is f32, so accepting
i64 avoids an arbitrary saturating cast but cannot make enormous
absolute pixel coordinates exact.
Pass this to RhythmLineMetrics::paint_origin_for to derive the
fragment’s line-box top without accumulating preceding f32 heights.
Sourcepub fn last_rows(&self, lines: u32) -> i32
pub fn last_rows(&self, lines: u32) -> i32
Row-cursor delta from the first baseline of a last fragment of
lines visual lines to the block’s whole-row bottom edge: lines − 1
line advances plus the closing for baseline anchors, or lines
advances plus the paired ink close for ink anchors. See
first_rows for the full contract.
§Panics
Panics when lines is zero or the row count does not fit in i32.
Source§impl RhythmBlockMetrics
Pixels-typed mirrors of the two block values that stay inside a paint
path’s Pixels chain: both are summed with grid lengths into the target
baseline RhythmLineMetrics::paint_origin_for_px consumes. See those
mirrors for the integration-boundary rule.
impl RhythmBlockMetrics
Pixels-typed mirrors of the two block values that stay inside a paint
path’s Pixels chain: both are summed with grid lengths into the target
baseline RhythmLineMetrics::paint_origin_for_px consumes. See those
mirrors for the integration-boundary rule.
Sourcepub fn first_baseline_px(&self) -> Pixels
Available on crate feature gpui only.
pub fn first_baseline_px(&self) -> Pixels
gpui only.first_baseline in Pixels.
Sourcepub fn baseline_at_row_px(&self, row: i64) -> Pixels
Available on crate feature gpui only.
pub fn baseline_at_row_px(&self, row: i64) -> Pixels
gpui only.baseline_at_row in Pixels.
Trait Implementations§
Source§impl Clone for RhythmBlockMetrics
impl Clone for RhythmBlockMetrics
Source§fn clone(&self) -> RhythmBlockMetrics
fn clone(&self) -> RhythmBlockMetrics
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RhythmBlockMetrics
Source§impl Debug for RhythmBlockMetrics
impl Debug for RhythmBlockMetrics
Source§impl PartialEq for RhythmBlockMetrics
impl PartialEq for RhythmBlockMetrics
impl StructuralPartialEq for RhythmBlockMetrics
Auto Trait Implementations§
impl Freeze for RhythmBlockMetrics
impl RefUnwindSafe for RhythmBlockMetrics
impl Send for RhythmBlockMetrics
impl Sync for RhythmBlockMetrics
impl Unpin for RhythmBlockMetrics
impl UnsafeUnpin for RhythmBlockMetrics
impl UnwindSafe for RhythmBlockMetrics
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