The Battle for Wesnoth
1.17.17+dev
help
help_menu.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2023
3
by David White <dave@whitevine.net>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#pragma once
17
18
#include <set>
// for set
19
#include <string>
// for string, basic_string
20
#include <vector>
// for vector
21
#include "
widgets/menu.hpp
"
// for menu
22
23
namespace
help
{
struct
section; }
24
namespace
help
{
struct
topic; }
25
26
namespace
help
{
27
28
/**
29
* The menu to the left in the help browser, where topics can be
30
* navigated through and chosen.
31
*/
32
class
help_menu
:
public
gui::menu
33
{
34
public
:
35
help_menu
(
const
section
&toplevel,
int
max_height=-1);
36
int
process
();
37
38
/**
39
* Make the topic the currently selected one, and expand all
40
* sections that need to be expanded to show it.
41
*/
42
void
select_topic
(
const
topic
&
t
);
43
44
/**
45
* If a topic has been chosen, return that topic, otherwise
46
* nullptr. If one topic is returned, it will not be returned again,
47
* if it is not re-chosen.
48
*/
49
const
topic
*
chosen_topic
();
50
51
private
:
52
/** Information about an item that is visible in the menu. */
53
struct
visible_item
{
54
visible_item
(
const
section
*_sec,
const
std::string &
visible_string
,
int
level
);
55
visible_item
(
const
topic
*_t,
const
std::string &
visible_string
,
int
level
);
56
// Invariant, one if these should be nullptr. The constructors
57
// enforce it.
58
const
topic
*
t
;
59
const
section
*
sec
;
60
std::string
visible_string
;
61
int
level
;
62
bool
operator==
(
const
visible_item
&vis_item)
const
;
63
bool
operator==
(
const
section
&
sec
)
const
;
64
bool
operator==
(
const
topic
&
t
)
const
;
65
};
66
67
/** Regenerate what items are visible by checking what sections are expanded. */
68
void
update_visible_items
(
const
section
&top_level,
unsigned
starting_level=0);
69
70
/** Return true if the section is expanded. */
71
bool
expanded
(
const
section
&sec);
72
73
/** Mark a section as expanded. Do not update the visible items or anything. */
74
void
expand
(
const
section
&sec);
75
76
/**
77
* Contract (close) a section. That is, mark it as not expanded,
78
* visible items are not updated.
79
*/
80
void
contract
(
const
section
&sec);
81
82
/**
83
* Return the string to use as the prefix for the icon part of the
84
* menu-string at the specified level.
85
*/
86
std::string
indent_list
(
const
std::string &icon,
const
unsigned
level
);
87
/** Return the string to use as the menu-string for sections at the specified level. */
88
std::string
get_string_to_show
(
const
section
&sec,
const
unsigned
level
);
89
/** Return the string to use as the menu-string for topics at the specified level. */
90
std::string
get_string_to_show
(
const
topic
&
topic
,
const
unsigned
level
);
91
92
/** Draw the currently visible items. */
93
void
display_visible_items
();
94
95
/**
96
* Internal recursive thingie. did_expand will be true if any
97
* section was expanded, otherwise untouched.
98
*/
99
bool
select_topic_internal
(
const
topic
&
t
,
const
section
&sec);
100
101
std::vector<visible_item>
visible_items_
;
102
const
section
&
toplevel_
;
103
std::set<const section*>
expanded_
;
104
topic
const
*
chosen_topic_
;
105
visible_item
selected_item_
;
106
};
107
108
}
// end namespace help
t
double t
Definition:
astarsearch.cpp:65
gui::menu
Definition:
menu.hpp:32
help::help_menu
The menu to the left in the help browser, where topics can be navigated through and chosen.
Definition:
help_menu.hpp:33
help::help_menu::update_visible_items
void update_visible_items(const section &top_level, unsigned starting_level=0)
Regenerate what items are visible by checking what sections are expanded.
Definition:
help_menu.cpp:65
help::help_menu::indent_list
std::string indent_list(const std::string &icon, const unsigned level)
Return the string to use as the prefix for the icon part of the menu-string at the specified level.
Definition:
help_menu.cpp:88
help::help_menu::select_topic
void select_topic(const topic &t)
Make the topic the currently selected one, and expand all sections that need to be expanded to show i...
Definition:
help_menu.cpp:134
help::help_menu::expand
void expand(const section &sec)
Mark a section as expanded.
Definition:
help_menu.cpp:51
help::help_menu::chosen_topic_
topic const * chosen_topic_
Definition:
help_menu.hpp:104
help::help_menu::toplevel_
const section & toplevel_
Definition:
help_menu.hpp:102
help::help_menu::expanded_
std::set< const section * > expanded_
Definition:
help_menu.hpp:103
help::help_menu::select_topic_internal
bool select_topic_internal(const topic &t, const section &sec)
Internal recursive thingie.
Definition:
help_menu.cpp:114
help::help_menu::chosen_topic
const topic * chosen_topic()
If a topic has been chosen, return that topic, otherwise nullptr.
Definition:
help_menu.cpp:196
help::help_menu::visible_items_
std::vector< visible_item > visible_items_
Definition:
help_menu.hpp:101
help::help_menu::get_string_to_show
std::string get_string_to_show(const section &sec, const unsigned level)
Return the string to use as the menu-string for sections at the specified level.
Definition:
help_menu.cpp:98
help::help_menu::help_menu
help_menu(const section &toplevel, int max_height=-1)
Definition:
help_menu.cpp:31
help::help_menu::expanded
bool expanded(const section &sec)
Return true if the section is expanded.
Definition:
help_menu.cpp:46
help::help_menu::contract
void contract(const section &sec)
Contract (close) a section.
Definition:
help_menu.cpp:58
help::help_menu::process
int process()
Definition:
help_menu.cpp:153
help::help_menu::display_visible_items
void display_visible_items()
Draw the currently visible items.
Definition:
help_menu.cpp:203
help::help_menu::selected_item_
visible_item selected_item_
Definition:
help_menu.hpp:105
menu.hpp
game_config::images::level
std::string level
Definition:
game_config.cpp:205
help
Definition:
help.cpp:57
help::help_menu::visible_item
Information about an item that is visible in the menu.
Definition:
help_menu.hpp:53
help::help_menu::visible_item::sec
const section * sec
Definition:
help_menu.hpp:59
help::help_menu::visible_item::visible_string
std::string visible_string
Definition:
help_menu.hpp:60
help::help_menu::visible_item::operator==
bool operator==(const visible_item &vis_item) const
Definition:
help_menu.cpp:232
help::help_menu::visible_item::t
const topic * t
Definition:
help_menu.hpp:58
help::help_menu::visible_item::level
int level
Definition:
help_menu.hpp:61
help::help_menu::visible_item::visible_item
visible_item(const section *_sec, const std::string &visible_string, int level)
Definition:
help_menu.cpp:216
help::section
A section contains topics and sections along with title and ID.
Definition:
help_impl.hpp:146
help::topic
A topic contains a title, an id and some text.
Definition:
help_impl.hpp:113
Generated by
1.9.1