-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgroup.hpp
180 lines (150 loc) · 4.74 KB
/
group.hpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#pragma once
//=====================================================================//
/*! @file
@brief グループ制御
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2019 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "gui/widget.hpp"
namespace gui {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief グループ・クラス(テンプレート)
@param[in] CNUM グループ最大数
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t CNUM>
struct group : public widget {
typedef group value_type;
private:
widget* child_[CNUM];
uint32_t count_;
void insert_(widget* w) {
if(count_ < CNUM) {
child_[count_] = w;
++count_;
}
}
public:
//-----------------------------------------------------------------//
/*!
@brief コンストラクター
@param[in] loc ロケーション
@param[in] str フレーム・タイトル
*/
//-----------------------------------------------------------------//
group(const vtx::srect& loc = vtx::srect(0), const char* str = "") noexcept :
widget(loc, str), child_{ nullptr }, count_(0)
{
insert_widget(this);
}
group(const group& th) = delete;
group& operator = (const group& th) = delete;
//-----------------------------------------------------------------//
/*!
@brief デストラクタ
*/
//-----------------------------------------------------------------//
virtual ~group() noexcept { remove_widget(this); }
//-----------------------------------------------------------------//
/*!
@brief 型整数を取得
@return 型整数
*/
//-----------------------------------------------------------------//
const char* get_name() const noexcept override { return "Group"; }
//-----------------------------------------------------------------//
/*!
@brief ID を取得
@return ID
*/
//-----------------------------------------------------------------//
ID get_id() const noexcept override { return ID::GROUP; }
//-----------------------------------------------------------------//
/*!
@brief 初期化
*/
//-----------------------------------------------------------------//
void init() noexcept override { }
//-----------------------------------------------------------------//
/*!
@brief タッチ判定を更新
@param[in] pos 判定位置
@param[in] num タッチ数
@param[in] slt スライド・タイプの場合「true」
*/
//-----------------------------------------------------------------//
void update_touch(const vtx::spos& pos, uint16_t num) noexcept override { }
//-----------------------------------------------------------------//
/*!
@brief 選択推移
*/
//-----------------------------------------------------------------//
void exec_select() noexcept override { }
//-----------------------------------------------------------------//
/*!
@brief 許可・不許可
@param[in] ena 不許可の場合「false」
*/
//-----------------------------------------------------------------//
void enable(bool ena = true) override
{
auto st = STATE::DISABLE;
if(ena) {
st = STATE::ENABLE;
} else {
reset_touch_state();
}
set_state(st);
for(uint32_t i = 0; i < count_; ++i) {
child_[i]->set_state(st);
if(!ena) {
child_[i]->reset_touch_state();
}
}
}
//-----------------------------------------------------------------//
/*!
@brief 子供のリスト数取得
@return 子供のリスト数
*/
//-----------------------------------------------------------------//
uint32_t get_child_num() const noexcept { return count_; }
//-----------------------------------------------------------------//
/*!
@brief 子供のリスト取得
@return 子供のリスト
*/
//-----------------------------------------------------------------//
widget** get_child() noexcept { return child_; }
//-----------------------------------------------------------------//
/*!
@brief 親の設定
@param[in] th 子のインスタンス
*/
//-----------------------------------------------------------------//
template <class T>
group& operator + (T& th)
{
th.set_parents(this);
insert_(&th);
return *this;
}
//-----------------------------------------------------------------//
/*!
@brief 親の設定
@param[in] th 子のインスタンス
*/
//-----------------------------------------------------------------//
template <class T>
group& operator += (T& th)
{
th.set_parents(this);
insert_(&th);
return *this;
}
};
}