allow window_decorations to work with config_builder

We need to manually convert to string, as the default ToDynamic
impl encodes the underlying bits value from the bitfield and
that doesn't round trip with the try_from String impl
This commit is contained in:
Wez Furlong committed 2023-02-01 15:01:28 -07:00
1 parent 44f31c9667
commit b4dae6c2a3
1 file changed
+23 -1
+23 -1
View File
@@ -1271,7 +1271,7 @@ impl KeyEvent {
bitflags! {
#[derive(Deserialize, Serialize, FromDynamic, ToDynamic)]
#[serde(try_from = "String")]
#[dynamic(try_from = "String")]
#[dynamic(try_from = "String", into = "String")]
pub struct WindowDecorations: u8 {
const TITLE = 1;
const RESIZE = 2;
@@ -1283,6 +1283,28 @@ bitflags! {
}
}
impl Into<String> for &WindowDecorations {
fn into(self) -> String {
let mut s = vec![];
if self.contains(WindowDecorations::TITLE) {
s.push("TITLE");
}
if self.contains(WindowDecorations::RESIZE) {
s.push("RESIZE");
}
if self.contains(WindowDecorations::MACOS_FORCE_ENABLE_SHADOW) {
s.push("MACOS_FORCE_ENABLE_SHADOW");
} else if self.contains(WindowDecorations::MACOS_FORCE_DISABLE_SHADOW) {
s.push("MACOS_FORCE_DISABLE_SHADOW");
}
if s.is_empty() {
"NONE".to_string()
} else {
s.join("|")
}
}
}
impl TryFrom<String> for WindowDecorations {
type Error = String;
fn try_from(s: String) -> std::result::Result<WindowDecorations, String> {