yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_INPUT_H
2#define YAZE_APP_CORE_INPUT_H
3
4#define IMGUI_DEFINE_MATH_OPERATORS
5
6#include <cctype>
7#include <cstddef>
8#include <cstdint>
9#include <functional>
10#include <string>
11#include <variant>
12#include <vector>
13
14#include "absl/strings/string_view.h"
16#include "imgui/imgui.h"
17
18namespace yaze {
19namespace gui {
20
21constexpr ImVec2 kDefaultModalSize = ImVec2(200, 0);
22constexpr ImVec2 kZeroPos = ImVec2(0, 0);
23
24IMGUI_API bool InputHex(const char* label, uint64_t* data);
25IMGUI_API bool InputHex(const char* label, int* data, int num_digits = 4,
26 float input_width = 50.f);
27
28IMGUI_API bool InputHexShort(const char* label, uint32_t* data);
29IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
30 float input_width = 50.f, bool no_step = false);
31IMGUI_API bool InputHexWord(const char* label, int16_t* data,
32 float input_width = 50.f, bool no_step = false);
33IMGUI_API bool InputHexByte(const char* label, uint8_t* data,
34 float input_width = 50.f, bool no_step = false);
35
36IMGUI_API bool InputHexByte(const char* label, uint8_t* data, uint8_t max_value,
37 float input_width = 50.f, bool no_step = false);
38
59// Semantic identity is independent of the ImGuiID so automation selectors stay
60// stable while pending edits remain bound to their room/entity/component.
62 uint64_t context = 0;
63 uint64_t container = 0;
64 uint64_t element = 0;
65 uint64_t component = 0;
66
67 bool operator==(const InputScalarTargetIdentity& other) const {
68 return context == other.context && container == other.container &&
69 element == other.element && component == other.component;
70 }
71};
72
73IMGUI_API bool InputScalarDeferred(
74 const char* label, ImGuiDataType data_type, void* data,
75 const char* format = nullptr, ImGuiInputTextFlags flags = 0,
76 InputScalarTargetIdentity target_identity = {});
77
78// Result type for InputHex functions that need to distinguish between
79// immediate changes (button/wheel) and text-edit changes (deferred)
81 bool changed; // Value was modified (any source)
82 bool immediate; // Change was from button/wheel (apply now)
83 bool text_committed; // Change was from text edit and committed (deactivated)
84
85 // Convenience: true if change should be applied immediately
86 // Use this instead of: InputHex(...) && IsItemDeactivatedAfterEdit()
87 bool ShouldApply() const { return immediate || text_committed; }
88
89 // Implicit bool conversion for backwards compatibility
90 operator bool() const { return changed; }
91};
92
93// New API that properly reports change source
94IMGUI_API InputHexResult InputHexByteEx(const char* label, uint8_t* data,
95 float input_width = 50.f,
96 bool no_step = false);
97IMGUI_API InputHexResult InputHexByteEx(const char* label, uint8_t* data,
98 uint8_t max_value,
99 float input_width = 50.f,
100 bool no_step = false);
101IMGUI_API InputHexResult InputHexWordEx(const char* label, uint16_t* data,
102 float input_width = 50.f,
103 bool no_step = false);
104
105// Custom hex input functions that properly respect width
106IMGUI_API bool InputHexByteCustom(const char* label, uint8_t* data,
107 float input_width = 50.f);
108IMGUI_API bool InputHexWordCustom(const char* label, uint16_t* data,
109 float input_width = 70.f);
110
111IMGUI_API void Paragraph(const std::string& text);
112
113IMGUI_API bool ClickableText(const std::string& text);
114
115IMGUI_API bool ListBox(const char* label, int* current_item,
116 const std::vector<std::string>& items,
117 int height_in_items = -1);
118
119bool InputTileInfo(const char* label, gfx::TileInfo* tile_info);
120
121using ItemLabelFlags = enum ItemLabelFlag {
122 Left = 1u << 0u,
123 Right = 1u << 1u,
124 Default = Left,
125};
126
127void ItemLabel(absl::string_view title, ItemLabelFlags flags);
128
129ImGuiID GetID(const std::string& id);
130
131ImGuiKey MapKeyToImGuiKey(char key);
132
133using GuiElement = std::variant<std::function<void()>, std::string>;
134
135struct Table {
136 const char* id;
138 ImGuiTableFlags flags;
139 ImVec2 size;
140 std::vector<std::string> column_labels;
141 std::vector<GuiElement> column_contents;
142};
143
144void AddTableColumn(Table& table, const std::string& label, GuiElement element);
145
146IMGUI_API bool OpenUrl(const std::string& url);
147
148void MemoryEditorPopup(const std::string& label, std::span<uint8_t> memory);
149
150// Slider with mouse wheel support
151IMGUI_API bool SliderFloatWheel(const char* label, float* v, float v_min,
152 float v_max, const char* format = "%.3f",
153 float wheel_step = 0.05f,
154 ImGuiSliderFlags flags = 0);
155IMGUI_API bool SliderIntWheel(const char* label, int* v, int v_min, int v_max,
156 const char* format = "%d", int wheel_step = 1,
157 ImGuiSliderFlags flags = 0);
158
159} // namespace gui
160} // namespace yaze
161
162#endif
SNES 16-bit tile metadata container.
Definition snes_tile.h:52
bool InputHexByteCustom(const char *label, uint8_t *data, float input_width)
Definition input.cc:829
bool ClickableText(const std::string &text)
Definition input.cc:567
bool SliderIntWheel(const char *label, int *v, int v_min, int v_max, const char *format, int wheel_step, ImGuiSliderFlags flags)
Definition input.cc:892
ImGuiID GetID(const std::string &id)
Definition input.cc:693
void Paragraph(const std::string &text)
Definition input.cc:562
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:462
bool ListBox(const char *label, int *current_item, const std::vector< std::string > &items, int height_in_items)
Definition input.cc:666
bool SliderFloatWheel(const char *label, float *v, float v_min, float v_max, const char *format, float wheel_step, ImGuiSliderFlags flags)
Definition input.cc:875
bool InputHexShort(const char *label, uint32_t *data)
Definition input.cc:456
void AddTableColumn(Table &table, const std::string &label, GuiElement element)
Definition input.cc:760
enum ItemLabelFlag { Left=1u<< 0u, Right=1u<< 1u, Default=Left, } ItemLabelFlags
Definition input.h:121
void MemoryEditorPopup(const std::string &label, std::span< uint8_t > memory)
Definition input.cc:815
bool OpenUrl(const std::string &url)
Definition input.cc:787
bool InputHexWordCustom(const char *label, uint16_t *data, float input_width)
Definition input.cc:852
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:438
bool InputTileInfo(const char *label, gfx::TileInfo *tile_info)
Definition input.cc:678
bool InputScalarDeferred(const char *label, ImGuiDataType data_type, void *data, const char *format, ImGuiInputTextFlags flags, InputScalarTargetIdentity target_identity)
Definition input.cc:360
std::variant< std::function< void()>, std::string > GuiElement
Definition input.h:133
constexpr ImVec2 kZeroPos
Definition input.h:22
constexpr ImVec2 kDefaultModalSize
Definition input.h:21
InputHexResult InputHexByteEx(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:506
ImGuiKey MapKeyToImGuiKey(char key)
Definition input.cc:697
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:483
void ItemLabel(absl::string_view title, ItemLabelFlags flags)
Definition input.cc:621
InputHexResult InputHexWordEx(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:544
bool ShouldApply() const
Definition input.h:87
Draw a scalar editor that commits the model value atomically.
Definition input.h:61
bool operator==(const InputScalarTargetIdentity &other) const
Definition input.h:67
std::vector< std::string > column_labels
Definition input.h:140
std::vector< GuiElement > column_contents
Definition input.h:141
ImVec2 size
Definition input.h:139
const char * id
Definition input.h:136
ImGuiTableFlags flags
Definition input.h:138