From b5b10c9cd9426e7a6ffdb3360ad1bcc481778d86 Mon Sep 17 00:00:00 2001 From: richelbilderbeek Date: Wed, 8 Feb 2023 18:42:03 +0100 Subject: [PATCH] Expose #714 --- src/menu.cpp | 26 ++++++++++++++++++++++---- src/menu.h | 7 +++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index 9def40d..a4f9474 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -18,7 +18,7 @@ menu::menu( int w_width, menu_button(label_button4, color_button4) } { - put_buttons_tidy(); + align_buttons(); } /// Gets the width of the screen int menu::get_w_width() const noexcept { return m_window_width; } @@ -27,7 +27,7 @@ int menu::get_w_width() const noexcept { return m_window_width; } int menu::get_height() const noexcept { return m_window_height; } /// Gets the vector of buttons -std::vector &menu::get_buttons() noexcept { return m_v_buttons; } +const std::vector& menu::get_buttons() const noexcept { return m_v_buttons; } menu_button &menu::get_button(int index) { @@ -48,7 +48,7 @@ menu_button &menu::get_button(const std::string& label) throw std::logic_error("No button in menu has this label."); } -void menu::put_buttons_tidy() noexcept +void menu::align_buttons() noexcept { for (unsigned int i = 0; i != get_buttons().size(); ++i) { @@ -119,7 +119,7 @@ void test_menu() int width = 1000; int height = 1000; menu v(width, height); - v.put_buttons_tidy(); + v.align_buttons(); for (unsigned int i = 0; i < v.get_buttons().size(); ++i) assert(v.get_buttons()[i].get_y() - (static_cast(i) + 1) * (width) / @@ -168,4 +168,22 @@ void test_menu() // press_esc(ov); // assert(is_showing_options(ov)); } + //#define FIX_ISSUE_714 + #ifdef FIX_ISSUE_714 + // Buttons are at the right half of the screen, + // the artwork at the left has the same height as the window + // and is square. + { + const menu m; + const int height{m.get_height()}; + const auto& buttons{m.get_buttons()}; + const int min_x{height}; // the art is square + + for (const auto& button: buttons) + { + // The x of a button is its origin + assert(button.get_x() >= min_x); + } + } + #endif // FIX_ISSUE_714 } diff --git a/src/menu.h b/src/menu.h index 6a7918a..4678654 100644 --- a/src/menu.h +++ b/src/menu.h @@ -25,7 +25,10 @@ class menu int get_height()const noexcept; /// Gets the vector of buttons - std::vector &get_buttons() noexcept; + const std::vector& get_buttons() const noexcept; + + /// Gets the vector of buttons + std::vector& get_buttons() noexcept { return m_v_buttons; } /// Get one button at index i menu_button &get_button(int index); @@ -36,7 +39,7 @@ class menu /// Sets the position of the buttons /// aligned in the center and equally /// distant vertically - void put_buttons_tidy() noexcept; + void align_buttons() noexcept; private: int m_window_width;