accesskit_unix/atspi/interfaces/
value.rs

1// Copyright 2022 The AccessKit Authors. All rights reserved.
2// Licensed under the Apache License, Version 2.0 (found in
3// the LICENSE-APACHE file) or the MIT license (found in
4// the LICENSE-MIT file), at your option.
5
6use accesskit_atspi_common::PlatformNode;
7use zbus::fdo;
8
9pub(crate) struct ValueInterface {
10    node: PlatformNode,
11}
12
13impl ValueInterface {
14    pub fn new(node: PlatformNode) -> Self {
15        Self { node }
16    }
17
18    fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
19        |error| crate::util::map_error_from_node(&self.node, error)
20    }
21}
22
23#[dbus_interface(name = "org.a11y.atspi.Value")]
24impl ValueInterface {
25    #[dbus_interface(property)]
26    fn minimum_value(&self) -> fdo::Result<f64> {
27        self.node.minimum_value().map_err(self.map_error())
28    }
29
30    #[dbus_interface(property)]
31    fn maximum_value(&self) -> fdo::Result<f64> {
32        self.node.maximum_value().map_err(self.map_error())
33    }
34
35    #[dbus_interface(property)]
36    fn minimum_increment(&self) -> fdo::Result<f64> {
37        self.node.minimum_increment().map_err(self.map_error())
38    }
39
40    #[dbus_interface(property)]
41    fn current_value(&self) -> fdo::Result<f64> {
42        self.node.current_value().map_err(self.map_error())
43    }
44
45    #[dbus_interface(property)]
46    fn set_current_value(&mut self, value: f64) -> fdo::Result<()> {
47        self.node.set_current_value(value).map_err(self.map_error())
48    }
49}