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;
30 const float padding = std::max(2.0f, style.FramePadding.x);
31 const float needed_width =
32 std::ceil(text_width + (style.FramePadding.x * 2.0f) + padding);
33 return std::max(button_height, needed_width);
38 float button_height) {
44 return std::max(button_size + 2.0f,
49 float min_item_width) {
50 if (item_count <= 1) {
53 const float spacing = ImGui::GetStyle().ItemSpacing.x;
54 const float required_width =
55 (min_item_width *
static_cast<float>(item_count)) +
56 (spacing *
static_cast<float>(item_count - 1));
57 return available_width < required_width;
61 const char* compact_title,
bool compact,
62 const char* subtitle =
nullptr) {
66 ImGui::SameLine(0.0f, 4.0f);
70 ImGui::AlignTextToFramePadding();
71 ImGui::TextUnformatted(
72 (compact && compact_title && *compact_title) ? compact_title : title);
73 if (subtitle && *subtitle) {
74 ImGui::TextDisabled(
"%s", subtitle);
81 const char* tooltip =
nullptr) {
85 ImGui::SameLine(0.0f, 6.0f);
87 ImGui::TextUnformatted(label);
88 if (tooltip && ImGui::IsItemHovered()) {
89 ImGui::SetTooltip(
"%s", tooltip);
95 float button_size,
const char* tooltip,
96 bool active =
false) {
99 icon, ImVec2(button_size, button_size), tooltip, active,
100 ImVec4(0, 0, 0, 0),
"dungeon_workbench",
id);
106 const char* title,
const char* compact_title,
107 const char* subtitle,
bool compact,
109 const std::function<
void()>& draw_actions) {
115 ImGuiStyleVar_FramePadding,
116 ImVec2(std::max(4.0f, ImGui::GetStyle().FramePadding.x),
117 std::max(3.0f, ImGui::GetStyle().FramePadding.y)));
119 ImGuiStyleVar_ItemSpacing,
120 ImVec2(std::max(ImGui::GetStyle().ItemSpacing.x, 4.0f),
121 std::max(3.0f, ImGui::GetStyle().ItemSpacing.y - 1.0f)));
123 constexpr ImGuiTableFlags kPaneHeaderTableFlags =
124 ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoPadInnerX |
125 ImGuiTableFlags_NoPadOuterX;
127 if (!ImGui::BeginTable(table_id, 2, kPaneHeaderTableFlags)) {
131 ImGui::TableSetupColumn(
"Title", ImGuiTableColumnFlags_WidthStretch);
132 ImGui::TableSetupColumn(
"Actions", ImGuiTableColumnFlags_WidthFixed,
133 action_width + 4.0f);
134 ImGui::TableNextRow();
136 ImGui::TableNextColumn();
137 DrawPaneTitle(icon, title, compact_title, compact, subtitle);
139 ImGui::TableNextColumn();
147 std::span<const SegmentSpec> segments,
148 int selected_index,
float height,
149 float min_item_width,
150 const std::function<
void(
int)>& on_select,
151 bool force_stack =
false) {
152 if (segments.empty()) {
156 const float available_width =
157 std::max(ImGui::GetContentRegionAvail().x, 1.0f);
162 const float spacing = ImGui::GetStyle().ItemSpacing.x;
163 const float inline_width =
165 : std::max(min_item_width,
167 (spacing *
static_cast<float>(segments.size() - 1))) /
168 static_cast<float>(segments.size()));
174 for (
size_t i = 0; i < segments.size(); ++i) {
175 const bool selected = selected_index ==
static_cast<int>(i);
177 ImVec2(inline_width, height))) {
179 on_select(
static_cast<int>(i));
182 if (segments[i].tooltip && ImGui::IsItemHovered()) {
183 ImGui::SetTooltip(
"%s", segments[i].tooltip);
185 if (!stack && i + 1 < segments.size()) {
186 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)