Struct kas_core::text::Environment
source · [−]pub struct Environment {
pub direction: Direction,
pub wrap: bool,
pub align: (Align, Align),
pub font_id: FontId,
pub dpem: f32,
pub bounds: Vec2,
}Expand description
Environment in which text is prepared for display
An Environment can be default-constructed (without line-wrapping).
Fields
direction: DirectionText direction
By default, text direction (LTR or RTL) is automatically detected with full bi-directional text support (Unicode Technical Report #9).
wrap: boolLine wrapping
By default, this is true and long text lines are wrapped based on the
width bounds. If set to false, lines are not wrapped at the width
boundary, but explicit line-breaks such as \n still result in new
lines.
align: (Align, Align)Alignment (horiz, vert)
By default, horizontal alignment is left or right depending on the
text direction (see Self::direction), and vertical alignment is
to the top.
font_id: FontIdDefault font
This font is used unless a formatting token (see crate::format)
is used.
dpem: f32Font size: pixels per Em
This is a scaling factor used to convert font sizes, with units
pixels/Em. Equivalently, this is the line-height in pixels.
See crate::fonts documentation.
To calculate this from text size in Points, use dpem = dpp * pt_size
where the dots-per-point is usually dpp = scale_factor * 96.0 / 72.0
on PC platforms, or dpp = 1 on MacOS (or 2 for retina displays).
bounds: Vec2The available (horizontal and vertical) space
This defaults to infinity (implying no bounds). To enable line-wrapping set at least a horizontal bound. The vertical bound is required for alignment (when aligning to the center or bottom). Glyphs outside of these bounds may not be drawn.
Implementations
sourceimpl Environment
impl Environment
sourcepub fn set_font_size(&mut self, pt_size: f32, scale_factor: f32)
pub fn set_font_size(&mut self, pt_size: f32, scale_factor: f32)
Set font size
This is an alternative to setting Self::dpem directly. It is assumed
that 72 Points = 1 Inch and the base screen resolution is 96 DPI.
(Note: MacOS uses a different definition where 1 Point = 1 Pixel.)
sourcepub fn line_height(&self, font_id: FontId) -> Result<f32, InvalidFontId>
pub fn line_height(&self, font_id: FontId) -> Result<f32, InvalidFontId>
Returns the height of horizontal text
This should be similar to the value of Self::dpem, but depends on
the font.
To use “the standard font”, use font_id = Default::default().
sourceimpl Environment
impl Environment
sourcepub fn new(dpem: f32) -> Environment
pub fn new(dpem: f32) -> Environment
Construct, with explicit font size (pixels per Em)
Trait Implementations
sourceimpl Clone for Environment
impl Clone for Environment
sourcefn clone(&self) -> Environment
fn clone(&self) -> Environment
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for Environment
impl Debug for Environment
sourceimpl Default for Environment
impl Default for Environment
sourcefn default() -> Environment
fn default() -> Environment
Returns the “default value” for a type. Read more
sourceimpl PartialEq<Environment> for Environment
impl PartialEq<Environment> for Environment
sourcefn eq(&self, other: &Environment) -> bool
fn eq(&self, other: &Environment) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
impl Copy for Environment
impl StructuralPartialEq for Environment
Auto Trait Implementations
impl RefUnwindSafe for Environment
impl Send for Environment
impl Sync for Environment
impl Unpin for Environment
impl UnwindSafe for Environment
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
sourcefn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Try approximate conversion from Self to T Read more
sourcefn cast_approx(self) -> T
fn cast_approx(self) -> T
Cast approximately from Self to T Read more
sourceimpl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
sourcefn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
sourcefn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
sourcefn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more
sourcefn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
sourcefn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
sourcefn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
sourcefn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more