1#ifndef YAZE_APP_EDITOR_DUNGEON_UI_WORKBENCH_DUNGEON_WORKBENCH_CHROME_H
2#define YAZE_APP_EDITOR_DUNGEON_UI_WORKBENCH_DUNGEON_WORKBENCH_CHROME_H
14#include "imgui/imgui.h"
24 if (!icon || !*icon) {
28 const ImGuiStyle& style = ImGui::GetStyle();
29 const float text_width = ImGui::CalcTextSize(icon).x;
31 const float frame_padding = std::max(4.0f, style.FramePadding.x);
32 const float padding = std::max(2.0f, frame_padding);
33 const float needed_width =
34 std::ceil(text_width + (frame_padding * 2.0f) + padding);
35 return std::max(button_height, needed_width);
40 float button_height) {
46 return std::max(button_size + 2.0f,
51 float min_item_width) {
52 if (item_count <= 1) {
55 const float spacing = ImGui::GetStyle().ItemSpacing.x;
56 const float required_width =
57 (min_item_width *
static_cast<float>(item_count)) +
58 (spacing *
static_cast<float>(item_count - 1));
59 return available_width < required_width;
63 const char* compact_title,
bool compact,
64 const char* subtitle =
nullptr) {
68 ImGui::SameLine(0.0f, 4.0f);
72 ImGui::AlignTextToFramePadding();
73 ImGui::TextUnformatted(
74 (compact && compact_title && *compact_title) ? compact_title : title);
75 if (subtitle && *subtitle) {
76 ImGui::TextDisabled(
"%s", subtitle);
83 const char* tooltip =
nullptr) {
87 ImGui::SameLine(0.0f, 6.0f);
89 ImGui::TextUnformatted(label);
90 if (tooltip && ImGui::IsItemHovered()) {
91 ImGui::SetTooltip(
"%s", tooltip);
97 float button_size,
const char* tooltip,
98 bool active =
false) {
102 tooltip, active, ImVec4(0, 0, 0, 0),
"dungeon_workbench",
id);
108 const char* title,
const char* compact_title,
109 const char* subtitle,
bool compact,
111 const std::function<
void()>& draw_actions) {
117 ImGuiStyleVar_FramePadding,
118 ImVec2(std::max(4.0f, ImGui::GetStyle().FramePadding.x),
119 std::max(3.0f, ImGui::GetStyle().FramePadding.y)));
121 ImGuiStyleVar_ItemSpacing,
122 ImVec2(std::max(ImGui::GetStyle().ItemSpacing.x, 4.0f),
123 std::max(3.0f, ImGui::GetStyle().ItemSpacing.y - 1.0f)));
125 constexpr ImGuiTableFlags kPaneHeaderTableFlags =
126 ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoPadInnerX |
127 ImGuiTableFlags_NoPadOuterX;
129 if (!ImGui::BeginTable(table_id, 2, kPaneHeaderTableFlags)) {
133 ImGui::TableSetupColumn(
"Title", ImGuiTableColumnFlags_WidthStretch);
134 ImGui::TableSetupColumn(
"Actions", ImGuiTableColumnFlags_WidthFixed,
135 action_width + 4.0f);
136 ImGui::TableNextRow();
138 ImGui::TableNextColumn();
139 DrawPaneTitle(icon, title, compact_title, compact, subtitle);
141 ImGui::TableNextColumn();
149 std::span<const SegmentSpec> segments,
150 int selected_index,
float height,
151 float min_item_width,
152 const std::function<
void(
int)>& on_select,
153 bool force_stack =
false) {
154 if (segments.empty()) {
158 const float available_width =
159 std::max(ImGui::GetContentRegionAvail().x, 1.0f);
164 const float spacing = ImGui::GetStyle().ItemSpacing.x;
165 const float inline_width =
167 : std::max(min_item_width,
169 (spacing *
static_cast<float>(segments.size() - 1))) /
170 static_cast<float>(segments.size()));
176 for (
size_t i = 0; i < segments.size(); ++i) {
177 const bool selected = selected_index ==
static_cast<int>(i);
179 ImVec2(inline_width, height))) {
181 on_select(
static_cast<int>(i));
184 if (segments[i].tooltip && ImGui::IsItemHovered()) {
185 ImGui::SetTooltip(
"%s", segments[i].tooltip);
187 if (!stack && i + 1 < segments.size()) {
188 ImGui::SameLine(0.0f, spacing);
static float GetTouchSafeWidgetHeight()
RAII guard for ImGui style vars.
bool ShouldStackSegments(float available_width, int item_count, float min_item_width)
float CalcPaneSegmentHeight(float button_size)
void DrawSectionLabel(const char *icon, const char *label, const char *tooltip=nullptr)
void DrawSegmentedControls(const char *id, std::span< const SegmentSpec > segments, int selected_index, float height, float min_item_width, const std::function< void(int)> &on_select, bool force_stack=false)
void DrawPaneHeader(const char *table_id, const char *icon, const char *title, const char *compact_title, const char *subtitle, bool compact, float action_width, const std::function< void()> &draw_actions)
float CalcIconButtonWidth(const char *icon, float button_height)
void DrawPaneTitle(const char *icon, const char *title, const char *compact_title, bool compact, const char *subtitle=nullptr)
float CalcIconToggleButtonWidth(const char *icon_on, const char *icon_off, float button_height)
bool DrawHeaderIconAction(const char *id, const char *icon, float button_size, const char *tooltip, bool active=false)
bool TransparentIconButton(const char *icon, const ImVec2 &size, const char *tooltip, bool is_active, const ImVec4 &active_color, const char *panel_id, const char *anim_id)
Draw a transparent icon button (hover effect only).
void ColoredText(const char *text, const ImVec4 &color)
bool ToggleButton(const char *label, bool active, const ImVec2 &size)