From fb080f6fb911b1831c176a06259e384772541dd5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 2 May 2022 22:36:21 +0200 Subject: refactor: seperate statusline related concerns --- src/game/statusline.cpp | 55 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 18 deletions(-) (limited to 'src/game/statusline.cpp') diff --git a/src/game/statusline.cpp b/src/game/statusline.cpp index d764d60..58a317b 100644 --- a/src/game/statusline.cpp +++ b/src/game/statusline.cpp @@ -3,9 +3,13 @@ #include "engine/escape.hpp" #include "util/color.hpp" +#include #include +#include +#include #include #include +#include StatusLine::StatusLine( std::shared_ptr cursor_controller, @@ -13,11 +17,6 @@ StatusLine::StatusLine( ) noexcept : _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) { - constexpr uint32_t SECTION_A_LENGTH = 20; - constexpr uint32_t SECTION_B_LENGTH = 30; - - _sections_lengths[StatusLineSection::A] = SECTION_A_LENGTH; - _sections_lengths[StatusLineSection::B] = SECTION_B_LENGTH; } void StatusLine::initialize_background() noexcept @@ -33,23 +32,27 @@ void StatusLine::initialize_background() noexcept } void StatusLine::set_status( - StatusLineSection section, - const std::string_view &statusline_str + const StatusLineSection §ion, + const std::string_view &status, + std::size_t start ) noexcept { - _clear_section(section); + _clear_section(section, start); - int32_t section_start = _get_section_start_x(section); + auto section_start = _get_section_start_x(section); - const auto previous_position = _move_to_statusline(section_start); + const auto previous_position = + _move_to_statusline(section_start + static_cast(start)); auto background_color = get_background_esc_seq(STATUSBAR_COLOR); auto section_length = _sections_lengths[section]; - auto status = statusline_str.length() > section_length - ? statusline_str.substr(0, section_length) - : statusline_str; + /* + auto status = status.length() > section_length + ? status_str.substr(0, section_length) + : status_str; + */ fmt::print("{}{}", background_color, status); fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); @@ -57,6 +60,14 @@ void StatusLine::set_status( _move_back(previous_position); } +void StatusLine::set_section_length( + const StatusLineSection §ion, + uint32_t length +) noexcept +{ + _sections_lengths[section] = length; +} + auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2 { const auto previous_position = _cursor_controller->where(); @@ -78,7 +89,8 @@ void StatusLine::_move_back(Vector2 previous_position) noexcept _cursor_controller->show(); } -auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept -> int32_t +auto StatusLine::_get_section_start_x(const StatusLineSection §ion) const noexcept + -> int32_t { int32_t section_start = 0; @@ -96,17 +108,24 @@ auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept return section_start; } -void StatusLine::_clear_section(StatusLineSection section) noexcept +void StatusLine::_clear_section( + const StatusLineSection §ion, + std::size_t start +) noexcept { auto section_start = _get_section_start_x(section); - const auto previous_position = _move_to_statusline(section_start); + auto start_int32 = static_cast(start); + + const auto previous_position = _move_to_statusline(section_start + start_int32); auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - auto section_length = _sections_lengths.at(section); + auto section_length = _sections_lengths[section]; + + auto start_uint32 = static_cast(start); - fmt::print("{}{}", background_color, std::string(section_length, ' ')); + fmt::print("{}{}", background_color, std::string(section_length - start_uint32, ' ')); fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); _move_back(previous_position); -- cgit v1.2.3-18-g5258