Skip to main content

yse_ui/widgets/
disk_map.rs

1//! Painted disk-usage overview wrapper.
2
3use crate::bridge as ffi;
4use crate::bridge::Void;
5use crate::component::Component;
6use crate::widgets::{IntoWidget, widget_wrapper};
7use std::rc::Rc;
8use yse_model::Signal;
9
10/// A painted proportional disk-usage overview.
11pub struct DiskMap {
12    pub(crate) inner: Rc<Component>,
13}
14
15impl DiskMap {
16    /// Replace the displayed segments. Shares are percentages and need not add
17    /// up exactly to 100; the widget normalizes them for display.
18    pub fn set_segments(
19        &self,
20        labels: impl IntoIterator<Item = String>,
21        shares: impl IntoIterator<Item = f64>,
22    ) {
23        if self.inner.is_alive() {
24            unsafe {
25                ffi::disk_map_set_segments(
26                    self.inner.raw(),
27                    labels.into_iter().collect(),
28                    shares.into_iter().collect(),
29                )
30            };
31        }
32    }
33}
34
35widget_wrapper!(DiskMap);