#[repr(C)]pub struct TextStyle { /* private fields */ }
Expand description
A text style is a font plus size/color/material parameters, and are used to keep text looking more consistent through the application by encouraging devs to re-use styles throughout the project. See Text.MakeStyle for making a TextStyle object. https://stereokit.net/Pages/StereoKit/TextStyle.html
§Examples
use stereokit_rust::{system::{TextStyle, Pivot, Align, Text, Lines, Hierarchy},
font::Font, material::Material, mesh::Mesh, maths::{Vec3, Matrix},
util::named_colors::{WHITE, GOLD, GREEN, BLUE, RED, BLACK}};
let font = Font::default();
let style = TextStyle::from_font(font, 0.88, WHITE);
let text = "ÂjlD;";
let size = Text::size_layout(text, Some(style), None);
let base_line_at = -style.get_cap_height();
let ascender_at = base_line_at + style.get_ascender();
let cap_height_at = base_line_at + style.get_cap_height();
let descender_at = base_line_at - style.get_descender();
let line_height_at = ascender_at - style.get_line_height_pct() * style. get_total_height();
let sizex = size.x;
let recenter = Matrix::t(Vec3::Y * 0.6);
filename_scr = "screenshots/text_style.jpeg"; fov_scr=110.0;
test_screenshot!( // !!!! Get a proper main loop !!!!
Hierarchy::push(token, recenter, None);
Text::add_at(token, text, Matrix::Y_180, Some(style), Some(GOLD.into()),
Some(Pivot::TopCenter), Some(Align::TopLeft), None, None, None);
Lines::add(token, [sizex, ascender_at, 0.0], [-sizex, ascender_at, 0.0], GREEN, None, 0.03 );
Lines::add(token, [sizex, base_line_at, 0.0], [-sizex, base_line_at, 0.0], WHITE, None, 0.03 );
Lines::add(token, [sizex, cap_height_at, 0.0], [-sizex, cap_height_at, 0.0], BLACK, None, 0.03 );
Lines::add(token, [sizex, descender_at, 0.0], [-sizex, descender_at, 0.0], BLUE, None, 0.03 );
Lines::add(token, [sizex, line_height_at, 0.0], [-sizex, line_height_at, 0.0], RED, None, 0.03 );
Hierarchy::pop(token);
);

Implementations§
Source§impl TextStyle
impl TextStyle
Sourcepub fn from_font(
font: impl AsRef<Font>,
layout_height_meters: f32,
color_gamma: impl Into<Color128>,
) -> Self
pub fn from_font( font: impl AsRef<Font>, layout_height_meters: f32, color_gamma: impl Into<Color128>, ) -> Self
Create a text style for use with other text functions! A text style is a font plus size/color/material parameters, and are used to keep text looking more consistent through the application by encouraging devs to re-use styles throughout the project.
This fn will create an unique Material for this style based on Default.ShaderFont. https://stereokit.net/Pages/StereoKit/TextStyle/FromFont.html
font
- Font asset you want attached to this style.layout_height_meters
- Height of a text glyph in meters. StereoKit currently bases this on CapHeight.color_gamma
- The gamma space color of the text style. This will be embedded in the vertex color of the text mesh.
see also text_make_style
§Examples
use stereokit_rust::{system::TextStyle, font::Font, util::named_colors};
let font = Font::default();
let text_style = TextStyle::from_font(&font, 0.02, named_colors::WHITE);
assert_eq!(text_style.get_material().get_id(), "sk/text_style/2/material");
assert_eq!(text_style.get_layout_height(), 0.02);
Sourcepub fn from_font_and_shader(
font: impl AsRef<Font>,
layout_height_meters: f32,
shader: impl AsRef<Shader>,
color_gamma: impl Into<Color128>,
) -> Self
pub fn from_font_and_shader( font: impl AsRef<Font>, layout_height_meters: f32, shader: impl AsRef<Shader>, color_gamma: impl Into<Color128>, ) -> Self
Create a text style for use with other text functions! A text style is a font plus size/color/material parameters, and are used to keep text looking more consistent through the application by encouraging devs to re-use styles throughout the project.
This function will create an unique Material for this style based on the provided Shader. https://stereokit.net/Pages/StereoKit/TextStyle/FromFont.html
font
- Font asset you want attached to this style.layout_height_meters
- Height of a text glyph in meters. StereoKit currently bases this on CapHeight.shader
- This style will create and use a unique/ Material based on the Shader that you provide here.color_gamma
- The gamma space color of the text style. This will be embedded in the vertex color of the text mesh.
see also text_make_style_shader
§Examples
use stereokit_rust::{system::TextStyle, font::Font, util::named_colors, shader::Shader};
let font = Font::default();
let shader = Shader::from_file("shaders/brick_pbr.hlsl.sks")
.expect("Brick_pbr should be a valid shader");
let text_style = TextStyle::from_font_and_shader(&font, 0.02, shader, named_colors::WHITE);
assert_eq!(text_style.get_material().get_id(), "sk/text_style/2/material");
assert_eq!(text_style.get_layout_height(), 0.02);
Sourcepub fn from_font_and_material(
font: impl AsRef<Font>,
layout_height_meters: f32,
material: impl AsRef<Material>,
color_gamma: impl Into<Color128>,
) -> Self
pub fn from_font_and_material( font: impl AsRef<Font>, layout_height_meters: f32, material: impl AsRef<Material>, color_gamma: impl Into<Color128>, ) -> Self
Create a text style for use with other text functions! A text style is a font plus size/color/material parameters, and are used to keep text looking more consistent through the application by encouraging devs to re-use styles throughout the project.
This overload allows you to set the specific Material that is used. This can be helpful if you’re keeping styles similar enough to re-use the material and save on draw calls. If you don’t know what that means, then prefer using the overload that takes a Shader, or takes neither a Shader nor a Material! https://stereokit.net/Pages/StereoKit/TextStyle/FromFont.html
font
- Font asset you want attached to this style.layout_height_meters
- Height of a text glyph in meters. StereoKit currently bases this on CapHeight.material
- Which material should be used to render the text with? Note that this does NOT duplicate the material, so the text with? Note that this does NOT duplicate the material, so some parameters of this Material instance will get overwritten, like the texture used for the glyph atlas. You should either use a new Material, or a Material that was already used with this same font.color_gamma
- The gamma space color of the text style. This will be embedded in the vertex color of the text mesh.
see also text_make_style_mat
§Examples
use stereokit_rust::{system::TextStyle, font::Font, util::named_colors, material::Material};
let font = Font::default();
let material = Material::pbr().copy();
let text_style = TextStyle::from_font_and_material(&font, 0.02, &material, named_colors::WHITE);
assert_eq!(text_style.get_material(), material);
assert_eq!(text_style.get_layout_height(), 0.02);
Sourcepub fn char_height(&mut self, char_height: f32)
👎Deprecated since 0.40.0: please use TextStyle::layout_height
pub fn char_height(&mut self, char_height: f32)
Height of a text glyph in meters. StereoKit currently bases this on the letter ‘T’. https://stereokit.net/Pages/StereoKit/TextStyle/CharHeight.html
see also text_style_set_layout_height
Sourcepub fn layout_height(&mut self, height_meters: f32)
pub fn layout_height(&mut self, height_meters: f32)
(meters) Layout height is the height of the font’s CapHeight, which is used for calculating the vertical height of the text when doing text layouts. This does not include the height of the descender , nor does it represent the maximum possible height a glyph may extend upwards (use Text::size_render). https://stereokit.net/Pages/StereoKit/TextStyle/LayoutHeight.html
see also text_style_set_layout_height
§Examples
use stereokit_rust::{font::Font, util::named_colors, system::TextStyle};
let font = Font::default();
let mut text_style = TextStyle::from_font(font, 0.02, named_colors::WHITE);
assert_eq!(text_style.get_layout_height(), 0.02);
text_style.layout_height(0.03);
assert!((text_style.get_layout_height() - 0.03) < 0.0001);
Sourcepub fn total_height(&mut self, height_meters: f32)
pub fn total_height(&mut self, height_meters: f32)
(meters) Height from the layout descender to the layout ascender. This is most equivalent to the ‘font-size’ in CSS or other text layout tools. Since ascender and descenders can vary a lot, using layout_height in many cases can lead to more consistency in the long run. https://stereokit.net/Pages/StereoKit/TextStyle/TotalHeight.html
see also text_style_set_total_height
§Examples
use stereokit_rust::{font::Font, util::named_colors, system::TextStyle};
let font = Font::default();
let mut text_style = TextStyle::from_font(font, 0.02, named_colors::WHITE);
text_style.total_height(0.03);
assert_eq!(text_style.get_total_height(), 0.03);
Sourcepub fn line_height_pct(&mut self, height_percent: f32)
pub fn line_height_pct(&mut self, height_percent: f32)
This is the space a full line of text takes, from baseline to baseline, as a 0-1 percentage of the font’s character height. This is similar to CSS line-height, a value of 1.0 means the line takes only https://stereokit.net/Pages/StereoKit/TextStyle/LineHeightPct.html
see also text_style_set_line_height_pct
§Examples
use stereokit_rust::{font::Font, util::named_colors, system::TextStyle};
let font = Font::default();
let mut text_style = TextStyle::from_font(font, 0.02, named_colors::WHITE);
assert_eq!(text_style.get_layout_height(), 0.02);
text_style.line_height_pct(30.0);
assert_eq!(text_style.get_line_height_pct(), 30.0);
Sourcepub fn get_material(&self) -> Material
pub fn get_material(&self) -> Material
This provides a reference to the Material used by this style, so you can override certain features! Note that if you’re creating TextStyles with manually provided Materials, this Material may not be unique to this style. https://stereokit.net/Pages/StereoKit/TextStyle/Material.html
see also text_style_get_material
see example in [TextStyle::from_font_and material
]
Sourcepub fn get_char_height(&self) -> f32
👎Deprecated since 0.40.0: please use get_layout_height
pub fn get_char_height(&self) -> f32
Returns the maximum height of a text character using this style, in meters. https://stereokit.net/Pages/StereoKit/TextStyle/CharHeight.html
see also text_style_get_layout_height
Sourcepub fn get_layout_height(&self) -> f32
pub fn get_layout_height(&self) -> f32
(meters) Layout height is the height of the font’s ascender, which is used for calculating the vertical height of the text when doing text layouts. This does not include the height of the descender (use total_height), nor does it represent the maximum possible height a glyph may extend upwards (use Text::size_render). https://stereokit.net/Pages/StereoKit/TextStyle/LayoutHeight.html
see also text_style_get_layout_height
see example in TextStyle::layout_height
Sourcepub fn get_total_height(&self) -> f32
pub fn get_total_height(&self) -> f32
(meters) Height from the layout descender to the layout ascender. This is most equivalent to the ‘font-size’ in CSS or other text layout tools. Since ascender and descenders can vary a lot, using layout_height in many cases can lead to more consistency in the long run. https://stereokit.net/Pages/StereoKit/TextStyle/TotalHeight.html
see also text_style_get_total_height
see example in TextStyle::total_height
Sourcepub fn get_line_height_pct(&self) -> f32
pub fn get_line_height_pct(&self) -> f32
This is the space a full line of text takes, from baseline to baseline, as a 0-1 percentage of the font’s character height. This is similar to CSS line-height, a value of 1.0 means the line takes only https://stereokit.net/Pages/StereoKit/TextStyle/LineHeightPct.html
see also text_style_get_line_height_pct
see example in TextStyle::line_height_pct
Sourcepub fn get_cap_height(&self) -> f32
pub fn get_cap_height(&self) -> f32
(meters) The height of a standard captial letter, such as ‘H’ or ‘T’ https://stereokit.net/Pages/StereoKit/TextStyle/CapHeight.html
see also text_style_get_cap_height
§Examples
use stereokit_rust::{font::Font, util::named_colors, system::TextStyle};
let font = Font::default();
let mut text_style = TextStyle::from_font(font, 0.02, named_colors::WHITE);
assert_eq!(text_style.get_layout_height(), 0.02);
assert_eq!(text_style.get_cap_height(), 0.02);
Sourcepub fn get_ascender(&self) -> f32
pub fn get_ascender(&self) -> f32
(meters) The layout ascender of the font, this is the height of the “tallest” glyphs as far as layout is concerned. Characters such as ‘l’ typically rise above the CapHeight, and this value usually matches this height. Some glyphs such as those with hats or umlauts will almost always be taller than this height (see Text::size_render), but this is not used when laying out characters. https://stereokit.net/Pages/StereoKit/TextStyle/Ascender.html
see also text_style_get_ascender
§Examples
use stereokit_rust::{font::Font, util::named_colors, system::TextStyle};
let font = Font::default();
let mut text_style = TextStyle::from_font(font, 0.02, named_colors::WHITE);
assert_eq!(text_style.get_layout_height(), 0.02);
//TODO: linux assert_eq!(text_style.get_ascender(), 0.03);
//TODO: windows assert_eq!(text_style.get_ascender(), 0.021176472);
Sourcepub fn get_descender(&self) -> f32
pub fn get_descender(&self) -> f32
(meters) The layout descender of the font, this is the positive height below the baseline https://stereokit.net/Pages/StereoKit/TextStyle/Descender.html
see also text_style_get_descender
§Examples
use stereokit_rust::{font::Font, util::named_colors, system::TextStyle};
let font = Font::default();
let mut text_style = TextStyle::from_font(font, 0.02, named_colors::WHITE);
assert_eq!(text_style.get_layout_height(), 0.02);
assert_ne!(text_style.get_descender(), 0.0);
Trait Implementations§
Source§impl Default for TextStyle
impl Default for TextStyle
Source§fn default() -> Self
fn default() -> Self
This is the default text style used by StereoKit. https://stereokit.net/Pages/StereoKit/TextStyle/Default.html
impl Copy for TextStyle
impl Eq for TextStyle
impl StructuralPartialEq for TextStyle
Auto Trait Implementations§
impl Freeze for TextStyle
impl RefUnwindSafe for TextStyle
impl Send for TextStyle
impl Sync for TextStyle
impl Unpin for TextStyle
impl UnwindSafe for TextStyle
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
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.