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
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;
use glib::GString;
use std::fmt;

/// AtkAttribute is a string name/value pair representing a generic
/// attribute. This can be used to expose additional information from
/// an accessible object as a whole (see `atk_object_get_attributes()`)
/// or an document (see `atk_document_get_attributes()`). In the case of
/// text attributes (see `atk_text_get_default_attributes()`),
/// [`TextAttribute`][crate::TextAttribute] enum defines all the possible text attribute
/// names. You can use [`TextAttribute::name()`][crate::TextAttribute::name()] to get the string
/// name from the enum value. See also [`TextAttribute::for_name()`][crate::TextAttribute::for_name()]
/// and [`TextAttribute::value()`][crate::TextAttribute::value()] for more information.
///
/// A string name/value pair representing a generic attribute.
#[doc(alias = "AtkAttribute")]
pub struct Attribute {
    pub name: GString,
    pub value: GString,
}

impl fmt::Display for Attribute {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("Attribute")
            .field("name", &self.name)
            .field("value", &self.value)
            .finish()
    }
}

#[doc(hidden)]
impl FromGlib<ffi::AtkAttribute> for Attribute {
    unsafe fn from_glib(value: ffi::AtkAttribute) -> Self {
        skip_assert_initialized!();
        Self {
            name: from_glib_full(value.name),
            value: from_glib_full(value.value),
        }
    }
}

#[doc(hidden)]
impl IntoGlib for Attribute {
    type GlibType = ffi::AtkAttribute;

    fn into_glib(self) -> ffi::AtkAttribute {
        ffi::AtkAttribute {
            name: self.name.to_glib_none().0,
            value: self.value.to_glib_none().0,
        }
    }
}