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§
source§impl 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()
.
Trait Implementations§
source§impl Clone for Environment
impl Clone for Environment
source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more