-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Redo config for window vibrancy
- Loading branch information
Showing
6 changed files
with
160 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
mod format_bytes; | ||
mod fs_util; | ||
mod length_value; | ||
mod parse_rgba; | ||
mod path_ext; | ||
mod window_ext; | ||
|
||
pub use format_bytes::*; | ||
pub use fs_util::*; | ||
pub use length_value::*; | ||
pub use parse_rgba::*; | ||
pub use path_ext::*; | ||
pub use window_ext::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#[derive(Debug)] | ||
pub enum ColorError { | ||
InvalidFormat, | ||
InvalidValue, | ||
} | ||
|
||
pub fn parse_rgba( | ||
color_str: &str, | ||
) -> Result<(u8, u8, u8, u8), ColorError> { | ||
let content = color_str | ||
.trim_start_matches("rgba(") | ||
.trim_end_matches(")") | ||
.trim(); | ||
|
||
let parts: Vec<&str> = content.split(',').map(|s| s.trim()).collect(); | ||
|
||
if parts.len() != 4 { | ||
return Err(ColorError::InvalidFormat); | ||
} | ||
|
||
let r = parts[0].parse().map_err(|_| ColorError::InvalidValue)?; | ||
let g = parts[1].parse().map_err(|_| ColorError::InvalidValue)?; | ||
let b = parts[2].parse().map_err(|_| ColorError::InvalidValue)?; | ||
|
||
let a = if parts[3].ends_with('%') { | ||
let percent = parts[3] | ||
.trim_end_matches('%') | ||
.parse::<f32>() | ||
.map_err(|_| ColorError::InvalidValue)?; | ||
if percent < 0.0 || percent > 100.0 { | ||
return Err(ColorError::InvalidValue); | ||
} | ||
(percent / 100.0 * 255.0) as u8 | ||
} else { | ||
let alpha = parts[3] | ||
.parse::<f32>() | ||
.map_err(|_| ColorError::InvalidValue)?; | ||
if alpha < 0.0 || alpha > 1.0 { | ||
return Err(ColorError::InvalidValue); | ||
} | ||
(alpha * 255.0) as u8 | ||
}; | ||
|
||
Ok((r, g, b, a)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_parse_rgba() { | ||
// Test valid inputs | ||
assert_eq!( | ||
parse_rgba("rgba(255, 0, 0, 1.0)").unwrap(), | ||
(255, 0, 0, 255) | ||
); | ||
assert_eq!( | ||
parse_rgba("rgba(255, 0, 0, 0.5)").unwrap(), | ||
(255, 0, 0, 127) | ||
); | ||
assert_eq!( | ||
parse_rgba("rgba(255, 0, 0, 100%)").unwrap(), | ||
(255, 0, 0, 255) | ||
); | ||
assert_eq!( | ||
parse_rgba("rgba(255, 0, 0, 50%)").unwrap(), | ||
(255, 0, 0, 127) | ||
); | ||
|
||
// Test invalid inputs | ||
assert!(parse_rgba("rgb(255, 0, 0)").is_err()); | ||
assert!(parse_rgba("rgba(300, 0, 0, 1.0)").is_err()); | ||
assert!(parse_rgba("rgba(255, 0, 0, 1.5)").is_err()); | ||
assert!(parse_rgba("rgba(255, 0, 0, 101%)").is_err()); | ||
assert!(parse_rgba("rgba(255, 0, 0)").is_err()); | ||
assert!(parse_rgba("rgba(255, 0, 0, invalid)").is_err()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters