aboutsummaryrefslogtreecommitdiff
path: root/src/game/status_manager.cpp
blob: a17468073919631d156de543d4116156c64ee3bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "status_manager.hpp"

#include <fmt/core.h>
#include <stdexcept>

void StatusManager::bind(const std::shared_ptr<IStatusLine> &statusline) noexcept
{
	_statusline = statusline;
}

void StatusManager::set_section_title(
	const StatusLineSection &section,
	const std::string_view &title)
{
	if (_section_title_lengths.contains(section))
	{
		throw std::logic_error(fmt::format(
			"Unable to set statusbar section title to '{}'. Section has already been "
			"assigned a title",
			title));
	}

	_statusline->set_section_status(section, title);

	_section_title_lengths[section] = static_cast<int>(title.length());
}

void StatusManager::set_section_body(
	const StatusLineSection &section,
	const std::string_view &body) noexcept
{
	auto section_title_length = _section_title_lengths[section];

	_statusline->set_section_status(section, body, section_title_length + 1);
}