Struct unsegen::base::style::StyleModifier[][src]

pub struct StyleModifier { /* fields omitted */ }
Expand description

Defines a set of modifications on a style. Multiple modifiers can be combined before applying them to a style.

Implementations

impl StyleModifier[src]

pub fn new() -> Self[src]

Construct a new (not actually) modifier, that leaves all style properties unchanged.

pub fn fg_color(self, fg_color: Color) -> Self[src]

Make the modifier change the foreground color to the specified value.

pub fn bg_color(self, bg_color: Color) -> Self[src]

Make the modifier change the background color to the specified value.

pub fn format(self, format: TextFormatModifier) -> Self[src]

Make the modifier change the textformat of the style to the specified value.

pub fn bold<M: Into<BoolModifyMode>>(self, val: M) -> Self[src]

Make the modifier change the bold property of the textformat of the style to the specified value.

This is a shortcut for using format using a TextFormatModifier that changes the bold property.

Examples:

use unsegen::base::{StyleModifier, TextFormatModifier};

let s1 = StyleModifier::new().bold(true);
let s2 = StyleModifier::new().format(TextFormatModifier::new().bold(true));

assert_eq!(s1, s2);

pub fn italic<M: Into<BoolModifyMode>>(self, val: M) -> Self[src]

Make the modifier change the italic property of the textformat of the style to the specified value.

This is a shortcut for using format using a TextFormatModifier that changes the italic property.

Examples:

use unsegen::base::{StyleModifier, TextFormatModifier};

let s1 = StyleModifier::new().italic(true);
let s2 = StyleModifier::new().format(TextFormatModifier::new().italic(true));

assert_eq!(s1, s2);

pub fn invert<M: Into<BoolModifyMode>>(self, val: M) -> Self[src]

Make the modifier change the invert property of the textformat of the style to the specified value.

This is a shortcut for using format using a TextFormatModifier that changes the invert property.

Examples:

use unsegen::base::{StyleModifier, TextFormatModifier};

let s1 = StyleModifier::new().invert(true);
let s2 = StyleModifier::new().format(TextFormatModifier::new().invert(true));

assert_eq!(s1, s2);

pub fn underline<M: Into<BoolModifyMode>>(self, val: M) -> Self[src]

Make the modifier change the underline property of the textformat of the style to the specified value.

This is a shortcut for using format using a TextFormatModifier that changes the underline property.

Examples:

use unsegen::base::{StyleModifier, TextFormatModifier};

let s1 = StyleModifier::new().underline(true);
let s2 = StyleModifier::new().format(TextFormatModifier::new().underline(true));

assert_eq!(s1, s2);

pub fn on_top_of(self, other: StyleModifier) -> Self[src]

Combine the current value with that of the argument so that the application of the returned value is always equivalent to first applying other and then applying self to some Style.

Examples:

use unsegen::base::*;

let mut s1 = Style::default();
let mut s2 = s1;

let m1 =
StyleModifier::new().fg_color(Color::Red).italic(BoolModifyMode::Toggle).bold(true).underline(false);
let m2 = StyleModifier::new().bg_color(Color::Blue).italic(true).bold(false);

m1.on_top_of(m2).modify(&mut s1);

m2.modify(&mut s2);
m1.modify(&mut s2);

assert_eq!(s1, s2);

pub fn apply_to_default(self) -> Style[src]

Apply the modifier to a default (i.e., empty) Style. In a way, this converts the StyleModifier to a Style.

Examples:

use unsegen::base::*;

let m = StyleModifier::new().fg_color(Color::Red).italic(true);
let mut style = Style::default();

assert_eq!(m.apply(style), m.apply_to_default());

pub fn apply(self, style: Style) -> Style[src]

Apply this modifier to a given style and return the result. This is essentially a convenience wrapper around modify, which clones the Style.

Examples:

use unsegen::base::*;

let m = StyleModifier::new().fg_color(Color::Red).italic(BoolModifyMode::Toggle);
let mut style = Style::default();
let style2 = m.apply(style);
m.modify(&mut style);

assert_eq!(style, style2);

pub fn modify(self, style: &mut Style)[src]

Modify the given style according to the properties of this modifier.

Trait Implementations

impl Clone for StyleModifier[src]

fn clone(&self) -> StyleModifier[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for StyleModifier[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Default for StyleModifier[src]

fn default() -> StyleModifier[src]

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

impl PartialEq<StyleModifier> for StyleModifier[src]

fn eq(&self, other: &StyleModifier) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &StyleModifier) -> bool[src]

This method tests for !=.

impl Copy for StyleModifier[src]

impl Eq for StyleModifier[src]

impl StructuralEq for StyleModifier[src]

impl StructuralPartialEq for StyleModifier[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.