Skip to content

Commit 9ac6801

Browse files
committed
Rename inherent clear, optimize DrawTarget::clear
1 parent 80599a5 commit 9ac6801

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- **(breaking)** [#184](https://github.com/jamwaffles/ssd1306/pull/184) Increased MSRV to 1.61.0
2020
- **(breaking)** [#179](https://github.com/jamwaffles/ssd1306/pull/179) Changed `Ssd1306::reset` signature.
2121
- [#181](https://github.com/jamwaffles/ssd1306/pull/181) Update embedded-graphics-core dependency to 0.4
22-
- **(breaking)** [#182](https://github.com/jamwaffles/ssd1306/pull/182) The inherent `BufferedGraphicsMode::clear` is no longer available when the `graphics` feature is enabled.
22+
- **(breaking)** [#18?](https://github.com/jamwaffles/ssd1306/pull/18?) The inherent `BufferedGraphicsMode::clear` has been renamed to `clear_buffer`.
2323

2424
## [0.7.1] - 2022-08-15
2525

src/mode/buffered_graphics.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ where
6868
DI: WriteOnlyDataCommand,
6969
SIZE: DisplaySize,
7070
{
71-
/// Clear the display buffer. You need to call `disp.flush()` for any effect on the screen
72-
#[cfg(not(feature = "graphics"))]
73-
pub fn clear(&mut self) {
74-
for b in self.mode.buffer.as_mut() {
75-
*b = 0;
76-
}
71+
fn clear_impl(&mut self, value: bool) {
72+
self.mode.buffer.as_mut().fill(value as u8);
7773

7874
let (width, height) = self.dimensions();
7975
self.mode.min_x = 0;
@@ -82,6 +78,11 @@ where
8278
self.mode.max_y = height - 1;
8379
}
8480

81+
/// Clear the underlying framebuffer. You need to call `disp.flush()` for any effect on the screen.
82+
pub fn clear_buffer(&mut self) {
83+
self.clear_impl(false);
84+
}
85+
8586
/// Write out data to a display.
8687
///
8788
/// This only updates the parts of the display that have changed since the last flush.
@@ -226,6 +227,11 @@ where
226227

227228
Ok(())
228229
}
230+
231+
fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error> {
232+
self.clear_impl(color.is_on());
233+
Ok(())
234+
}
229235
}
230236

231237
#[cfg(feature = "graphics")]

0 commit comments

Comments
 (0)