Struct tdesktop_theme::TdesktopTheme[][src]

pub struct TdesktopTheme {
    pub wallpaper: Option<Wallpaper>,
    // some fields omitted
}

Represents a .tdesktop-theme file structure.

Fields

Holds the theme's wallpaper.

Methods

impl TdesktopTheme
[src]

Creates a new, empty TdesktopTheme.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

assert_eq!(theme.wallpaper, None);
assert_eq!(theme.len(), 0);

Creates an empty theme with capacity for n variables.

You may need this if you're hardcoding a theme, so you only allocate memory once instead of, for example, 451 times. generate_default_theme uses this.

Parsers the bytes and returns the parse result. Parses both .tdesktop-palette and .tdesktop-theme files.

Examples

use tdesktop_theme::*;

let contents = b"windowBg: #ffffff; // this is a comment
/*
  this is a multiline comment
*/ windowFg: #000000;
windowBoldFg: windowFg;";

let theme = TdesktopTheme::from_bytes(contents).unwrap();

assert_eq!(theme.wallpaper, None);
assert_eq!(
  theme.get_variable("windowBg"),
  Some(&Value::Color([0xff; 4])),
);
assert_eq!(
  theme.get_variable("windowFg"),
  Some(&Value::Color([0x00, 0x00, 0x00, 0xff])),
);
assert_eq!(
  theme.get_variable("windowBoldFg"),
  Some(&Value::Link("windowFg".to_string())),
);

Sets variable's value to Value::color(color).

Notes

If variable's name is invalid, then an error is returned.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
assert_eq!(
  theme.get_variable("windowBg"),
  Some(&Value::Color([0xff; 4])),
);

Gets the variable's raw value. A raw value means that it may be either a color or a link to another variable.

Example

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();
theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
theme
  .link_variable("windowActiveBg".to_string(), "windowBg".to_string())
  .unwrap();

assert_eq!(
  theme.get_variable("windowBg"),
  Some(&Value::Color([0xff; 4])),
);

assert_eq!(
  theme.get_variable("windowActiveBg"),
  Some(&Value::Link("windowBg".to_string())),
);

Checks that the theme contains variable and returns a boolean.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();

assert!(theme.has_variable("windowBg"));
assert!(!theme.has_variable("windowFg"));

Deletes variable.

Notes

Since IndexMap.remove is used under the hood, variables order is distorted.

This method won't unlink variables that depended on this variable before deleting.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
theme.delete_variable("windowBg");

assert!(!theme.has_variable("windowBg"));

Links variable to link_to.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();
theme
  .link_variable("windowBoldFg".to_string(), "windowFg".to_string())
  .unwrap();

assert_eq!(
  theme.get_variable("windowBoldFg"),
  Some(&Value::Link("windowFg".to_string()))
);

Gets variables's real color value and assigns it to variable, so that variable doesn't depend on other variables anymore.

Notes

If it can't resolve variable to a color, then variable is deleted.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowFg".to_string(), [0x00; 4]).unwrap();
theme
  .link_variable("windowBoldFg".to_string(), "windowFg".to_string())
  .unwrap();
theme.unlink_variable("windowBoldFg");

assert_eq!(
  theme.get_variable("windowBoldFg"),
  Some(&Value::Color([0x00; 4])),
);

Gets variable's real color value. That is, this method resolves all links until it gets a color value or None.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowFg".to_string(), [0xff; 4]).unwrap();
theme
  .link_variable("windowBoldFg".to_string(), "windowFg".to_string())
  .unwrap();

assert_eq!(
  theme.resolve_variable("windowBoldFg"),
  Some(&[0xff; 4]),
);

Returns amount of variables in the theme.

Example

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

assert_eq!(theme.len(), 0);
theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
assert_eq!(theme.len(), 1);

Returns an iterator over the theme's variables.

Examples

use tdesktop_theme::*;

let theme = TdesktopTheme::from_bytes(b"
  windowBg: #ffffff;
  windowFg: #000000;
").unwrap();

for variable in theme.variables() {
  println!("{}", variable);
  assert!(theme.has_variable(variable));
}

Serializes the palette of the theme. That is, only the variables without the wallpaper; the result is to be saved in a .tdesktop-palette file.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
theme
  .link_variable("windowActiveBg".to_string(), "windowBg".to_string())
  .unwrap();

assert_eq!(theme.palette_to_bytes(), b"windowBg: #ffffffff;
windowActiveBg: windowBg;
".to_vec());

Zips the theme. It returns a buffer that is to be saved as .tdesktop-theme.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
theme
  .link_variable("windowActiveBg".to_string(), "windowBg".to_string())
  .unwrap();

// Go check that on your own!
std::fs::write(
  "./tests/ignore/my-theme.tdesktop-theme",
  theme.to_zip().unwrap(),
).unwrap();

Trait Implementations

impl PartialEq for TdesktopTheme
[src]

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

This method tests for !=.

impl Clone for TdesktopTheme
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> IntoIterator for &'a TdesktopTheme
[src]

Iterates over variables and their raw values.

Examples

use tdesktop_theme::*;

let theme = TdesktopTheme::from_bytes(b"
  windowFg: #212121;
  windowBoldFg: windowFg;
").unwrap();

for (variable, value) in &theme {
  match value {
    Value::Color([red, green, blue, alpha]) => {
      println!("{} has the value:", variable);
      println!("  Red: {}", red);
      println!("  Green: {}", green);
      println!("  Blue: {}", blue);
      println!("  Alpha: {}", alpha);
    },
    Value::Link(link) => {
      println!("{} is linked to {}", variable, link);
    },
  };
};

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a> Add for &'a TdesktopTheme
[src]

Clones all variables from other to self.

Notes

other's wallpaper is taken if it's Some(...). Otherwise, self's wallpaper is taken.

You can do both &theme + &other_theme and theme + other_theme. In the first case, variables and wallpapers are cloned; in the second case, theme and other_theme are borrowed. Choose the right way depending on your case.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
theme.set_variable("windowFg".to_string(), [0x00; 4]).unwrap();
theme.wallpaper = Some(Wallpaper {
  wallpaper_type: WallpaperType::Tiled,
  extension: WallpaperExtension::Jpg,
  bytes: b"Pretend it's a wallpaper".to_vec(),
});

let mut other_theme = TdesktopTheme::new();

other_theme.set_variable("windowFg".to_string(), [0x21; 4]).unwrap();
other_theme
  .link_variable("windowBoldFg".to_string(), "windowFg".to_string())
  .unwrap();

let third_theme = &theme + &other_theme;

assert_eq!(third_theme.wallpaper, theme.wallpaper);
assert_eq!(
  third_theme.get_variable("windowBg"),
  Some(&Value::Color([0xff; 4])),
);
assert_eq!(
  third_theme.get_variable("windowFg"),
  Some(&Value::Color([0x21; 4])),
);
assert_eq!(
  third_theme.get_variable("windowBoldFg"),
  Some(&Value::Link("windowFg".to_string())),
);

The resulting type after applying the + operator.

Performs the + operation.

impl Add for TdesktopTheme
[src]

Takes all variables from other and adds to self.

Notes

other's wallpaper is taken if it's Some(...). Otherwise, self's wallpaper is taken.

You can do both &theme + &other_theme and theme + other_theme. In the first case, variables and wallpapers are cloned; in the second case, theme and other_theme are borrowed. Choose the right way depending on your case.

The resulting type after applying the + operator.

Performs the + operation.

impl AddAssign for TdesktopTheme
[src]

Clones all variables from other to self.

Notes

other's wallpaper is taken if it's Some(...).

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap();
theme.set_variable("windowFg".to_string(), [0x00; 4]).unwrap();
theme.wallpaper = Some(Wallpaper {
  wallpaper_type: WallpaperType::Tiled,
  extension: WallpaperExtension::Jpg,
  bytes: b"Pretend it's a wallpaper".to_vec(),
});

let mut other_theme = TdesktopTheme::new();

other_theme.set_variable("windowFg".to_string(), [0x21; 4]).unwrap();
other_theme
  .link_variable("windowBoldFg".to_string(), "windowFg".to_string())
  .unwrap();

theme += other_theme;

assert_eq!(theme.wallpaper, Some(Wallpaper {
  wallpaper_type: WallpaperType::Tiled,
  extension: WallpaperExtension::Jpg,
  bytes: b"Pretend it's a wallpaper".to_vec(),
}));

assert_eq!(
  theme.get_variable("windowBg"),
  Some(&Value::Color([0xff; 4])),
);
assert_eq!(
  theme.get_variable("windowFg"),
  Some(&Value::Color([0x21; 4])),
);
assert_eq!(
  theme.get_variable("windowBoldFg"),
  Some(&Value::Link("windowFg".to_string())),
);

Performs the += operation.

impl<'a> BitOr for &'a TdesktopTheme
[src]

Clones other's variables that are absent in self.

Notes

other's wallpaper is taken if self's wallpaper is None.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0x00; 4]).unwrap();

let default_theme = utils::generate_default_theme();

let normalized_theme = &theme | &default_theme;

assert_eq!(
  normalized_theme.get_variable("windowBg"),
  Some(&Value::Color([0x00; 4])),
);

assert_eq!(
  normalized_theme.get_variable("windowFg"),
  Some(&Value::Color([0x00, 0x00, 0x00, 0xff])),
);

The resulting type after applying the | operator.

Performs the | operation.

impl BitOr for TdesktopTheme
[src]

Moves other's variables that are absent in self.

Notes

other's wallpaper is taken if self's wallpaper is None.

You can do both &theme | &other_theme and theme | other_theme. In the first case, variables and wallpapers are cloned; in the second case, theme and other_theme are borrowed. Choose the right way depending on your case.

The resulting type after applying the | operator.

Performs the | operation.

impl BitOrAssign for TdesktopTheme
[src]

Clones other's variables that are absent in self.

Notes

other's wallpaper is taken if self's wallpaper is None.

You can do both &theme | &other_theme and theme | other_theme. In the first case, variables and wallpapers are cloned; in the second case, theme and other_theme are borrowed. Choose the right way depending on your case.

Examples

use tdesktop_theme::*;

let mut theme = TdesktopTheme::new();

theme.set_variable("windowBg".to_string(), [0x00; 4]).unwrap();

let default_theme = utils::generate_default_theme();

let normalized_theme = &theme | &default_theme;

assert_eq!(
  normalized_theme.get_variable("windowBg"),
  Some(&Value::Color([0x00; 4])),
);

assert_eq!(
  normalized_theme.get_variable("windowFg"),
  Some(&Value::Color([0x00, 0x00, 0x00, 0xff])),
);

Performs the |= operation.

Auto Trait Implementations