Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
PresetDropdownHelper.h
Go to the documentation of this file.
1/**
2 * @file PresetDropdownHelper.h
3 * @brief Reusable ImGui dropdown component for ConditionPreset selection (Phase 24).
4 * @author Olympe Engine
5 * @date 2026-03-20
6 *
7 * @details
8 * PresetDropdownHelper provides a reusable dropdown widget that displays all
9 * available ConditionPresets from the global registry, with optional filtering
10 * and search capabilities.
11 *
12 * Usage:
13 * @code
14 * PresetDropdownHelper dropdown(registry);
15 * dropdown.SetLabel("Select Condition");
16 * if (dropdown.Render(selectedPresetID)) {
17 * // User selected a preset; selectedPresetID was updated
18 * OnPresetSelected(selectedPresetID);
19 * }
20 * @endcode
21 *
22 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
23 */
24
25#pragma once
26
27#include <string>
28#include <vector>
29#include "../../Editor/ConditionPreset/ConditionPreset.h"
30#include "../../Editor/ConditionPreset/ConditionPresetRegistry.h"
31
32namespace Olympe {
33
34/**
35 * @class PresetDropdownHelper
36 * @brief ImGui dropdown widget for selecting a ConditionPreset from the registry.
37 */
39public:
40
41 /**
42 * @brief Constructs the dropdown helper bound to the preset registry.
43 * @param registry Global ConditionPresetRegistry (must outlive this helper).
44 */
46
48
49 // -----------------------------------------------------------------------
50 // Configuration
51 // -----------------------------------------------------------------------
52
53 /**
54 * @brief Sets the label displayed next to the dropdown.
55 * @param label Display label (e.g. "Select Condition").
56 */
57 void SetLabel(const std::string& label) { m_label = label; }
58
59 /**
60 * @brief Sets optional filter — only presets matching this substring
61 * are shown in the dropdown.
62 * @param filter Filter string (empty = no filter).
63 */
64 void SetFilter(const std::string& filter) { m_filter = filter; }
65
66 /**
67 * @brief Clears any active filter.
68 */
69 void ClearFilter() { m_filter.clear(); }
70
71 // -----------------------------------------------------------------------
72 // Rendering & Interaction (ImGui — headless-safe)
73 // -----------------------------------------------------------------------
74
75 /**
76 * @brief Renders the dropdown widget and handles selection.
77 *
78 * Must be called once per frame inside the ImGui render loop.
79 *
80 * @param[in,out] selectedPresetID Current selection; updated on user change.
81 * Pass empty string for "no selection".
82 * @return true if the user made a new selection in this frame.
83 *
84 * @details
85 * The dropdown displays presets filtered by m_filter and the registry's
86 * internal search state. Clicking a preset updates selectedPresetID and
87 * returns true.
88 */
89 bool Render(std::string& selectedPresetID);
90
91 // -----------------------------------------------------------------------
92 // Query
93 // -----------------------------------------------------------------------
94
95 /**
96 * @brief Returns the number of presets visible after filtering.
97 */
98 size_t GetVisiblePresetCount() const;
99
100 /**
101 * @brief Returns the display name of a preset, or empty if not found.
102 */
103 std::string GetPresetDisplayName(const std::string& presetID) const;
104
105private:
106
108 std::string m_label; // Dropdown label
109 std::string m_filter; // Search/filter substring
110 bool m_isOpen = false; // Dropdown open state
111 int m_hoveredIndex = -1; // Hovered item (-1 = none)
112};
113
114} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Manages the global pool of ConditionPreset objects.
ImGui dropdown widget for selecting a ConditionPreset from the registry.
size_t GetVisiblePresetCount() const
Returns the number of presets visible after filtering.
void ClearFilter()
Clears any active filter.
std::string GetPresetDisplayName(const std::string &presetID) const
Returns the display name of a preset, or empty if not found.
void SetFilter(const std::string &filter)
Sets optional filter — only presets matching this substring are shown in the dropdown.
ConditionPresetRegistry & m_registry
bool Render(std::string &selectedPresetID)
Renders the dropdown widget and handles selection.
void SetLabel(const std::string &label)
Sets the label displayed next to the dropdown.
< Provides AssetID and INVALID_ASSET_ID