diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-02 22:36:21 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:58 +0200 |
commit | fb080f6fb911b1831c176a06259e384772541dd5 (patch) | |
tree | e18140e700cd974f84a5630f41fcb0b496b7e772 /src/game/status_manager.cpp | |
parent | 40d02748924aa7c48b04cf948204d8dacdfbbc74 (diff) |
refactor: seperate statusline related concerns
Diffstat (limited to 'src/game/status_manager.cpp')
-rw-r--r-- | src/game/status_manager.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp new file mode 100644 index 0000000..727452c --- /dev/null +++ b/src/game/status_manager.cpp @@ -0,0 +1,43 @@ +#include "status_manager.hpp" + +#include <fmt/core.h> + +#include <utility> + +StatusManager::StatusManager(std::shared_ptr<IStatusLine> statusline) noexcept + : _statusline(std::move(statusline)) + +{ + _statusline->set_section_length(StatusLineSection::A, 5U); + _statusline->set_section_length(StatusLineSection::B, 15U); + _statusline->set_section_length(StatusLineSection::C, 15U); + _statusline->set_section_length(StatusLineSection::D, 20U); + _statusline->set_section_length(StatusLineSection::E, 15U); + _statusline->set_section_length(StatusLineSection::F, 15U); +} + +void StatusManager::set_section_title( + const StatusLineSection §ion, + const std::string_view &title +) noexcept +{ + if (_title_lengths.count(section) != 0) + { + fmt::print(stderr, "Error: can't set statusbar section title more than once"); + return; + } + + _statusline->set_status(section, title); + + _title_lengths[section] = title.length(); +} + +void StatusManager::set_section_body( + const StatusLineSection §ion, + const std::string_view &body +) noexcept +{ + auto section_title_length = _title_lengths[section]; + + _statusline->set_status(section, body, section_title_length + 1); +} |