aboutsummaryrefslogtreecommitdiff
path: root/src/game/statusline.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-02 22:36:21 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:58 +0200
commitfb080f6fb911b1831c176a06259e384772541dd5 (patch)
treee18140e700cd974f84a5630f41fcb0b496b7e772 /src/game/statusline.cpp
parent40d02748924aa7c48b04cf948204d8dacdfbbc74 (diff)
refactor: seperate statusline related concerns
Diffstat (limited to 'src/game/statusline.cpp')
-rw-r--r--src/game/statusline.cpp55
1 files changed, 37 insertions, 18 deletions
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 <algorithm>
#include <iostream>
+#include <numeric>
+#include <ranges>
#include <string>
#include <utility>
+#include <vector>
StatusLine::StatusLine(
std::shared_ptr<ICursorController> 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 &section,
+ 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<int32_t>(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 &section,
+ 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 &section) 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 &section,
+ 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<int32_t>(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<uint32_t>(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);