Struct tdesktop_theme::TdesktopTheme [−][src]
Represents a .tdesktop-theme
file structure.
Fields
wallpaper: Option<Wallpaper>
Holds the theme's wallpaper.
Methods
impl TdesktopTheme
[src]
impl TdesktopTheme
pub fn new() -> TdesktopTheme
[src]
pub fn new() -> TdesktopTheme
Creates a new, empty TdesktopTheme
.
Examples
use tdesktop_theme::*; let mut theme = TdesktopTheme::new(); assert_eq!(theme.wallpaper, None); assert_eq!(theme.len(), 0);
pub fn with_capacity(n: usize) -> TdesktopTheme
[src]
pub fn with_capacity(n: usize) -> TdesktopTheme
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.
pub fn from_bytes(bytes: &[u8]) -> Result<TdesktopTheme, ParseError>
[src]
pub fn from_bytes(bytes: &[u8]) -> Result<TdesktopTheme, ParseError>
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())), );
pub fn set_variable(
&mut self,
variable: String,
color: [u8; 4]
) -> Result<(), String>
[src]
pub fn set_variable(
&mut self,
variable: String,
color: [u8; 4]
) -> Result<(), 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])), );
pub fn get_variable(&self, variable: &str) -> Option<&Value>
[src]
pub fn get_variable(&self, variable: &str) -> Option<&Value>
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())), );
pub fn has_variable(&self, variable: &str) -> bool
[src]
pub fn has_variable(&self, variable: &str) -> bool
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"));
pub fn delete_variable(&mut self, variable: &str)
[src]
pub fn delete_variable(&mut self, variable: &str)
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"));
pub fn link_variable(
&mut self,
variable: String,
link_to: String
) -> Result<(), String>
[src]
pub fn link_variable(
&mut self,
variable: String,
link_to: String
) -> Result<(), String>
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())) );
pub fn unlink_variable(&mut self, variable: &str)
[src]
pub fn unlink_variable(&mut self, variable: &str)
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])), );
pub fn resolve_variable(&self, variable: &str) -> Option<&[u8; 4]>
[src]
pub fn resolve_variable(&self, variable: &str) -> Option<&[u8; 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]), );
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
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);
pub fn variables(&self) -> Keys<String, Value>
[src]
pub fn variables(&self) -> Keys<String, Value>
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)); }
pub fn palette_to_bytes(&self) -> Vec<u8>
[src]
pub fn palette_to_bytes(&self) -> Vec<u8>
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());
pub fn to_zip(&self) -> Result<Vec<u8>, ZipError>
[src]
pub fn to_zip(&self) -> Result<Vec<u8>, ZipError>
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]
impl PartialEq for TdesktopTheme
fn eq(&self, other: &TdesktopTheme) -> bool
[src]
fn eq(&self, other: &TdesktopTheme) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &TdesktopTheme) -> bool
[src]
fn ne(&self, other: &TdesktopTheme) -> bool
This method tests for !=
.
impl Clone for TdesktopTheme
[src]
impl Clone for TdesktopTheme
fn clone(&self) -> TdesktopTheme
[src]
fn clone(&self) -> TdesktopTheme
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a> IntoIterator for &'a TdesktopTheme
[src]
impl<'a> IntoIterator for &'a TdesktopTheme
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); }, }; };
type Item = (&'a String, &'a Value)
The type of the elements being iterated over.
type IntoIter = Iter<'a, String, Value>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'a> Add for &'a TdesktopTheme
[src]
impl<'a> Add for &'a TdesktopTheme
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())), );
type Output = TdesktopTheme
The resulting type after applying the +
operator.
fn add(self, other: &TdesktopTheme) -> Self::Output
[src]
fn add(self, other: &TdesktopTheme) -> Self::Output
Performs the +
operation.
impl Add for TdesktopTheme
[src]
impl Add for TdesktopTheme
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.
type Output = TdesktopTheme
The resulting type after applying the +
operator.
fn add(self, other: TdesktopTheme) -> Self::Output
[src]
fn add(self, other: TdesktopTheme) -> Self::Output
Performs the +
operation.
impl AddAssign for TdesktopTheme
[src]
impl AddAssign for TdesktopTheme
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())), );
fn add_assign(&mut self, other: TdesktopTheme)
[src]
fn add_assign(&mut self, other: TdesktopTheme)
Performs the +=
operation.
impl<'a> BitOr for &'a TdesktopTheme
[src]
impl<'a> BitOr for &'a TdesktopTheme
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])), );
type Output = TdesktopTheme
The resulting type after applying the |
operator.
fn bitor(self, other: &TdesktopTheme) -> Self::Output
[src]
fn bitor(self, other: &TdesktopTheme) -> Self::Output
Performs the |
operation.
impl BitOr for TdesktopTheme
[src]
impl BitOr for TdesktopTheme
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.
type Output = TdesktopTheme
The resulting type after applying the |
operator.
fn bitor(self, other: TdesktopTheme) -> Self::Output
[src]
fn bitor(self, other: TdesktopTheme) -> Self::Output
Performs the |
operation.
impl BitOrAssign for TdesktopTheme
[src]
impl BitOrAssign for TdesktopTheme
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])), );
fn bitor_assign(&mut self, other: TdesktopTheme)
[src]
fn bitor_assign(&mut self, other: TdesktopTheme)
Performs the |=
operation.
Auto Trait Implementations
impl Send for TdesktopTheme
impl Send for TdesktopTheme
impl Sync for TdesktopTheme
impl Sync for TdesktopTheme