libwtk-sdl2
0.0.1
include
selection_context.hpp
1
#ifndef LIBWTK_SDL2_SELECTION_CONTEXT_HPP
2
#define LIBWTK_SDL2_SELECTION_CONTEXT_HPP
3
4
#include <SDL2/SDL_rect.h>
5
6
#include "geometry.hpp"
7
#include "key_event.hpp"
8
enum class
navigation_type;
9
struct
widget
;
10
11
// TODO work with shared_ptr (in case a selected widget gets removed)
12
//
13
// This class provides an optional mechanism to interact with the widgets. Think
14
// of it as traversing a 2-dimensional grid in which the widgets are positioned.
15
// The primary purpose is the use of a remote control.
16
//
17
// In principle this represents tabulator based widget focus.
18
struct
selection_context
19
{
20
selection_context
(SDL_Rect widget_area,
widget
* w =
nullptr
);
21
22
// Manually select a widget.
23
void
select_widget(
widget
* w);
24
25
void
unselect_widget();
26
27
// Runs the selected widget's activation event (this may happen when
28
// pressing the return key).
29
void
dispatch_activation();
30
void
dispatch_key_event(
key_event
const
& ke);
31
32
bool
is_selected_widget(
widget
const
* w)
const
;
33
34
// Performs a selection action from the currently selected widgets position.
35
// If no such widget exists, it will perform the action starting from the
36
// given widget.
37
//
38
// This is the entry point of all navigation events.
39
void
navigate_selection(navigation_type nt,
widget
* main_widget);
40
41
void
change_widget_area(SDL_Rect new_box);
42
43
private
:
44
45
void
unselect_helper();
46
void
select_helper();
47
48
point
_selected_position;
49
widget
* _selected_widget;
50
SDL_Rect _widget_area;
51
};
52
53
#endif
54
key_event
Definition:
key_event.hpp:4
point
Definition:
geometry.hpp:6
selection_context
Definition:
selection_context.hpp:18
widget
Definition:
widget.hpp:52
Generated by
1.8.14