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.

Warning

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

source

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");
source

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.

source

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);
source

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.

source

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);
source

pub fn stroke_color(self, val: Option<impl Into<String>>) -> Self

Unlike room visuals, only hex triplets with a leading # are valid.

source

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);
source

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);
source

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);
source

pub fn opacity(self, val: f32) -> Self

Sets the opacity of the text visual. Valid values are in the range 0.0..=1.0.

The default value is 0.5.

Examples
use screeps::MapTextStyle;

let opaque = MapTextStyle::default().opacity(1.0_f32);
let ghost = MapTextStyle::default().opacity(0.05_f32);

Trait Implementations§

source§

impl Clone for MapTextStyle

source§

fn clone(&self) -> MapTextStyle

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for MapTextStyle

source§

fn default() -> MapTextStyle

Returns the “default value” for a type. Read more
source§

impl Serialize for MapTextStyle

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.