Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Expose #714
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Feb 8, 2023
1 parent 79b2e32 commit b5b10c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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_button> &menu::get_buttons() noexcept { return m_v_buttons; }
const std::vector<menu_button>& menu::get_buttons() const noexcept { return m_v_buttons; }

menu_button &menu::get_button(int index)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<int>(i) + 1) * (width) /
Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class menu
int get_height()const noexcept;

/// Gets the vector of buttons
std::vector<menu_button> &get_buttons() noexcept;
const std::vector<menu_button>& get_buttons() const noexcept;

/// Gets the vector of buttons
std::vector<menu_button>& get_buttons() noexcept { return m_v_buttons; }

/// Get one button at index i
menu_button &get_button(int index);
Expand All @@ -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;
Expand Down

0 comments on commit b5b10c9

Please sign in to comment.