From d15ace46766d8ade8a4451c9d3c2f767aa98ff00 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 28 Nov 2016 10:55:45 -0800 Subject: [PATCH] Hide ui::Size implementation. --- firmware/application/ui_debug.cpp | 2 +- firmware/application/ui_menu.cpp | 4 ++-- firmware/application/ui_spectrum.cpp | 2 +- firmware/common/lcd_ili9341.cpp | 12 +++++----- firmware/common/ui.hpp | 34 ++++++++++++++++++---------- firmware/common/ui_painter.cpp | 8 +++---- firmware/common/ui_text.cpp | 6 +++-- firmware/common/ui_text.hpp | 4 ++-- firmware/common/ui_widget.cpp | 4 ++-- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index 6e1bdcca..11aff219 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -164,7 +164,7 @@ void RegistersWidget::update() { } void RegistersWidget::paint(Painter& painter) { - const Coord left = (size().w - config.row_width()) / 2; + const Coord left = (size().width() - config.row_width()) / 2; draw_legend(left, painter); draw_values(left, painter); diff --git a/firmware/application/ui_menu.cpp b/firmware/application/ui_menu.cpp index 1406875b..2d6bf7ff 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.h - font_height) / 2 }, + { r.pos.x() + 8, r.pos.y() + (r.size.height() - font_height) / 2 }, paint_style, item.text ); @@ -87,7 +87,7 @@ void MenuView::set_parent_rect(const Rect new_parent_rect) { for(auto child : children_) { child->set_parent_rect({ { 0, static_cast(i * item_height) }, - { size().w, item_height } + { size().width(), item_height } }); i++; } diff --git a/firmware/application/ui_spectrum.cpp b/firmware/application/ui_spectrum.cpp index 448e0766..07739ee0 100644 --- a/firmware/application/ui_spectrum.cpp +++ b/firmware/application/ui_spectrum.cpp @@ -112,7 +112,7 @@ void FrequencyScale::draw_frequency_ticks(Painter& painter, const Rect r) { (magnitude_n >= 6) ? "M" : (magnitude_n >= 3) ? "k" : ""; const std::string label = to_string_dec_uint(tick_offset) + zero_pad + unit; - const auto label_width = style().font.size_of(label).w; + const auto label_width = style().font.size_of(label).width(); const Coord offset_low = r.left() + x_center - pixel_offset; const Rect tick_low { offset_low, r.top(), 1, r.height() }; diff --git a/firmware/common/lcd_ili9341.cpp b/firmware/common/lcd_ili9341.cpp index 68a04ef9..77868949 100644 --- a/firmware/common/lcd_ili9341.cpp +++ b/firmware/common/lcd_ili9341.cpp @@ -196,8 +196,8 @@ void lcd_start_ram_write( const ui::Point p, const ui::Size s ) { - lcd_caset(p.x(), p.x() + s.w - 1); - lcd_paset(p.y(), p.y() + s.h - 1); + lcd_caset(p.x(), p.x() + s.width() - 1); + lcd_paset(p.y(), p.y() + s.height() - 1); lcd_ramwr_start(); } @@ -205,8 +205,8 @@ void lcd_start_ram_read( const ui::Point p, const ui::Size s ) { - lcd_caset(p.x(), p.x() + s.w - 1); - lcd_paset(p.y(), p.y() + s.h - 1); + lcd_caset(p.x(), p.x() + s.width() - 1); + lcd_paset(p.y(), p.y() + s.height() - 1); lcd_ramrd_start(); } @@ -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.w * r_clipped.size.h; + size_t count = r_clipped.size.width() * r_clipped.size.height(); io.lcd_write_pixels(c, count); } } @@ -341,7 +341,7 @@ void ILI9341::draw_bitmap( ) { lcd_start_ram_write(p, size); - const size_t count = size.w * size.h; + const size_t count = size.width() * size.height(); for(size_t i=0; i> 3] & (1U << (i & 0x7)); io.lcd_write_pixel(pixel ? foreground : background); diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index fb331f12..8861eb7c 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -135,25 +135,35 @@ public: }; struct Size { - Dim w; - Dim h; +private: + Dim _w; + Dim _h; +public: constexpr Size( - ) : w { 0 }, - h { 0 } + ) : _w { 0 }, + _h { 0 } { } constexpr Size( int w, int h - ) : w { static_cast(w) }, - h { static_cast(h) } + ) : _w { static_cast(w) }, + _h { static_cast(h) } { } + int width() const { + return _w; + } + + int height() const { + return _h; + } + bool is_empty() const { - return (w < 1) || (h < 1); + return (_w < 1) || (_h < 1); } }; @@ -188,7 +198,7 @@ struct Rect { } int bottom() const { - return pos.y() + size.h; + return pos.y() + size.height(); } int left() const { @@ -196,19 +206,19 @@ struct Rect { } int right() const { - return pos.x() + size.w; + return pos.x() + size.width(); } int width() const { - return size.w; + return size.width(); } int height() const { - return size.h; + return size.height(); } Point center() const { - return { pos.x() + size.w / 2, pos.y() + size.h / 2 }; + return { pos.x() + size.width() / 2, pos.y() + size.height() / 2 }; } bool is_empty() const { diff --git a/firmware/common/ui_painter.cpp b/firmware/common/ui_painter.cpp index 6ad11a0b..47f5b02b 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.w, c); - draw_vline({ r.pos.x(), r.pos.y() + 1 }, r.size.h - 2, c); - draw_vline({ r.pos.x() + r.size.w - 1, r.pos.y() + 1 }, r.size.h - 2, c); - draw_hline({ r.pos.x(), r.pos.y() + r.size.h - 1 }, r.size.w, 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); } void Painter::fill_rectangle(const Rect r, const Color c) { diff --git a/firmware/common/ui_text.cpp b/firmware/common/ui_text.cpp index 0f55c5f6..e926ba0d 100644 --- a/firmware/common/ui_text.cpp +++ b/firmware/common/ui_text.cpp @@ -44,8 +44,10 @@ Size Font::size_of(const std::string s) const { for(const auto c : s) { const auto glyph_data = glyph(c); - size.w += glyph_data.w(); - size.h = std::max(size.h, glyph_data.h()); + size = { + size.width() + glyph_data.w(), + std::max(size.height(), glyph_data.h()) + }; } return size; diff --git a/firmware/common/ui_text.hpp b/firmware/common/ui_text.hpp index ae3c94b7..d60c746f 100644 --- a/firmware/common/ui_text.hpp +++ b/firmware/common/ui_text.hpp @@ -42,11 +42,11 @@ public: { } - Dim w() const { + int w() const { return w_; } - Dim h() const { + int h() const { return h_; } diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index a84b731a..897c9b85 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -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.w - 2, r.size.h - 2 }, + { r.pos.x() + 1, r.pos.y() + 1, r.size.width() - 2, r.size.height() - 2 }, paint_style.background ); const auto label_r = paint_style.font.size_of(text_); painter.draw_string( - { r.pos.x() + (r.size.w - label_r.w) / 2, r.pos.y() + (r.size.h - label_r.h) / 2 }, + { r.pos.x() + (r.size.width() - label_r.width()) / 2, r.pos.y() + (r.size.height() - label_r.height()) / 2 }, paint_style, text_ );