[−][src]Struct tdesktop_theme::TdesktopTheme
Represents a .tdesktop-theme
file structure.
Fields
wallpaper: Option<Wallpaper>
Holds the theme's wallpaper.
Implementations
impl TdesktopTheme
[src]
pub fn new() -> 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);
pub fn with_capacity(n: usize) -> TdesktopTheme
[src]
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]
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]
&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]
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]
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]
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]
&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]
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]
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]
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 is_empty(&self) -> bool
[src]
Returns true
if the theme has no variables.
Example
use tdesktop_theme::*; let mut theme = TdesktopTheme::new(); assert!(theme.is_empty()); theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap(); assert!(!theme.is_empty());
pub fn variables(&self) -> Keys<'_, String, Value>
[src]
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 to_palette_bytes(&self) -> Vec<u8>
[src]
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.to_palette_bytes(), b"windowBg: #ffffffff; windowActiveBg: windowBg; ".to_vec());
pub fn to_zip_bytes(&self) -> Result<Vec<u8>, ZipError>
[src]
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_bytes().unwrap(), ).unwrap();
pub fn variables_mut(&mut self) -> IterMut<'_, String, Value>
[src]
Returns an interator over mutable color values.
Example
use tdesktop_theme::*; let mut theme = TdesktopTheme::new(); theme.set_variable("windowBg".to_string(), [0xff; 4]).unwrap(); for (variable, value) in theme.variables_mut() { *value = Value::Color([0x00; 4]); } assert_eq!( theme.get_variable("windowBg"), Some(&Value::Color([0x00; 4])), );
Trait Implementations
impl<'a> Add<&'a TdesktopTheme> 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())), );
type Output = TdesktopTheme
The resulting type after applying the +
operator.
pub fn add(self, other: &TdesktopTheme) -> Self::Output
[src]
impl Add<TdesktopTheme> 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.
type Output = TdesktopTheme
The resulting type after applying the +
operator.
pub fn add(self, other: TdesktopTheme) -> Self::Output
[src]
impl AddAssign<TdesktopTheme> 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())), );
pub fn add_assign(&mut self, other: TdesktopTheme)
[src]
impl<'a> BitOr<&'a TdesktopTheme> 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 = default_themes::classic(); 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.
pub fn bitor(self, other: &TdesktopTheme) -> Self::Output
[src]
impl BitOr<TdesktopTheme> 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.
type Output = TdesktopTheme
The resulting type after applying the |
operator.
pub fn bitor(self, other: TdesktopTheme) -> Self::Output
[src]
impl BitOrAssign<TdesktopTheme> 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 = default_themes::classic(); 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])), );
pub fn bitor_assign(&mut self, other: TdesktopTheme)
[src]
impl Clone for TdesktopTheme
[src]
pub fn clone(&self) -> TdesktopTheme
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for TdesktopTheme
[src]
impl Default for TdesktopTheme
[src]
pub fn default() -> TdesktopTheme
[src]
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); }, }; };
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?
pub fn into_iter(self) -> Self::IntoIter
[src]
impl PartialEq<TdesktopTheme> for TdesktopTheme
[src]
pub fn eq(&self, other: &TdesktopTheme) -> bool
[src]
pub fn ne(&self, other: &TdesktopTheme) -> bool
[src]
impl StructuralPartialEq for TdesktopTheme
[src]
Auto Trait Implementations
impl RefUnwindSafe for TdesktopTheme
[src]
impl Send for TdesktopTheme
[src]
impl Sync for TdesktopTheme
[src]
impl Unpin for TdesktopTheme
[src]
impl UnwindSafe for TdesktopTheme
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,