SD card status view inherits from new Image class.

This commit is contained in:
Jared Boone 2016-02-03 15:50:14 -08:00
parent 84824a504f
commit dd6d56cff8
4 changed files with 17 additions and 9 deletions

View File

@ -46,7 +46,6 @@ SystemStatusView::SystemStatusView() {
&button_sleep,
&sd_card_status_view,
} });
sd_card_status_view.set_parent_rect({ 28 * 8, 0 * 16, 2 * 8, 1 * 16 });
button_back.on_select = [this](Button&){
if( this->on_back ) {

View File

@ -64,7 +64,9 @@ private:
"ZZ",
};
SDCardStatusView sd_card_status_view;
SDCardStatusView sd_card_status_view {
{ 28 * 8, 0 * 16, 2 * 8, 1 * 16 }
};
};
class NavigationView : public View {

View File

@ -111,6 +111,12 @@ const Color color_sd_card(const sd_card::Status status) {
} /* namespace detail */
SDCardStatusView::SDCardStatusView(
const Rect parent_rect
) : Image { parent_rect, &detail::bitmap_sd_card_unknown, detail::color_sd_card_unknown, Color::black() }
{
}
void SDCardStatusView::on_show() {
sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) {
this->on_status(status);
@ -123,15 +129,14 @@ void SDCardStatusView::on_hide() {
void SDCardStatusView::paint(Painter& painter) {
const auto status = sd_card::status();
painter.draw_bitmap(
screen_pos(),
detail::bitmap_sd_card(status),
detail::color_sd_card(status),
style().background
);
set_bitmap(&detail::bitmap_sd_card(status));
set_foreground(detail::color_sd_card(status));
Image::paint(painter);
}
void SDCardStatusView::on_status(const sd_card::Status) {
// Don't update image properties here, they might change. Wait until paint.
set_dirty();
}

View File

@ -27,8 +27,10 @@
namespace ui {
class SDCardStatusView : public View {
class SDCardStatusView : public Image {
public:
SDCardStatusView(const Rect parent_rect);
void on_show() override;
void on_hide() override;