diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/components/statusline.cpp | 29 | ||||
-rw-r--r-- | src/engine/components/statusline.hpp | 3 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/engine/components/statusline.cpp b/src/engine/components/statusline.cpp index ae0f3fa..df16e83 100644 --- a/src/engine/components/statusline.cpp +++ b/src/engine/components/statusline.cpp @@ -49,12 +49,17 @@ void StatusLine::set_status( auto pos = Vector2({.x = section_start + start, .y = 0}); - for (const auto &character : status) - { - _component_matrix->set(pos, character); + const auto column_cnt = static_cast<int32_t>(_component_matrix->get_column_cnt()); - pos += Vector2::right(); - } + const auto section_length = _section_lengths[section]; + + const auto status_len = static_cast<int32_t>(status.length()); + + _matrix_write_string( + pos, + status_len <= section_length + ? status + : status.substr(0U, static_cast<uint32_t>(section_length))); set_need_render(true); } @@ -64,6 +69,20 @@ void StatusLine::set_section_length(StatusLineSection section, int32_t length) n _section_lengths[section] = length; } +void StatusLine::_matrix_write_string( + const Vector2 &position, + const std::string_view &str) noexcept +{ + auto working_pos = position; + + for (const auto &character : str) + { + _component_matrix->set(working_pos, character); + + working_pos += Vector2::right(); + } +} + auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept -> int32_t { int32_t section_start = 0; diff --git a/src/engine/components/statusline.hpp b/src/engine/components/statusline.hpp index 3fdb8d3..8c1969b 100644 --- a/src/engine/components/statusline.hpp +++ b/src/engine/components/statusline.hpp @@ -38,6 +38,9 @@ private: std::unordered_map<StatusLineSection, int32_t> _section_lengths; bool _need_render; + void + _matrix_write_string(const Vector2 &position, const std::string_view &str) noexcept; + [[nodiscard]] auto _get_section_start_x(StatusLineSection section) const noexcept -> int32_t; |