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 <string>
5#include <vector>
6
7#include "absl/strings/str_format.h"
8#include "absl/strings/string_view.h"
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace gui {
14
22 public:
24 float left = 0.0f;
25 float right = 0.0f;
26 float top = 0.0f;
27 float bottom = 0.0f;
28 };
29
31 ImVec2 pos{};
32 bool clamped = false;
33 };
34
35 // Core sizing functions (respect theme compact_factor + multipliers)
36 static float GetStandardWidgetHeight();
37 static float GetStandardSpacing();
38 static float GetToolbarHeight();
39 static float GetPanelPadding();
40 static float GetStandardInputWidth();
41 static float GetHexInputWidth();
42 static float GetComboWidth();
43 static float GetSliderWidth();
44 static float GetCompactInputWidth();
45 static float GetButtonPadding();
46 static float GetTableRowHeight();
47 static float GetCanvasToolbarHeight();
48
49 // Layout utilities
50 static void BeginPaddedPanel(const char* label, float padding = -1.0f);
51 static void EndPaddedPanel();
52
53 // Call EndTableWithTheming() only when BeginTableWithTheming() returns
54 // true, the same rule as ImGui::BeginTable(). On false the theme pushes
55 // are already undone.
56 static bool BeginTableWithTheming(const char* str_id, int columns,
57 ImGuiTableFlags flags = 0,
58 const ImVec2& outer_size = ImVec2(0, 0),
59 float inner_width = 0.0f);
60 static void EndTableWithTheming();
61
62 static void BeginCanvasPanel(const char* label,
63 ImVec2* canvas_size = nullptr);
64 static void EndCanvasPanel();
65
66 // Content child with minimum size (fill available, never smaller than min_size)
67 static bool BeginContentChild(const char* id, const ImVec2& min_size,
68 bool border = false,
69 ImGuiWindowFlags flags = 0);
70 static void EndContentChild() { ImGui::EndChild(); }
71
72 // Input field helpers
73 static bool AutoSizedInputField(const char* label, char* buf, size_t buf_size,
74 ImGuiInputTextFlags flags = 0);
75 static bool AutoSizedInputInt(const char* label, int* v, int step = 1,
76 int step_fast = 100,
77 ImGuiInputTextFlags flags = 0);
78 static bool AutoSizedInputFloat(const char* label, float* v,
79 float step = 0.0f, float step_fast = 0.0f,
80 const char* format = "%.3f",
81 ImGuiInputTextFlags flags = 0);
82
83 // Input preset functions for common patterns
84 static bool InputHexRow(const char* label, uint8_t* data);
85 static bool InputHexRow(const char* label, uint16_t* data);
86 static bool InputToolbarField(const char* label, char* buf, size_t buf_size);
87
88 // Toolbar helpers
89 static void BeginToolbar(const char* label);
90 static void EndToolbar();
91 static void ToolbarSeparator();
92 static bool ToolbarButton(const char* label,
93 const ImVec2& size = ImVec2(0, 0));
94
95 // Common layout patterns
96 static void PropertyRow(const char* label,
97 std::function<void()> widget_callback);
98 static void SectionHeader(const char* label);
99 static void HelpMarker(const char* desc);
100
101 // Platform/layout helpers
102 static SafeAreaInsets GetSafeAreaInsets();
103 static float GetTopInset();
104 static bool IsTouchDevice();
105
106 // Touch-aware sizing (Apple HIG 44pt minimum)
107 static float GetMinTouchTarget();
108 static float GetTouchSafeWidgetHeight();
109
110 // Clamp a window position so at least min_visible pixels remain within rect.
111 static WindowClampResult ClampWindowToRect(const ImVec2& pos,
112 const ImVec2& size,
113 const ImVec2& rect_pos,
114 const ImVec2& rect_size,
115 float min_visible = 32.0f);
116
117 // Get current theme
118 static const Theme& GetTheme() {
120 }
121
122 private:
123 static float GetBaseFontSize() { return ImGui::GetFontSize(); }
124 static float ApplyCompactFactor(float base_value) {
125 return base_value * GetTheme().compact_factor;
126 }
127};
128
129// Returns "text###stable_id" for ImGui::TableSetupColumn(). ImGui matches
130// saved column width, order and visibility by the label's ID, and only the
131// part after "###" goes into that ID. Use this when `text` is translated
132// (tr()), so a language change keeps the saved column settings. The header
133// still shows only `text`.
134std::string ColumnLabel(absl::string_view text, absl::string_view stable_id);
135
136} // namespace gui
137} // namespace yaze
138
139#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 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()
std::string ColumnLabel(absl::string_view text, absl::string_view stable_id)
Comprehensive theme structure for YAZE.