Skip to content

Commit 186d71b

Browse files
eflukxrfuest
andauthored
Add custom color themes (#63)
* Add custom color themes * Tweak changelog entry * Reformat code --------- Co-authored-by: Ralf Fuest <mail@rfuest.de>
1 parent 4a7b741 commit 186d71b

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Added
1010

11+
- [#63] Added support for custom binary color themes (`BinaryColorTheme::Custom`).
1112
- [#62] Added an SDL based audio example (sdl-audio.rs).
1213

1314
## [0.7.0] - 2024-09-10

examples/sdl-audio.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ fn main() -> Result<(), core::convert::Infallible> {
4949
let audio_subsystem = sdl.audio().unwrap();
5050

5151
// Start audio playback by opening the device and setting the custom callback.
52-
let audio_device = audio_subsystem.open_playback(None, &audio_spec, |_| audio_wrapper).unwrap();
52+
let audio_device = audio_subsystem
53+
.open_playback(None, &audio_spec, |_| audio_wrapper)
54+
.unwrap();
5355
audio_device.resume();
5456

5557
let output_settings = OutputSettingsBuilder::new()

src/theme.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub enum BinaryColorTheme {
2424

2525
/// An on/off OLED-like display with a dark blue background and light blue pixels
2626
OledBlue,
27+
28+
/// Custom binary color theme/mapping
29+
Custom {
30+
/// The color used for the "off" state pixels.
31+
color_off: Rgb888,
32+
/// The color used for the "on" state pixels.
33+
color_on: Rgb888,
34+
},
2735
}
2836

2937
fn map_color(color: Rgb888, color_off: Rgb888, color_on: Rgb888) -> Rgb888 {
@@ -38,6 +46,10 @@ impl BinaryColorTheme {
3846
pub(crate) fn convert(self, color: Rgb888) -> Rgb888 {
3947
match self {
4048
BinaryColorTheme::Default => color,
49+
BinaryColorTheme::Custom {
50+
color_off,
51+
color_on,
52+
} => map_color(color, color_off, color_on),
4153
BinaryColorTheme::Inverted => {
4254
Rgb888::new(255 - color.r(), 255 - color.g(), 255 - color.b())
4355
}

0 commit comments

Comments
 (0)