Skip to content

Commit f864235

Browse files
committed
fix: use bitflags for MessageBoxButton
1 parent f799b17 commit f864235

5 files changed

Lines changed: 21 additions & 60 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ keywords = ["async", "gui"]
1414
compio = "0.15.0"
1515
compio-log = "0.1.0"
1616

17+
bitflags = "2"
1718
cfg-if = "1"
1819
euclid = "0.22"
1920
futures-util = { version = "0.3", features = ["alloc"] }

src/ui/gtk/msgbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl MessageBox {
110110
title: String::new(),
111111
instr: String::new(),
112112
style: MessageBoxStyle::None,
113-
btns: MessageBoxButton::None,
113+
btns: MessageBoxButton::empty(),
114114
cbtns: vec![],
115115
}
116116
}

src/ui/msgbox.rs

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
2-
31
use crate::{MaybeBorrowedWindow, ui::sys};
42

53
/// Style of message box.
@@ -16,60 +14,22 @@ pub enum MessageBoxStyle {
1614
Error,
1715
}
1816

19-
/// The pre-defined message box buttons.
20-
#[repr(i32)]
21-
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
22-
#[non_exhaustive]
23-
pub enum MessageBoxButton {
24-
/// No pre-defined button.
25-
#[default]
26-
None = 0,
27-
/// "Ok"
28-
Ok = 1 << 0,
29-
/// "Yes"
30-
Yes = 1 << 1,
31-
/// "No"
32-
No = 1 << 2,
33-
/// "Cancel"
34-
Cancel = 1 << 3,
35-
/// "Retry"
36-
Retry = 1 << 4,
37-
/// "Close"
38-
Close = 1 << 5,
39-
}
40-
41-
impl MessageBoxButton {
42-
/// Check if it contains specific pre-defined button.
43-
pub fn contains(&self, v: Self) -> bool {
44-
*self & v == v
45-
}
46-
}
47-
48-
impl BitOr for MessageBoxButton {
49-
type Output = MessageBoxButton;
50-
51-
fn bitor(self, rhs: Self) -> Self::Output {
52-
unsafe { std::mem::transmute(self as i32 | rhs as i32) }
53-
}
54-
}
55-
56-
impl BitOrAssign for MessageBoxButton {
57-
fn bitor_assign(&mut self, rhs: Self) {
58-
*self = *self | rhs;
59-
}
60-
}
61-
62-
impl BitAnd for MessageBoxButton {
63-
type Output = MessageBoxButton;
64-
65-
fn bitand(self, rhs: Self) -> Self::Output {
66-
unsafe { std::mem::transmute(self as i32 & rhs as i32) }
67-
}
68-
}
69-
70-
impl BitAndAssign for MessageBoxButton {
71-
fn bitand_assign(&mut self, rhs: Self) {
72-
*self = *self & rhs;
17+
bitflags::bitflags! {
18+
/// The pre-defined message box buttons.
19+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
20+
pub struct MessageBoxButton: i32 {
21+
/// "Ok"
22+
const Ok = 1 << 0;
23+
/// "Yes"
24+
const Yes = 1 << 1;
25+
/// "No"
26+
const No = 1 << 2;
27+
/// "Cancel"
28+
const Cancel = 1 << 3;
29+
/// "Retry"
30+
const Retry = 1 << 4;
31+
/// "Close"
32+
const Close = 1 << 5;
7333
}
7434
}
7535

src/ui/qt/msgbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl MessageBox {
112112
title: String::new(),
113113
instr: String::new(),
114114
style: MessageBoxStyle::None,
115-
btns: MessageBoxButton::None,
115+
btns: MessageBoxButton::empty(),
116116
cbtns: vec![],
117117
}
118118
}

src/ui/windows/msgbox.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async fn msgbox_custom(
4646
hwndParent: parent_handle as _,
4747
hInstance: null_mut(),
4848
dwFlags: TDF_ALLOW_DIALOG_CANCELLATION | TDF_SIZE_TO_CONTENT,
49-
dwCommonButtons: btns as _,
49+
dwCommonButtons: btns.bits(),
5050
pszWindowTitle: title.as_ptr(),
5151
Anonymous1: TASKDIALOGCONFIG_0 {
5252
pszMainIcon: match style {
@@ -133,7 +133,7 @@ impl MessageBox {
133133
title: U16CString::new(),
134134
instr: U16CString::new(),
135135
style: MessageBoxStyle::None,
136-
btns: MessageBoxButton::None,
136+
btns: MessageBoxButton::empty(),
137137
cbtns: vec![],
138138
}
139139
}

0 commit comments

Comments
 (0)