winio_ui_winui/widgets/
progress.rs1use inherit_methods_macro::inherit_methods;
2use windows::core::Interface;
3use winio_handle::AsContainer;
4use winio_primitive::{Point, Size};
5use winui3::Microsoft::UI::Xaml::Controls as MUXC;
6
7use crate::{Result, Widget};
8
9#[derive(Debug)]
10pub struct Progress {
11 handle: Widget,
12 progress_bar: MUXC::ProgressBar,
13}
14
15#[inherit_methods(from = "self.handle")]
16impl Progress {
17 pub fn new(parent: impl AsContainer) -> Result<Self> {
18 let progress_bar = MUXC::ProgressBar::new()?;
19 Ok(Self {
20 handle: Widget::new(parent, progress_bar.cast()?)?,
21 progress_bar,
22 })
23 }
24
25 pub fn is_visible(&self) -> Result<bool>;
26
27 pub fn set_visible(&mut self, v: bool) -> Result<()>;
28
29 pub fn is_enabled(&self) -> Result<bool>;
30
31 pub fn set_enabled(&mut self, v: bool) -> Result<()>;
32
33 pub fn preferred_size(&self) -> Result<Size> {
34 let size = self.handle.preferred_size()?;
35 Ok(Size::new(0.0, size.height))
36 }
37
38 pub fn loc(&self) -> Result<Point>;
39
40 pub fn set_loc(&mut self, p: Point) -> Result<()>;
41
42 pub fn size(&self) -> Result<Size>;
43
44 pub fn set_size(&mut self, v: Size) -> Result<()>;
45
46 pub fn tooltip(&self) -> Result<String>;
47
48 pub fn set_tooltip(&mut self, s: impl AsRef<str>) -> Result<()>;
49
50 pub fn minimum(&self) -> Result<usize> {
51 Ok(self.progress_bar.Minimum()? as usize)
52 }
53
54 pub fn set_minimum(&mut self, v: usize) -> Result<()> {
55 self.progress_bar.SetMinimum(v as _)?;
56 Ok(())
57 }
58
59 pub fn maximum(&self) -> Result<usize> {
60 Ok(self.progress_bar.Maximum()? as usize)
61 }
62
63 pub fn set_maximum(&mut self, v: usize) -> Result<()> {
64 self.progress_bar.SetMaximum(v as _)?;
65 Ok(())
66 }
67
68 pub fn pos(&self) -> Result<usize> {
69 Ok(self.progress_bar.Value()? as usize)
70 }
71
72 pub fn set_pos(&mut self, pos: usize) -> Result<()> {
73 self.progress_bar.SetValue(pos as f64)?;
74 Ok(())
75 }
76
77 pub fn is_indeterminate(&self) -> Result<bool> {
78 self.progress_bar.IsIndeterminate()
79 }
80
81 pub fn set_indeterminate(&mut self, indeterminate: bool) -> Result<()> {
82 self.progress_bar.SetIsIndeterminate(indeterminate)?;
83 Ok(())
84 }
85}
86
87winio_handle::impl_as_widget!(Progress, handle);