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
39// Result type for InputHex functions that need to distinguish between
40// immediate changes (button/wheel) and text-edit changes (deferred)
42 bool changed; // Value was modified (any source)
43 bool immediate; // Change was from button/wheel (apply now)
44 bool text_committed; // Change was from text edit and committed (deactivated)
45
46 // Convenience: true if change should be applied immediately
47 // Use this instead of: InputHex(...) && IsItemDeactivatedAfterEdit()
48 bool ShouldApply() const { return immediate || text_committed; }
49
50 // Implicit bool conversion for backwards compatibility
51 operator bool() const { return changed; }
52};
53
54// New API that properly reports change source
55IMGUI_API InputHexResult InputHexByteEx(const char* label, uint8_t* data,
56 float input_width = 50.f,
57 bool no_step = false);
58IMGUI_API InputHexResult InputHexByteEx(const char* label, uint8_t* data,
59 uint8_t max_value,
60 float input_width = 50.f,
61 bool no_step = false);
62IMGUI_API InputHexResult InputHexWordEx(const char* label, uint16_t* data,
63 float input_width = 50.f,
64 bool no_step = false);
65
66// Custom hex input functions that properly respect width
67IMGUI_API bool InputHexByteCustom(const char* label, uint8_t* data,
68 float input_width = 50.f);
69IMGUI_API bool InputHexWordCustom(const char* label, uint16_t* data,
70 float input_width = 70.f);
71
72IMGUI_API void Paragraph(const std::string& text);
73
74IMGUI_API bool ClickableText(const std::string& text);
75
76IMGUI_API bool ListBox(const char* label, int* current_item,
77 const std::vector<std::string>& items,
78 int height_in_items = -1);
79
80bool InputTileInfo(const char* label, gfx::TileInfo* tile_info);
81
82using ItemLabelFlags = enum ItemLabelFlag {
83 Left = 1u << 0u,
84 Right = 1u << 1u,
85 Default = Left,
86};
87
88IMGUI_API void ItemLabel(absl::string_view title, ItemLabelFlags flags);
89
90IMGUI_API ImGuiID GetID(const std::string& id);
91
92ImGuiKey MapKeyToImGuiKey(char key);
93
94using GuiElement = std::variant<std::function<void()>, std::string>;
95
96struct Table {
97 const char* id;
99 ImGuiTableFlags flags;
100 ImVec2 size;
101 std::vector<std::string> column_labels;
102 std::vector<GuiElement> column_contents;
103};
104
105void AddTableColumn(Table& table, const std::string& label, GuiElement element);
106
107IMGUI_API bool OpenUrl(const std::string& url);
108
109void MemoryEditorPopup(const std::string& label, std::span<uint8_t> memory);
110
111// Slider with mouse wheel support
112IMGUI_API bool SliderFloatWheel(const char* label, float* v, float v_min,
113 float v_max, const char* format = "%.3f",
114 float wheel_step = 0.05f,
115 ImGuiSliderFlags flags = 0);
116IMGUI_API bool SliderIntWheel(const char* label, int* v, int v_min, int v_max,
117 const char* format = "%d", int wheel_step = 1,
118 ImGuiSliderFlags flags = 0);
119
120} // namespace gui
121} // namespace yaze
122
123#endif
SNES 16-bit tile metadata container.
Definition snes_tile.h:50
bool InputHexByteCustom(const char *label, uint8_t *data, float input_width)
Definition input.cc:703
bool ClickableText(const std::string &text)
Definition input.cc:448
bool SliderIntWheel(const char *label, int *v, int v_min, int v_max, const char *format, int wheel_step, ImGuiSliderFlags flags)
Definition input.cc:765
void Paragraph(const std::string &text)
Definition input.cc:443
void ItemLabel(absl::string_view title, ItemLabelFlags flags)
Definition input.cc:502
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:344
bool ListBox(const char *label, int *current_item, const std::vector< std::string > &items, int height_in_items)
Definition input.cc:547
bool SliderFloatWheel(const char *label, float *v, float v_min, float v_max, const char *format, float wheel_step, ImGuiSliderFlags flags)
Definition input.cc:749
bool InputHexShort(const char *label, uint32_t *data)
Definition input.cc:338
void AddTableColumn(Table &table, const std::string &label, GuiElement element)
Definition input.cc:640
enum ItemLabelFlag { Left=1u<< 0u, Right=1u<< 1u, Default=Left, } ItemLabelFlags
Definition input.h:82
void MemoryEditorPopup(const std::string &label, std::span< uint8_t > memory)
Definition input.cc:689
bool OpenUrl(const std::string &url)
Definition input.cc:667
bool InputHexWordCustom(const char *label, uint16_t *data, float input_width)
Definition input.cc:726
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:325
bool InputTileInfo(const char *label, gfx::TileInfo *tile_info)
Definition input.cc:559
std::variant< std::function< void()>, std::string > GuiElement
Definition input.h:94
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:397
ImGuiID GetID(const std::string &id)
Definition input.cc:573
ImGuiKey MapKeyToImGuiKey(char key)
Definition input.cc:577
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:370
InputHexResult InputHexWordEx(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:429
bool ShouldApply() const
Definition input.h:48
std::vector< std::string > column_labels
Definition input.h:101
std::vector< GuiElement > column_contents
Definition input.h:102
ImVec2 size
Definition input.h:100
int num_columns
Definition input.h:98
const char * id
Definition input.h:97
ImGuiTableFlags flags
Definition input.h:99