use std::path::{Path, PathBuf};
use raw_window_handle::HasWindowHandle;
mod utils;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum MessageIcon {
Info,
Warning,
Error,
Question,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum MessageButtons {
Ok,
OkCancel,
YesNo,
YesNoCancel,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum MessageResult {
Ok,
Cancel,
Yes,
No,
}
#[derive(Copy, Clone)]
pub struct MessageBox<'a> {
pub title: &'a str,
pub message: &'a str,
pub icon: MessageIcon,
pub buttons: MessageButtons,
pub owner: Option<&'a dyn HasWindowHandle>,
}
impl<'a> MessageBox<'a> {
#[inline]
pub fn show(&self) -> Option<MessageResult> {
message_box(self)
}
}
#[derive(Copy, Clone, Debug)]
pub struct FileFilter<'a> {
pub desc: &'a str,
pub patterns: &'a [&'a str],
}
#[derive(Copy, Clone)]
pub struct FileDialog<'a> {
pub title: &'a str,
pub path: Option<&'a Path>,
pub filter: Option<&'a [FileFilter<'a>]>,
pub owner: Option<&'a dyn HasWindowHandle>,
}
impl<'a> FileDialog<'a> {
#[inline]
pub fn pick_file(&self) -> Option<PathBuf> {
pick_file(self)
}
#[inline]
pub fn pick_files(&self) -> Option<Vec<PathBuf>> {
pick_files(self)
}
#[inline]
pub fn save_file(&self) -> Option<PathBuf> {
save_file(self)
}
}
#[derive(Copy, Clone)]
pub struct FolderDialog<'a> {
pub title: &'a str,
pub directory: Option<&'a Path>,
pub owner: Option<&'a dyn HasWindowHandle>,
}
impl<'a> FolderDialog<'a> {
#[inline]
pub fn show(&self) -> Option<std::path::PathBuf> {
folder_dialog(self)
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum TextInputMode {
SingleLine,
MultiLine,
Password,
}
#[derive(Copy, Clone)]
pub struct TextInput<'a> {
pub title: &'a str,
pub message: &'a str,
pub value: &'a str,
pub mode: TextInputMode,
pub owner: Option<&'a dyn HasWindowHandle>,
}
impl<'a> TextInput<'a> {
#[inline]
pub fn show(&self) -> Option<String> {
text_input(self)
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct ColorValue {
pub red: u8,
pub green: u8,
pub blue: u8,
}
#[derive(Copy, Clone)]
pub struct ColorPicker<'a> {
pub title: &'a str,
pub value: ColorValue,
pub owner: Option<&'a dyn HasWindowHandle>,
}
impl<'a> ColorPicker<'a> {
#[inline]
pub fn show(&self) -> Option<ColorValue> {
color_picker(self)
}
}
#[derive(Copy, Clone, Debug)]
pub struct Notification<'a> {
pub app_id: &'a str,
pub title: &'a str,
pub message: &'a str,
pub icon: MessageIcon,
pub timeout: i32,
}
impl<'a> Notification<'a> {
pub const SHORT_TIMEOUT: i32 = 5000;
pub const LONG_TIMEOUT: i32 = 10000;
#[inline]
pub fn setup(app_id: &str) {
notify_setup(app_id);
}
#[inline]
pub fn show(&self) {
notify(self)
}
}
#[cfg(windows)]
mod win32;
#[cfg(windows)]
use win32::*;
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
))]
mod linux;
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
))]
use linux::*;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
use macos::*;
#[cfg(not(any(
windows,
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
target_os = "macos",
)))]
mod unsupported;
#[cfg(not(any(
windows,
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
target_os = "macos",
)))]
use unsupported::*;