108 using OnSelectionChangedCallback = std::function<
void()>;
116 u32 selected_item_idx;
117 i32 selected_item_alpha;
118 SigmoidIncrementer<i32> selected_item_alpha_incr;
119 i32 prev_selected_item_idx;
120 i32 prev_selected_item_alpha;
121 SigmoidIncrementer<i32> prev_selected_item_alpha_incr;
122 u32 advanced_item_count;
125 Color items_focus_clr;
126 bool cooldown_enabled;
129 std::chrono::time_point<std::chrono::steady_clock> move_start_time;
130 OnSelectionChangedCallback on_selection_changed_cb;
131 std::vector<MenuItem::Ref> items;
132 std::string font_name;
133 std::vector<sdl2::Texture> loaded_name_texs;
134 u8 item_alpha_incr_steps;
135 float icon_item_sizes_factor;
138 u8 light_scrollbar_color_factor;
141 u8 shadow_base_alpha;
142 s64 move_wait_time_ms;
144 void ReloadItemRenders();
148 inline Color MakeItemsFocusColor(
const u8 alpha) {
149 return this->items_focus_clr.WithAlpha(alpha);
152 inline constexpr Color MakeLighterScrollbarColor() {
153 i32 base_r =
this->scrollbar_clr.r -
this->light_scrollbar_color_factor;
157 i32 base_g =
this->scrollbar_clr.g -
this->light_scrollbar_color_factor;
161 i32 base_b =
this->scrollbar_clr.b -
this->light_scrollbar_color_factor;
166 return {
static_cast<u8>(base_r),
static_cast<u8>(base_g),
static_cast<u8>(base_b),
this->scrollbar_clr.a };
169 inline void HandleOnSelectionChanged() {
170 if(
this->on_selection_changed_cb) {
171 (
this->on_selection_changed_cb)();
175 inline void RunSelectedItemCallback(
const u64 keys) {
176 auto item =
this->items.at(
this->selected_item_idx);
177 const auto cb_count = item->GetOnKeyCallbackCount();
178 for(u32 i = 0; i < cb_count; i++) {
179 if(keys & item->GetOnKeyCallbackKey(i)) {
180 if(!
this->cooldown_enabled) {
181 auto cb = item->GetOnKeyCallback(i);
188 this->cooldown_enabled =
false;
191 inline u32 GetItemCount() {
192 auto item_count =
this->items_to_show;
193 if(item_count >
this->items.size()) {
194 item_count =
this->items.size();
196 if((item_count +
this->advanced_item_count) >
this->items.size()) {
197 item_count =
this->items.size() -
this->advanced_item_count;
203 Menu(
const i32 x,
const i32 y,
const i32 width,
const Color items_clr,
const Color items_focus_clr,
const i32 items_height,
const u32 items_to_show);
210 inline void SetX(
const i32 x) {
218 inline void SetY(
const i32 y) {
231 return this->items_h *
this->items_to_show;
250 this->on_selection_changed_cb = on_selection_changed_cb;
254 this->items.push_back(item);
260 this->ReloadItemRenders();
266 return this->items.at(
this->selected_item_idx);
278 void OnInput(
const u64 keys_down,
const u64 keys_up,
const u64 keys_held,
const TouchPoint touch_pos)
override;
Definition sdl2_Types.hpp:18