Skip to main content

atk/
attribute.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use glib::GString;
5use glib::translate::*;
6use std::fmt;
7
8/// AtkAttribute is a string name/value pair representing a generic
9/// attribute. This can be used to expose additional information from
10/// an accessible object as a whole (see `atk_object_get_attributes()`)
11/// or an document (see `atk_document_get_attributes()`). In the case of
12/// text attributes (see `atk_text_get_default_attributes()`),
13/// [`TextAttribute`][crate::TextAttribute] enum defines all the possible text attribute
14/// names. You can use [`TextAttribute::name()`][crate::TextAttribute::name()] to get the string
15/// name from the enum value. See also [`TextAttribute::for_name()`][crate::TextAttribute::for_name()]
16/// and [`TextAttribute::value()`][crate::TextAttribute::value()] for more information.
17///
18/// A string name/value pair representing a generic attribute.
19#[doc(alias = "AtkAttribute")]
20pub struct Attribute {
21    pub name: GString,
22    pub value: GString,
23}
24
25impl fmt::Display for Attribute {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        f.debug_struct("Attribute")
28            .field("name", &self.name)
29            .field("value", &self.value)
30            .finish()
31    }
32}
33
34#[doc(hidden)]
35impl FromGlib<ffi::AtkAttribute> for Attribute {
36    unsafe fn from_glib(value: ffi::AtkAttribute) -> Self {
37        unsafe {
38            skip_assert_initialized!();
39            Self {
40                name: from_glib_full(value.name),
41                value: from_glib_full(value.value),
42            }
43        }
44    }
45}
46
47#[doc(hidden)]
48impl IntoGlib for Attribute {
49    type GlibType = ffi::AtkAttribute;
50
51    fn into_glib(self) -> ffi::AtkAttribute {
52        ffi::AtkAttribute {
53            name: self.name.to_glib_none().0,
54            value: self.value.to_glib_none().0,
55        }
56    }
57}