yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
layout_helpers.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_LAYOUT_HELPERS_H
2#define YAZE_APP_GUI_LAYOUT_HELPERS_H
3
4#include <vector>
5
6#include "absl/strings/str_format.h"
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace gui {
12
20 public:
22 float left = 0.0f;
23 float right = 0.0f;
24 float top = 0.0f;
25 float bottom = 0.0f;
26 };
27
29 ImVec2 pos{};
30 bool clamped = false;
31 };
32
33 // Core sizing functions (respect theme compact_factor + multipliers)
34 static float GetStandardWidgetHeight();
35 static float GetStandardSpacing();
36 static float GetToolbarHeight();
37 static float GetPanelPadding();
38 static float GetStandardInputWidth();
39 static float GetHexInputWidth();
40 static float GetComboWidth();
41 static float GetSliderWidth();
42 static float GetCompactInputWidth();
43 static float GetButtonPadding();
44 static float GetTableRowHeight();
45 static float GetCanvasToolbarHeight();
46
47 // Layout utilities
48 static void BeginPaddedPanel(const char* label, float padding = -1.0f);
49 static void EndPaddedPanel();
50
51 static bool BeginTableWithTheming(const char* str_id, int columns,
52 ImGuiTableFlags flags = 0,
53 const ImVec2& outer_size = ImVec2(0, 0),
54 float inner_width = 0.0f);
55 static void EndTableWithTheming();
56 static void EndTable() { ImGui::EndTable(); }
57
58 static void BeginCanvasPanel(const char* label,
59 ImVec2* canvas_size = nullptr);
60 static void EndCanvasPanel();
61
62 // Content child with minimum size (fill available, never smaller than min_size)
63 static bool BeginContentChild(const char* id, const ImVec2& min_size,
64 bool border = false,
65 ImGuiWindowFlags flags = 0);
66 static void EndContentChild() { ImGui::EndChild(); }
67
68 // Input field helpers
69 static bool AutoSizedInputField(const char* label, char* buf, size_t buf_size,
70 ImGuiInputTextFlags flags = 0);
71 static bool AutoSizedInputInt(const char* label, int* v, int step = 1,
72 int step_fast = 100,
73 ImGuiInputTextFlags flags = 0);
74 static bool AutoSizedInputFloat(const char* label, float* v,
75 float step = 0.0f, float step_fast = 0.0f,
76 const char* format = "%.3f",
77 ImGuiInputTextFlags flags = 0);
78
79 // Input preset functions for common patterns
80 static bool InputHexRow(const char* label, uint8_t* data);
81 static bool InputHexRow(const char* label, uint16_t* data);
82 static void BeginPropertyGrid(const char* label);
83 static void EndPropertyGrid();
84 static bool InputToolbarField(const char* label, char* buf, size_t buf_size);
85
86 // Toolbar helpers
87 static void BeginToolbar(const char* label);
88 static void EndToolbar();
89 static void ToolbarSeparator();
90 static bool ToolbarButton(const char* label,
91 const ImVec2& size = ImVec2(0, 0));
92
93 // Common layout patterns
94 static void PropertyRow(const char* label,
95 std::function<void()> widget_callback);
96 static void SectionHeader(const char* label);
97 static void HelpMarker(const char* desc);
98
99 // Platform/layout helpers
100 static SafeAreaInsets GetSafeAreaInsets();
101 static float GetTopInset();
102 static bool IsTouchDevice();
103
104 // Touch-aware sizing (Apple HIG 44pt minimum)
105 static float GetMinTouchTarget();
106 static float GetTouchSafeWidgetHeight();
107
108 // Clamp a window position so at least min_visible pixels remain within rect.
109 static WindowClampResult ClampWindowToRect(const ImVec2& pos,
110 const ImVec2& size,
111 const ImVec2& rect_pos,
112 const ImVec2& rect_size,
113 float min_visible = 32.0f);
114
115 // Get current theme
116 static const Theme& GetTheme() {
118 }
119
120 private:
121 static float GetBaseFontSize() { return ImGui::GetFontSize(); }
122 static float ApplyCompactFactor(float base_value) {
123 return base_value * GetTheme().compact_factor;
124 }
125};
126
127} // namespace gui
128} // namespace yaze
129
130#endif // YAZE_APP_GUI_LAYOUT_HELPERS_H
Theme-aware sizing helpers for consistent UI layout.
static float GetHexInputWidth()
static WindowClampResult ClampWindowToRect(const ImVec2 &pos, const ImVec2 &size, const ImVec2 &rect_pos, const ImVec2 &rect_size, float min_visible=32.0f)
static float GetMinTouchTarget()
static float GetSliderWidth()
static void SectionHeader(const char *label)
static float GetPanelPadding()
static float GetTouchSafeWidgetHeight()
static bool BeginContentChild(const char *id, const ImVec2 &min_size, bool border=false, ImGuiWindowFlags flags=0)
static void BeginToolbar(const char *label)
static float GetCompactInputWidth()
static float GetCanvasToolbarHeight()
static void EndTableWithTheming()
static void EndContentChild()
static float ApplyCompactFactor(float base_value)
static void HelpMarker(const char *desc)
static float GetTableRowHeight()
static const Theme & GetTheme()
static float GetStandardInputWidth()
static void BeginPropertyGrid(const char *label)
static SafeAreaInsets GetSafeAreaInsets()
static bool AutoSizedInputFloat(const char *label, float *v, float step=0.0f, float step_fast=0.0f, const char *format="%.3f", ImGuiInputTextFlags flags=0)
static bool AutoSizedInputInt(const char *label, int *v, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
static bool InputToolbarField(const char *label, char *buf, size_t buf_size)
static void BeginCanvasPanel(const char *label, ImVec2 *canvas_size=nullptr)
static void PropertyRow(const char *label, std::function< void()> widget_callback)
static float GetBaseFontSize()
static float GetButtonPadding()
static float GetToolbarHeight()
static void BeginPaddedPanel(const char *label, float padding=-1.0f)
static bool ToolbarButton(const char *label, const ImVec2 &size=ImVec2(0, 0))
static bool InputHexRow(const char *label, uint8_t *data)
static float GetStandardWidgetHeight()
static float GetStandardSpacing()
static bool BeginTableWithTheming(const char *str_id, int columns, ImGuiTableFlags flags=0, const ImVec2 &outer_size=ImVec2(0, 0), float inner_width=0.0f)
static bool AutoSizedInputField(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0)
const Theme & GetCurrentTheme() const
static ThemeManager & Get()
Comprehensive theme structure for YAZE.