Struct screeps::objects::visual::MapTextStyle
source · pub struct MapTextStyle { /* private fields */ }
Expand description
Settings for text visuals on the map, used with MapVisual::text
.
This is different than TextStyle
which is used with RoomVisual::text
because the two methods take data in a slightly different format. Notably,
room visuals accept colors in any web format and take use a shorthond for
font data, where map visuals require stricter color formats and have
different font options.
The backgroundPadding
setting in the Screeps docs does not function in
game so it is not present in this API.
See also: Screeps docs.
Implementations§
source§impl MapTextStyle
impl MapTextStyle
sourcepub fn color(self, val: impl Into<String>) -> Self
pub fn color(self, val: impl Into<String>) -> Self
Sets the color of the text style.
Unlike room visuals, only hex triplets with a leading #
are valid.
The default value is #FFFFFF
.
Examples
use screeps::MapTextStyle;
// Bright pink! We really need to see this text!
let style = MapTextStyle::default().color("#FF00FF");
sourcepub fn font_family(self, val: impl Into<String>) -> Self
pub fn font_family(self, val: impl Into<String>) -> Self
Sets the font family of the text style. Font families with spaces in their name must be quoted. Normally this involves escaping quotes in a string literal.
The default value is sans-serif
.
Examples
use screeps::MapTextStyle;
let monospace_style = MapTextStyle::default().font_family("monospace");
let font_family_style = MapTextStyle::default().font_family("\"Comic Sans MS\"");
let fallback_style = MapTextStyle::default().font_family("\"Comic Sans MS\", Times, serif");
For more information about font families, see the MDN Documentation.
sourcepub fn font_size(self, val: f32) -> Self
pub fn font_size(self, val: f32) -> Self
Sets the size of the font, in game coordinates. This means that a
font_size
of 1 corresponds to the same size as one coordinate on the
map. This does not support any other units for size.
The default value is 10
.
Examples
use screeps::MapTextStyle;
let tiny_text = MapTextStyle::default().font_size(2_f32);
let room_height = MapTextStyle::default().font_size(50_f32);
sourcepub fn font_style(self, val: MapFontStyle) -> Self
pub fn font_style(self, val: MapFontStyle) -> Self
Sets the style of the font. This controls whether a font should be styled with a normal, italic, or oblique face.
The default value is MapFontStyle::Normal
.
oblique <angle>
is not supported.
Examples
use screeps::{MapFontStyle, MapTextStyle};
let normal = MapTextStyle::default().font_style(MapFontStyle::Normal);
let italic = MapTextStyle::default().font_style(MapFontStyle::Italic);
For more information about font styles, see the MDN Documentation.
sourcepub fn font_variant(self, val: MapFontVariant) -> Self
pub fn font_variant(self, val: MapFontVariant) -> Self
Sets the variant of the font. This controls whether or not text is rendered as small caps.
The default value is MapFontVariant::Normal
.
Examples
use screeps::{MapFontVariant, MapTextStyle};
let normal = MapTextStyle::default().font_variant(MapFontVariant::Normal);
let small_caps = MapTextStyle::default().font_variant(MapFontVariant::SmallCaps);
sourcepub fn stroke_color(self, val: Option<impl Into<String>>) -> Self
pub fn stroke_color(self, val: Option<impl Into<String>>) -> Self
Unlike room visuals, only hex triplets with a leading #
are valid.
sourcepub fn stroke_width(self, val: f32) -> Self
pub fn stroke_width(self, val: f32) -> Self
Sets the width of the stroke for the text, if the stroke is enabled.
A stroke width of 0
results in no stroke. Negative values are invalid.
The default value is 0.15
.
Examples
use screeps::MapTextStyle;
let thin = MapTextStyle::default().stroke_width(0.05_f32);
let wide = MapTextStyle::default().stroke_width(2.0_f32);
sourcepub fn background_color(self, val: Option<&str>) -> Self
pub fn background_color(self, val: Option<&str>) -> Self
Sets or removes the background color for the text visual. When a
background is enabled, the text’s vertical align is set to middle
instead of baseline
.
Unlike room visuals, only hex triplets with a leading #
are valid.
The default value is None
.
Examples
use screeps::MapTextStyle;
let lavender = MapTextStyle::default().background_color(Some("#b373de"));
// Even though this is the default, it's possible to unset the background color.
let unset = MapTextStyle::default().background_color(None);
sourcepub fn align(self, val: TextAlign) -> Self
pub fn align(self, val: TextAlign) -> Self
Sets the horizontal alignment of the text.
The default value is TextAlign::Center
.
Examples
use screeps::{MapTextStyle, TextAlign};
let left = MapTextStyle::default().align(TextAlign::Left);
Trait Implementations§
source§impl Clone for MapTextStyle
impl Clone for MapTextStyle
source§fn clone(&self) -> MapTextStyle
fn clone(&self) -> MapTextStyle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more