1#define IMGUI_DEFINE_MATH_OPERATORS
5#include "absl/strings/str_format.h"
11#include "imgui/imgui.h"
12#include "imgui/imgui_internal.h"
31 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 2));
32 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3, 3));
33 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(6, 4));
45 ImGui::PopStyleVar(3);
54 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.15f, 0.15f, 0.17f, 0.5f));
57 const float button_size = 28.0f;
58 const float padding = 4.0f;
59 const int num_buttons = 2;
60 const float item_spacing = ImGui::GetStyle().ItemSpacing.x;
62 float total_width = (num_buttons * button_size) +
63 ((num_buttons - 1) * item_spacing) + (padding * 2);
65 ImGui::BeginChild(
"##ModeGroup", ImVec2(total_width, button_size + padding),
66 ImGuiChildFlags_AlwaysUseWindowPadding,
67 ImGuiWindowFlags_NoScrollbar);
80 bool clicked = ImGui::Button(icon, ImVec2(size, size));
83 ImGui::PopStyleColor();
86 if (tooltip && ImGui::IsItemHovered()) {
87 ImGui::SetTooltip(
"%s", tooltip);
98 ImGui::PopStyleColor();
105 ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
111 version == 0xFF ?
"Vanilla" : absl::StrFormat(
"v%d", version).c_str(),
114 if (on_upgrade && (version == 0xFF || version < 3)) {
115 ImGui::SameLine(0, 2);
119 if (ImGui::IsItemHovered()) {
120 ImGui::SetTooltip(
"Upgrade to ZSCustomOverworld v3");
128 std::function<
void()> on_change) {
129 ImGui::Text(
"%s", icon);
131 ImGui::SetNextItemWidth(55);
134 if (changed && on_change) {
143 std::function<
void()> on_change) {
144 ImGui::Text(
"%s", icon);
146 ImGui::SetNextItemWidth(70);
149 if (changed && on_change) {
158 const char*
const items[],
int count) {
159 ImGui::Text(
"%s", icon);
160 ImGui::SameLine(0, 2);
161 ImGui::SetNextItemWidth(100);
163 bool changed = ImGui::Combo(
"##combo", current, items, count);
176 bool clicked = ImGui::SmallButton(icon);
179 if (ImGui::GetItemID() != 0 && tooltip) {
180 std::string button_path = absl::StrFormat(
"ToolbarAction:%s", tooltip);
182 ImGui::GetItemID(), tooltip);
185 if (tooltip && ImGui::IsItemHovered()) {
186 ImGui::SetTooltip(
"%s", tooltip);
195 bool is_open = ImGui::CollapsingHeader(label, ImGuiTreeNodeFlags_None);
207 std::function<
void()> on_settings) {
208 if (version >= 3 && version != 0xFF) {
211 if (ImGui::SmallButton(
ICON_MD_TUNE " Settings") && on_settings) {
218 ImGui::OpenPopup(
"UpgradeROMVersion");
226 if (tooltip && ImGui::IsItemHovered()) {
227 ImGui::SetTooltip(
"%s", tooltip);
238 : title_(title), icon_(icon ? icon :
""), default_size_(400, 300) {
243 : title_(title), icon_(icon ? icon :
""), default_size_(400, 300) {
262 if (p_open && !*p_open) {
268 int current_frame = ImGui::GetFrameCount();
283 fprintf(stderr,
"[PanelWindow] DUPLICATE DETECTED: '%s' Begin() called twice in frame %d\n",
298 ImGuiWindowFlags flags = ImGuiWindowFlags_None;
302 flags |= ImGuiWindowFlags_NoTitleBar;
303 flags |= ImGuiWindowFlags_NoCollapse;
308 flags |= ImGuiWindowFlags_NoDocking;
313 flags |= ImGuiWindowFlags_NoSavedSettings;
318 float display_width = ImGui::GetIO().DisplaySize.x;
319 float display_height = ImGui::GetIO().DisplaySize.y;
323 ImGui::SetNextWindowPos(
325 ImGuiCond_FirstUseEver);
328 ImGui::SetNextWindowPos(ImVec2(10, 30), ImGuiCond_FirstUseEver);
331 ImGui::SetNextWindowPos(
333 ImGuiCond_FirstUseEver);
336 ImGui::SetNextWindowPos(ImVec2(10, 30), ImGuiCond_FirstUseEver);
340 ImGui::SetNextWindowPos(
342 display_height * 0.3f),
343 ImGuiCond_FirstUseEver);
347 ImGui::SetNextWindowSize(
default_size_, ImGuiCond_FirstUseEver);
355 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 8.0f);
356 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
357 ImGui::PushStyleColor(ImGuiCol_TitleBg,
GetThemeColor(ImGuiCol_TitleBg));
361 bool* actual_p_open = p_open ? p_open :
p_open_;
364 bool visible = ImGui::Begin(window_title.c_str(),
365 closable_ ? actual_p_open :
nullptr, flags);
376 if (ImGui::GetCurrentWindow() && ImGui::GetCurrentWindow()->ID != 0) {
377 std::string panel_path = absl::StrFormat(
"PanelWindow:%s",
title_.c_str());
379 panel_path,
"window", ImGui::GetCurrentWindow()->ID,
380 absl::StrFormat(
"Editor panel: %s",
title_.c_str()));
390 focused_ = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
393 ImGui::PopStyleColor(2);
394 ImGui::PopStyleVar(2);
408 ImGui::SetNextWindowSize(ImVec2(50, 50));
410 ImGuiWindowFlags flags =
411 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
412 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse;
414 std::string icon_window_name =
window_name_ +
"##IconCollapsed";
416 if (ImGui::Begin(icon_window_name.c_str(),
nullptr, flags)) {
418 if (ImGui::Button(
icon_.c_str(), ImVec2(40, 40))) {
422 if (ImGui::IsItemHovered()) {
423 ImGui::SetTooltip(
"Expand %s",
title_.c_str());
427 if (ImGui::IsWindowHovered() &&
428 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
429 ImVec2 mouse_delta = ImGui::GetIO().MouseDelta;
467 ImGui::BeginChild(
"##MainCanvas", ImVec2(0, 0),
false);
void RegisterPanel(PanelWindow *panel)
std::vector< PanelWindow * > panels_
Draggable, dockable panel for editor sub-windows.
static std::string duplicate_panel_name_
static int last_frame_count_
PanelWindow(const char *title, const char *icon=nullptr)
std::vector< HeaderButton > header_buttons_
void SetPosition(Position pos)
bool Begin(bool *p_open=nullptr)
void AddHeaderButton(const char *icon, const char *tooltip, std::function< void()> callback)
void DrawFloatingIconButton()
static bool duplicate_detected_
static std::vector< std::string > panels_begun_this_frame_
void SetDefaultSize(float width, float height)
#define ICON_MD_ANALYTICS
bool ToggleIconButton(const char *icon_on, const char *icon_off, bool *state, const char *tooltip)
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
void RomVersionBadge(const char *version, bool is_vanilla)
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Color GetThemeColor(const std::string &color_name)
void StatusBadge(const char *text, ButtonType type)