pub struct TextAnchor {
pub h: TextAlign,
pub v: TextVAlign,
}Expand description
How canvas text hangs on its at point: one placement per axis (docs/canvas.md “Text”).
Two axes rather than a list of named positions, because that is the shape of the problem and
of every native API underneath: NSAttributedString drawing, Pango extents,
QFontMetricsF, Paint.Align, Canvas2D’s textAlign/textBaseline. The alignment is done
by the backend, which is both cheaper and more accurate than doing it in app code: it already
has the laid-out metrics, where an app has to ask for them through
Toolkit::measure_text first.
TextAnchor::LEADING and TextAnchor::CENTERED name the two placements that used to be
this type’s only variants.
Fields§
§h: TextAlignThe horizontal placement: the same three-way leading/center/trailing a wrapped label’s
lines take (props::TextAlign), because it is the same question with the same RTL rule.
Trailing is what an axis label right-aligned against its axis wants, and the reason the
horizontal axis is settable at all: emulating it in app code costs a
Toolkit::measure_text call per label, where the backend already holds the width it is
about to draw with.
v: TextVAlignImplementations§
Source§impl TextAnchor
impl TextAnchor
Sourcepub const LEADING: TextAnchor
pub const LEADING: TextAnchor
The top-leading corner of the line box, the default.
Sourcepub const CENTERED: TextAnchor
pub const CENTERED: TextAnchor
The center of the line box, both ways.
Sourcepub const TRAILING: TextAnchor
pub const TRAILING: TextAnchor
The top-trailing corner of the line box.
Sourcepub fn offset(self, width: f64, height: f64, ascent: f64) -> (f64, f64)
pub fn offset(self, width: f64, height: f64, ascent: f64) -> (f64, f64)
Where the text’s top-leading corner goes, as an offset from at, given the line box this
text measures to. The single definition of what an anchor means: every backend that draws
in Rust calls this, and the C++/Java/JS shims repeat exactly this arithmetic.
height is the line box (ascent + descent) and ascent the baseline’s offset from its
top, the two numbers TextMetrics carries.
Sourcepub fn pack(self) -> f64
pub fn pack(self) -> f64
The anchor as one number, for the numeric op stream the serializing backends share:
h * 4 + v, so it still occupies the single slot the two-variant enum did.
Sourcepub fn unpack(code: f64) -> TextAnchor
pub fn unpack(code: f64) -> TextAnchor
Inverse of TextAnchor::pack. An unrecognized code answers the default rather than
failing: a stream is only ever written by a matching encoder, and a drawing with text in
the wrong corner beats one that panics inside a native draw callback.
Trait Implementations§
Source§impl Clone for TextAnchor
impl Clone for TextAnchor
Source§fn clone(&self) -> TextAnchor
fn clone(&self) -> TextAnchor
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 TextAnchor
Source§impl Debug for TextAnchor
impl Debug for TextAnchor
Source§impl Default for TextAnchor
impl Default for TextAnchor
Source§fn default() -> TextAnchor
fn default() -> TextAnchor
impl Eq for TextAnchor
Source§impl PartialEq for TextAnchor
impl PartialEq for TextAnchor
impl StructuralPartialEq for TextAnchor
Auto Trait Implementations§
impl Freeze for TextAnchor
impl RefUnwindSafe for TextAnchor
impl Send for TextAnchor
impl Sync for TextAnchor
impl Unpin for TextAnchor
impl UnsafeUnpin for TextAnchor
impl UnwindSafe for TextAnchor
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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