yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
empty_state.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace gui {
12
13namespace {
14
15void CenterNextItem(float width) {
16 const float avail = ImGui::GetContentRegionAvail().x;
17 if (avail > width) {
18 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (avail - width) * 0.5f);
19 }
20}
21
22} // namespace
23
24bool DrawEmptyState(const EmptyStateOptions& options) {
25 if (!options.title && !options.detail && !options.icon) {
26 return false;
27 }
28
29 const float top_pad = options.compact ? 8.0f : 24.0f;
30 const float mid_pad = options.compact ? 6.0f : 12.0f;
31 ImGui::Dummy(ImVec2(0.0f, top_pad));
32
33 if (options.icon && options.icon[0] != '\0') {
34 const ImVec2 icon_size = ImGui::CalcTextSize(options.icon);
35 CenterNextItem(icon_size.x);
37 }
38
39 if (options.title && options.title[0] != '\0') {
40 ImGui::Spacing();
41 const ImVec2 title_size = ImGui::CalcTextSize(options.title);
42 CenterNextItem(title_size.x);
43 ImGui::PushStyleColor(
45 ImGui::TextWrapped("%s", options.title);
46 ImGui::PopStyleColor();
47 }
48
49 if (options.detail && options.detail[0] != '\0') {
50 ImGui::Dummy(ImVec2(0.0f, mid_pad * 0.5f));
51 const float wrap_width =
52 ImGui::GetContentRegionAvail().x * (options.compact ? 0.95f : 0.85f);
53 const float indent = (ImGui::GetContentRegionAvail().x - wrap_width) * 0.5f;
54 if (indent > 0.0f) {
55 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + indent);
56 }
57 ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + wrap_width);
58 ImGui::TextDisabled("%s", options.detail);
59 ImGui::PopTextWrapPos();
60 }
61
62 bool clicked = false;
63 if (options.action_label && options.action_label[0] != '\0') {
64 ImGui::Dummy(ImVec2(0.0f, mid_pad));
65 const ImVec2 label_size = ImGui::CalcTextSize(options.action_label);
66 const float button_width =
67 std::min(label_size.x + ImGui::GetStyle().FramePadding.x * 4.0f,
68 std::max(1.0f, ImGui::GetContentRegionAvail().x));
69 CenterNextItem(button_width);
70 if (PrimaryButton(options.action_label, ImVec2(button_width, 0.0f))) {
71 clicked = true;
72 if (options.on_action) {
73 options.on_action();
74 }
75 }
76 }
77
78 ImGui::Dummy(ImVec2(0.0f, top_pad * 0.5f));
79 return clicked;
80}
81
85 opts.title = "Open a ROM";
86 opts.detail =
87 "Use File > Open ROM / Project, or drop a .sfc / .smc file onto the "
88 "window.";
89 opts.compact = compact;
90 return opts;
91}
92
96 opts.title = "Select something";
97 opts.detail =
98 "Click an object in the active editor to view and edit its properties. "
99 "Dungeon: rooms, objects, sprites. Overworld: maps, tiles, entities. "
100 "Graphics: sheets, palettes.";
101 opts.compact = compact;
102 return opts;
103}
104
107 opts.icon = ICON_MD_MOUSE;
108 opts.title = "Select in the canvas";
109 opts.detail =
110 "Click a room object, door, sprite, or item to inspect it here. "
111 "Shift-click and drag to multi-select. Use placement panels to add new "
112 "entities.";
113 opts.compact = compact;
114 return opts;
115}
116
120 opts.title = "Open a project";
121 opts.detail =
122 "Create or open a .yaze project via File > New Project / Open to manage "
123 "ROM versioning, snapshots, and project settings.";
124 opts.compact = compact;
125 return opts;
126}
127
128EmptyStateOptions EmptyLoading(const char* what, bool compact) {
131 opts.title = "Loading…";
132 opts.detail = what;
133 opts.compact = compact;
134 return opts;
135}
136
137} // namespace gui
138} // namespace yaze
#define ICON_MD_FOLDER_OPEN
Definition icons.h:813
#define ICON_MD_FOLDER_SPECIAL
Definition icons.h:815
#define ICON_MD_TOUCH_APP
Definition icons.h:2000
#define ICON_MD_MOUSE
Definition icons.h:1251
#define ICON_MD_HOURGLASS_EMPTY
Definition icons.h:967
void ColoredText(const char *text, const ImVec4 &color)
bool PrimaryButton(const char *label, const ImVec2 &size, const char *panel_id, const char *anim_id)
Draw a primary action button (accented color).
EmptyStateOptions EmptyLoading(const char *what, bool compact)
EmptyStateOptions EmptyNoProject(bool compact)
ImVec4 GetDisabledColor()
Definition ui_helpers.cc:74
bool DrawEmptyState(const EmptyStateOptions &options)
Draw a centered empty-state block.
EmptyStateOptions EmptyNoSelection(bool compact)
EmptyStateOptions EmptyNoRom(bool compact)
EmptyStateOptions EmptySelectInCanvas(bool compact)
ImVec4 ResolveSemanticColor(SemanticColor color)
Definition ui_helpers.cc:20
Shared empty / disabled panel presentation.
Definition empty_state.h:15
std::function< void()> on_action
Definition empty_state.h:20
bool compact
Tighter vertical rhythm for drawers / inspectors.
Definition empty_state.h:22