accesskit_unix/atspi/interfaces/
value.rs

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
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use accesskit_atspi_common::PlatformNode;
use zbus::fdo;

pub(crate) struct ValueInterface {
    node: PlatformNode,
}

impl ValueInterface {
    pub fn new(node: PlatformNode) -> Self {
        Self { node }
    }

    fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
        |error| crate::util::map_error_from_node(&self.node, error)
    }
}

#[dbus_interface(name = "org.a11y.atspi.Value")]
impl ValueInterface {
    #[dbus_interface(property)]
    fn minimum_value(&self) -> fdo::Result<f64> {
        self.node.minimum_value().map_err(self.map_error())
    }

    #[dbus_interface(property)]
    fn maximum_value(&self) -> fdo::Result<f64> {
        self.node.maximum_value().map_err(self.map_error())
    }

    #[dbus_interface(property)]
    fn minimum_increment(&self) -> fdo::Result<f64> {
        self.node.minimum_increment().map_err(self.map_error())
    }

    #[dbus_interface(property)]
    fn current_value(&self) -> fdo::Result<f64> {
        self.node.current_value().map_err(self.map_error())
    }

    #[dbus_interface(property)]
    fn set_current_value(&mut self, value: f64) -> fdo::Result<()> {
        self.node.set_current_value(value).map_err(self.map_error())
    }
}