[][src]Struct attheme::Attheme

pub struct Attheme {
    pub variables: Variables,
    pub wallpaper: Option<Wallpaper>,
}

Represents contents of an .attheme file.

Fields

variables: Variables

An IndexMap of variables of the theme.

wallpaper: Option<Wallpaper>

The image wallpaper of the theme.

Note that Telegram only recognizes .jpg images, but the crate doesn't check that the wallpaper is actually a valid .jpg. You should do it on your own.

Methods

impl Attheme[src]

#[must_use] pub fn new() -> Self[src]

Creates an empty theme.

Examples

use attheme::Attheme;

let theme = Attheme::new();

assert!(theme.variables.is_empty());
assert_eq!(theme.wallpaper, None);

#[must_use] pub fn with_capacity(capacity: usize) -> Self[src]

Creates an empty theme, with preallocation for capacity variables.

#[must_use] pub fn from_bytes(contents: &[u8]) -> Self[src]

Parses .attheme contents passed as bytes.

Examples

use attheme::{Attheme, Color};

let contents = b"
checkbox=-1
checkboxCheck=#123456
divider=#40302010

WPS
Pretend it's Mona Lisa here
WPE
";
let theme = Attheme::from_bytes(contents);

let mut variables = theme.variables.iter();
assert_eq!(
    variables.next(),
    Some((&"checkbox".to_string(), &Color::new(255, 255, 255, 255))),
);
assert_eq!(
    variables.next(),
    Some((
        &"checkboxCheck".to_string(),
        &Color::new(0x12, 0x34, 0x56, 0xff)),
    ),
);
assert_eq!(
    variables.next(),
    Some((&"divider".to_string(), &Color::new(0x30, 0x20, 0x10, 0x40))),
);
assert_eq!(variables.next(), None);

assert_eq!(
  theme.wallpaper,
  Some(b"Pretend it's Mona Lisa here".to_vec()),
);

Notes

If Telegram can't parse something, it will simply ignore it. This crate resembles this behavior.

Though Telegram only recognizes .jpg images, the crate does not check if the image is a valid .jpg. You should do it on your own.

#[must_use] pub fn to_bytes(&self, color_signature: ColorSignature) -> Vec<u8>[src]

Serializes the theme.

Examples

use attheme::{Attheme, Color, ColorSignature};

let mut theme = Attheme::new();

theme.variables.insert("divider".to_string(), Color::new(1, 2, 3, 4));
theme.variables.insert(
    "checkbox".to_string(),
    Color::new(255, 255, 255, 255),
);

let expected_contents = b"divider=67174915
checkbox=-1
".to_vec();

assert_eq!(theme.to_bytes(ColorSignature::Int), expected_contents);

theme.wallpaper = Some(b"Pretend it's Mona Lisa here".to_vec());

let expected_contents = b"divider=#04010203
checkbox=#ffffffff

WPS
Pretend it's Mona Lisa here
WPE
".to_vec();

assert_eq!(theme.to_bytes(ColorSignature::Hex), expected_contents);

pub fn fallback_to_other(&mut self, other: Self)[src]

Fallbacks self to other:

  • All variables that exist in other but not in self are added to self;
  • If self doesn't have a wallpaper, other's wallpaper is moved to self.

Examples

Basic usage

use attheme::{Attheme, Color};

let mut first_theme = Attheme::new();
let mut second_theme = Attheme::new();
let wallpaper = b"Just pretending".to_vec();

first_theme.variables.insert(
    "checkbox".to_string(),
    Color::new(255, 255, 255, 255),
);
first_theme.wallpaper = Some(wallpaper.clone());
second_theme.variables.insert(
    "checkbox".to_string(),
    Color::new(0x80, 0x80, 0x80, 0x80),
);
second_theme.variables.insert(
    "divider".to_string(),
    Color::new(0x40, 0x40, 0x40, 0x40),
);

first_theme.fallback_to_other(second_theme.clone());

assert_eq!(
    first_theme.variables["checkbox"],
    Color::new(255, 255, 255, 255),
);
assert_eq!(
  first_theme.variables["divider"],
  second_theme.variables["divider"],
);
assert_eq!(first_theme.wallpaper, Some(wallpaper));

Imitating Telegram's behavior

theme.fallback_to_self(attheme::FALLBACKS);
theme.fallback_to_other(attheme::default_themes::default());

pub fn fallback_to_self(&mut self, fallback_map: &[(&str, &str)])[src]

Fallbacks variables to other existing variabled according to the map.

Examples

Basic usage

use attheme::{Attheme, Color};

let mut theme = Attheme::new();
theme.variables.insert("foo".to_string(), Color::new(0, 0, 0, 0));
theme.fallback_to_self(&[("bar", "foo"), ("eggs", "spam")]);

assert_eq!(theme.variables.get("bar"), Some(&Color::new(0, 0, 0, 0)));
assert_eq!(theme.variables.get("eggs"), None);

Imitating Telegram's behavior

theme.fallback_to_self(attheme::FALLBACKS);
theme.fallback_to_other(attheme::default_themes::default());

Trait Implementations

impl Clone for Attheme[src]

impl Default for Attheme[src]

impl PartialEq<Attheme> for Attheme[src]

impl Debug for Attheme[src]

Auto Trait Implementations

impl Send for Attheme

impl Sync for Attheme

impl Unpin for Attheme

impl UnwindSafe for Attheme

impl RefUnwindSafe for Attheme

Blanket Implementations

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.

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

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

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

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]