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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! AppProgressIndicator module for wxDragon.
//!
//! This module provides a safe wrapper around wxWidgets' wxAppProgressIndicator class.
use crate::window::WxWidget;
use wxdragon_sys as ffi;
/// # Example
///
/// ```rust,no_run
/// use wxdragon::prelude::*;
///
/// wxdragon::main(|_| {
/// let frame = Frame::builder().with_title("My App").build();
///
/// let app_progress = AppProgressIndicator::new(None);
/// app_progress.set_value(0);
/// app_progress.set_range(1000);
/// let mut progress = 0;
/// frame.on_idle(move |_e| {
/// if progress < 1000 {
/// progress += 1;
/// app_progress.set_value(progress);
/// }
/// });
///
/// frame.show(true);
/// })
/// .unwrap();
/// ```
pub struct AppProgressIndicator {
ptr: *mut ffi::wxd_AppProgressIndicator_t,
}
impl AppProgressIndicator {
/// Create a new application progress
pub fn new(parent: Option<&dyn WxWidget>) -> Self {
let parent_ptr = if let Some(p) = parent {
p.handle_ptr()
} else {
std::ptr::null_mut()
};
let ptr = unsafe { ffi::wxd_AppProgressIndicator_Create(parent_ptr) };
Self { ptr }
}
// Check if the application progress display is available.
pub fn is_available(&self) -> bool {
unsafe { ffi::wxd_AppProgressIndicator_IsAvailable(self.ptr) }
}
// Set the progress value in taskbar button of parent window.
pub fn set_value(&self, value: i32) {
unsafe { ffi::wxd_AppProgressIndicator_SetValue(self.ptr, value) }
}
// Set the progress range in taskbar button of parent window.
pub fn set_range(&self, range: i32) {
unsafe { ffi::wxd_AppProgressIndicator_SetRange(self.ptr, range) }
}
// Makes the progress bar run in indeterminate mode.
pub fn pulse(&self) {
unsafe { ffi::wxd_AppProgressIndicator_Pulse(self.ptr) }
}
}
impl Drop for AppProgressIndicator {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe { ffi::wxd_AppProgressIndicator_Destroy(self.ptr) };
}
}
}