diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index 8a53da71..0823d050 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -200,7 +200,7 @@ void RecentEntriesTable::draw( } line.resize(target_rect.width() / 8, ' '); - painter.draw_string(target_rect.pos, style, line); + painter.draw_string(target_rect.location(), style, line); } AISRecentEntryDetailView::AISRecentEntryDetailView() { diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index 5df0f336..91b3e5e1 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -91,7 +91,7 @@ void RecentEntriesTable::draw( } line.resize(target_rect.width() / 8, ' '); - painter.draw_string(target_rect.pos, style, line); + painter.draw_string(target_rect.location(), style, line); } ERTAppView::ERTAppView(NavigationView&) { diff --git a/firmware/application/recent_entries.cpp b/firmware/application/recent_entries.cpp index 0521238a..bc6ef17a 100644 --- a/firmware/application/recent_entries.cpp +++ b/firmware/application/recent_entries.cpp @@ -45,7 +45,7 @@ void RecentEntriesHeader::paint(Painter& painter) { .foreground = parent_style.foreground, }; - auto p = r.pos; + auto p = r.location(); for(const auto& column : _columns) { const auto width = column.second; auto text = column.first; diff --git a/firmware/application/recent_entries.hpp b/firmware/application/recent_entries.hpp index 335cf0b7..90fd5203 100644 --- a/firmware/application/recent_entries.hpp +++ b/firmware/application/recent_entries.hpp @@ -140,7 +140,7 @@ public: const auto r = screen_rect(); const auto& s = style(); - Rect target_rect { r.pos, { r.width(), s.font.line_height() }}; + Rect target_rect { r.location(), { r.width(), s.font.line_height() }}; const size_t visible_item_count = r.height() / s.font.line_height(); auto selected = find(recent, selected_key); diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 7fe5ab6f..82cdbd3f 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -129,7 +129,7 @@ void RecentEntriesTable::draw( } line.resize(target_rect.width() / 8, ' '); - painter.draw_string(target_rect.pos, style, line); + painter.draw_string(target_rect.location(), style, line); } TPMSAppView::TPMSAppView(NavigationView&) { diff --git a/firmware/application/ui_console.cpp b/firmware/application/ui_console.cpp index af71ee14..fc37b8ce 100644 --- a/firmware/application/ui_console.cpp +++ b/firmware/application/ui_console.cpp @@ -49,7 +49,7 @@ void Console::write(const std::string& message) { crlf(); } const Point pos_glyph { - rect.pos.x() + pos.x(), + rect.left() + pos.x(), display.scroll_area_y(pos.y()) }; display.draw_glyph(pos_glyph, glyph, s.foreground, s.background); diff --git a/firmware/application/ui_menu.cpp b/firmware/application/ui_menu.cpp index 2d6bf7ff..7498a611 100644 --- a/firmware/application/ui_menu.cpp +++ b/firmware/application/ui_menu.cpp @@ -54,7 +54,7 @@ void MenuItemView::paint(Painter& painter) { ); painter.draw_string( - { r.pos.x() + 8, r.pos.y() + (r.size.height() - font_height) / 2 }, + { r.left() + 8, r.top() + (r.height() - font_height) / 2 }, paint_style, item.text ); diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index 77868949..db434d6c 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -213,13 +213,13 @@ void lcd_start_ram_read( void lcd_start_ram_write( const ui::Rect& r ) { - lcd_start_ram_write(r.pos, r.size); + lcd_start_ram_write(r.location(), r.size()); } void lcd_start_ram_read( const ui::Rect& r ) { - lcd_start_ram_read(r.pos, r.size); + lcd_start_ram_read(r.location(), r.size()); } void lcd_vertical_scrolling_definition( @@ -272,7 +272,7 @@ void ILI9341::fill_rectangle(ui::Rect r, const ui::Color c) { const auto r_clipped = r.intersect(screen_rect()); if( !r_clipped.is_empty() ) { lcd_start_ram_write(r_clipped); - size_t count = r_clipped.size.width() * r_clipped.size.height(); + size_t count = r_clipped.width() * r_clipped.height(); io.lcd_write_pixels(c, count); } } @@ -315,7 +315,7 @@ void ILI9341::draw_pixels( const size_t count ) { /* TODO: Assert that rectangle width x height < count */ - lcd_start_ram_write(r.pos, r.size); + lcd_start_ram_write(r); io.lcd_write_pixels(colors, count); } diff --git a/firmware/common/ui.cpp b/firmware/common/ui.cpp index a9a3eae9..06255c2d 100644 --- a/firmware/common/ui.cpp +++ b/firmware/common/ui.cpp @@ -51,21 +51,21 @@ Rect& Rect::operator+=(const Rect& p) { if( !p.is_empty() ) { const auto x1 = std::min(left(), p.left()); const auto y1 = std::min(top(), p.top()); - pos = { x1, y1 }; + _pos = { x1, y1 }; const auto x2 = std::max(right(), p.right()); const auto y2 = std::max(bottom(), p.bottom()); - size = { x2 - x1, y2 - y1 }; + _size = { x2 - x1, y2 - y1 }; } return *this; } Rect& Rect::operator+=(const Point& p) { - pos += p; + _pos += p; return *this; } Rect& Rect::operator-=(const Point& p) { - pos -= p; + _pos -= p; return *this; } diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index 8861eb7c..368f4959 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -168,61 +168,71 @@ public: }; struct Rect { - Point pos; - Size size; +private: + Point _pos; + Size _size; +public: constexpr Rect( - ) : pos { }, - size { } + ) : _pos { }, + _size { } { } constexpr Rect( int x, int y, int w, int h - ) : pos { x, y }, - size { w, h } + ) : _pos { x, y }, + _size { w, h } { } constexpr Rect( Point pos, Size size - ) : pos(pos), - size(size) + ) : _pos(pos), + _size(size) { } + Point location() const { + return _pos; + } + + Size size() const { + return _size; + } + int top() const { - return pos.y(); + return _pos.y(); } int bottom() const { - return pos.y() + size.height(); + return _pos.y() + _size.height(); } int left() const { - return pos.x(); + return _pos.x(); } int right() const { - return pos.x() + size.width(); + return _pos.x() + _size.width(); } int width() const { - return size.width(); + return _size.width(); } int height() const { - return size.height(); + return _size.height(); } Point center() const { - return { pos.x() + size.width() / 2, pos.y() + size.height() / 2 }; + return { _pos.x() + _size.width() / 2, _pos.y() + _size.height() / 2 }; } bool is_empty() const { - return size.is_empty(); + return _size.is_empty(); } bool contains(const Point p) const; @@ -230,7 +240,7 @@ struct Rect { Rect intersect(const Rect& o) const; Rect operator+(const Point& p) const { - return { pos + p, size }; + return { _pos + p, _size }; } Rect& operator+=(const Rect& p); @@ -238,7 +248,7 @@ struct Rect { Rect& operator-=(const Point& p); operator bool() const { - return !size.is_empty(); + return !_size.is_empty(); } }; diff --git a/firmware/common/ui_painter.cpp b/firmware/common/ui_painter.cpp index 47f5b02b..97f223a2 100644 --- a/firmware/common/ui_painter.cpp +++ b/firmware/common/ui_painter.cpp @@ -67,10 +67,10 @@ void Painter::draw_vline(Point p, int height, const Color c) { } void Painter::draw_rectangle(const Rect r, const Color c) { - draw_hline(r.pos, r.size.width(), c); - draw_vline({ r.pos.x(), r.pos.y() + 1 }, r.size.height() - 2, c); - draw_vline({ r.pos.x() + r.size.width() - 1, r.pos.y() + 1 }, r.size.height() - 2, c); - draw_hline({ r.pos.x(), r.pos.y() + r.size.height() - 1 }, r.size.width(), c); + draw_hline(r.location(), r.width(), c); + draw_vline({ r.left(), r.top() + 1 }, r.height() - 2, c); + draw_vline({ r.left() + r.width() - 1, r.top() + 1 }, r.height() - 2, c); + draw_hline({ r.left(), r.top() + r.height() - 1 }, r.width(), c); } void Painter::fill_rectangle(const Rect r, const Color c) { diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 897c9b85..61abaecf 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -49,11 +49,11 @@ bool is_dirty() { const std::vector Widget::no_children { }; Point Widget::screen_pos() { - return screen_rect().pos; + return screen_rect().location(); } Size Widget::size() const { - return parent_rect.size; + return parent_rect.size(); } Rect Widget::screen_rect() const { @@ -317,7 +317,7 @@ void Text::paint(Painter& painter) { painter.fill_rectangle(rect, s.background); painter.draw_string( - rect.pos, + rect.location(), s, text ); @@ -351,13 +351,13 @@ void Button::paint(Painter& painter) { painter.draw_rectangle(r, style().foreground); painter.fill_rectangle( - { r.pos.x() + 1, r.pos.y() + 1, r.size.width() - 2, r.size.height() - 2 }, + { r.left() + 1, r.top() + 1, r.width() - 2, r.height() - 2 }, paint_style.background ); const auto label_r = paint_style.font.size_of(text_); painter.draw_string( - { r.pos.x() + (r.size.width() - label_r.width()) / 2, r.pos.y() + (r.size.height() - label_r.height()) / 2 }, + { r.left() + (r.width() - label_r.width()) / 2, r.top() + (r.height() - label_r.height()) / 2 }, paint_style, text_ );