1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// This file was generated by gir (4b09025) from gir-files (71d73f0)
// DO NOT EDIT

use StyleProperties;
use ffi;
use gdk;
use glib::translate::*;
use std::fmt;

glib_wrapper! {
    pub struct SymbolicColor(Shared<ffi::GtkSymbolicColor>);

    match fn {
        ref => |ptr| ffi::gtk_symbolic_color_ref(ptr),
        unref => |ptr| ffi::gtk_symbolic_color_unref(ptr),
    }
}

impl SymbolicColor {
    pub fn new_alpha(color: &SymbolicColor, factor: f64) -> SymbolicColor {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_new_alpha(color.to_glib_none().0, factor))
        }
    }

    pub fn new_literal(color: &gdk::RGBA) -> SymbolicColor {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_new_literal(color.to_glib_none().0))
        }
    }

    pub fn new_mix(color1: &SymbolicColor, color2: &SymbolicColor, factor: f64) -> SymbolicColor {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_new_mix(color1.to_glib_none().0, color2.to_glib_none().0, factor))
        }
    }

    pub fn new_name(name: &str) -> SymbolicColor {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_new_name(name.to_glib_none().0))
        }
    }

    pub fn new_shade(color: &SymbolicColor, factor: f64) -> SymbolicColor {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_new_shade(color.to_glib_none().0, factor))
        }
    }

    pub fn new_win32(theme_class: &str, id: i32) -> SymbolicColor {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_new_win32(theme_class.to_glib_none().0, id))
        }
    }

    pub fn resolve<'a, P: Into<Option<&'a StyleProperties>>>(&self, props: P) -> Option<gdk::RGBA> {
        let props = props.into();
        let props = props.to_glib_none();
        unsafe {
            let mut resolved_color = gdk::RGBA::uninitialized();
            let ret = from_glib(ffi::gtk_symbolic_color_resolve(self.to_glib_none().0, props.0, resolved_color.to_glib_none_mut().0));
            if ret { Some(resolved_color) } else { None }
        }
    }

    fn to_string(&self) -> String {
        unsafe {
            from_glib_full(ffi::gtk_symbolic_color_to_string(self.to_glib_none().0))
        }
    }
}

impl fmt::Display for SymbolicColor {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.to_string())
    }
}