Struct kas_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: Direction

Text direction

By default, text direction (LTR or RTL) is automatically detected with full bi-directional text support (Unicode Technical Report #9).

§wrap: bool

Line 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: FontId

Default font

This font is used unless a formatting token (see crate::format) is used.

§dpem: f32

Font 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: Vec2

The 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§

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.)

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().

Construct, with explicit font size (pixels per Em)

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Cast from Self to T Read more
Try converting from Self to T Read more
Try approximate conversion from Self to T Read more
Cast approximately from Self to T Read more
Cast to integer, truncating Read more
Cast to the nearest integer Read more
Cast the floor to an integer Read more
Cast the ceiling to an integer Read more
Try converting to integer with truncation Read more
Try converting to the nearest integer Read more
Try converting the floor to an integer Read more
Try convert the ceiling to an integer Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.