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