summaryrefslogtreecommitdiff
path: root/src/listwidgetbackend.cpp
blob: 97ed1a32ed7f89779b34eb9bcdaf12d39ebd5562 (plain) (blame)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "listwidgetbackend.h"

#include "utils.h"

namespace newsboat {

ListWidgetBackend::ListWidgetBackend(const std::string& list_name, Stfl::Form& form)
	: list_name(list_name)
	, form(form)
	, num_lines(0)
{
}

void ListWidgetBackend::stfl_replace_list(std::uint32_t number_of_lines, std::string stfl)
{
	num_lines = number_of_lines;
	form.modify(list_name, "replace", stfl);

	on_list_changed();
}

void ListWidgetBackend::stfl_replace_lines(const ListFormatter& listfmt)
{
	num_lines = listfmt.get_lines_count();
	form.modify(list_name, "replace_inner", listfmt.format_list());

	on_list_changed();
}

std::uint32_t ListWidgetBackend::get_width()
{
	return utils::to_u(form.get(list_name + ":w"));
}

std::uint32_t ListWidgetBackend::get_height()
{
	return utils::to_u(form.get(list_name + ":h"));
}

std::uint32_t ListWidgetBackend::get_num_lines()
{
	return num_lines;
}

void ListWidgetBackend::update_position(std::uint32_t pos, std::uint32_t scroll_offset)
{
	form.set(list_name + "_pos", std::to_string(pos));
	form.set(list_name + "_offset", std::to_string(scroll_offset));
}

} // namespace newsboat