47 const ImGuiViewport* viewport = ImGui::GetMainViewport();
48 ImVec2 max_window_size(1600.0f, 1000.0f);
49 ImVec2 default_window_size(1080.0f, 700.0f);
51 max_window_size = ImVec2(std::max(760.0f, viewport->WorkSize.x * 0.95f),
52 std::max(520.0f, viewport->WorkSize.y * 0.95f));
53 default_window_size = ImVec2(
54 std::clamp(viewport->WorkSize.x * 0.72f, 880.0f, max_window_size.x),
55 std::clamp(viewport->WorkSize.y * 0.76f, 600.0f, max_window_size.y));
56 const ImVec2 center(viewport->WorkPos.x + viewport->WorkSize.x * 0.5f,
57 viewport->WorkPos.y + viewport->WorkSize.y * 0.5f);
58 ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
61 ImGui::SetNextWindowSize(default_window_size, ImGuiCond_Appearing);
62 ImGui::SetNextWindowSizeConstraints(ImVec2(780, 520), max_window_size);
66 p_open, ImGuiWindowFlags_NoDocking)) {
67 std::vector<std::string> categories =
69 std::sort(categories.begin(), categories.end());
77 auto count_windows = [&](
const std::string& category,
78 bool visible_only) ->
int {
80 for (
const auto& window_id : all_windows) {
86 if (category !=
"All" && window->category != category) {
91 if (!visible_only || visible) {
98 ImGui::SetNextItemWidth(
99 std::max(280.0f, ImGui::GetContentRegionAvail().x * 0.45f));
100 ImGui::InputTextWithHint(
129 const float content_height = ImGui::GetContentRegionAvail().y;
130 const float max_sidebar_width =
131 std::max(220.0f, ImGui::GetContentRegionAvail().x * 0.50f);
132 float category_sidebar_width =
136 if (ImGui::BeginChild(
"##WindowBrowserCategories",
137 ImVec2(category_sidebar_width, content_height),
139 const int visible_total = count_windows(
"All",
true);
140 std::string all_label =
142 visible_total,
static_cast<int>(all_windows.size()));
148 for (
const auto& category : categories) {
149 const int category_total = count_windows(category,
false);
150 if (category_total <= 0) {
153 const int visible_in_category = count_windows(category,
true);
155 std::string label = absl::StrFormat(
156 "%s %s (%d/%d)", icon.c_str(), category.c_str(),
157 visible_in_category, category_total);
165 ImGui::SameLine(0.0f, 0.0f);
167 const float splitter_width = 6.0f;
168 const ImVec2 splitter_pos = ImGui::GetCursorScreenPos();
169 ImGui::InvisibleButton(
"##WindowBrowserSplitter",
170 ImVec2(splitter_width, content_height));
171 const bool splitter_hovered = ImGui::IsItemHovered();
172 const bool splitter_active = ImGui::IsItemActive();
173 if (splitter_hovered || splitter_active) {
174 ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
176 if (splitter_hovered &&
177 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
180 category_sidebar_width =
184 if (splitter_active) {
185 category_sidebar_width =
186 std::clamp(category_sidebar_width + ImGui::GetIO().MouseDelta.x,
187 220.0f, max_sidebar_width);
189 ImGui::SetTooltip(
"Width: %.0f px", category_sidebar_width);
194 splitter_active ? 0.95f : (splitter_hovered ? 0.72f : 0.35f);
195 ImGui::GetWindowDrawList()->AddLine(
196 ImVec2(splitter_pos.x + splitter_width * 0.5f, splitter_pos.y),
197 ImVec2(splitter_pos.x + splitter_width * 0.5f,
198 splitter_pos.y + content_height),
199 ImGui::GetColorU32(splitter_color), splitter_active ? 2.0f : 1.0f);
201 ImGui::SameLine(0.0f, 0.0f);
203 if (ImGui::BeginChild(
"##WindowBrowserTable", ImVec2(0, content_height),
205 if (ImGui::BeginTable(
"##WindowTable", 5,
206 ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg |
207 ImGuiTableFlags_Borders |
208 ImGuiTableFlags_Resizable)) {
209 ImGui::TableSetupColumn(
"Visible", ImGuiTableColumnFlags_WidthFixed,
211 ImGui::TableSetupColumn(
"Pin", ImGuiTableColumnFlags_WidthFixed, 36);
212 ImGui::TableSetupColumn(
"Name", ImGuiTableColumnFlags_WidthStretch);
213 ImGui::TableSetupColumn(
"Category", ImGuiTableColumnFlags_WidthFixed,
215 ImGui::TableSetupColumn(
"Shortcut", ImGuiTableColumnFlags_WidthFixed,
217 ImGui::TableHeadersRow();
221 : std::vector<std::string>{};
223 auto category_windows =
225 windows.reserve(category_windows.size());
226 for (
const auto& window : category_windows) {
227 windows.push_back(window.card_id);
231 for (
const auto& window_id : windows) {
242 ImGui::TableNextRow();
244 ImGui::TableNextColumn();
245 if (window->visibility_flag) {
246 bool visible = *window->visibility_flag;
247 if (ImGui::Checkbox(absl::StrFormat(
"##vis_%s", window->card_id)
254 ImGui::TableNextColumn();
256 const ImVec4 pin_color =
258 const float pin_side =
261 absl::StrFormat(
"browser_pin_%s", window->card_id).c_str());
264 ImVec2(pin_side, pin_side),
265 is_pinned ?
"Unpin window" :
"Pin window", is_pinned,
266 pin_color,
"window_browser", window->card_id.c_str())) {
272 ImGui::TableNextColumn();
273 ImGui::Text(
"%s %s", window->icon.c_str(),
274 window->display_name.c_str());
275 if (ImGui::IsItemHovered() &&
276 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
278 const std::string window_name =
280 if (!window_name.empty()) {
281 ImGui::SetWindowFocus(window_name.c_str());
285 ImGui::TableNextColumn();
286 ImGui::TextUnformatted(window->category.c_str());
288 ImGui::TableNextColumn();
289 if (window->shortcut_hint.empty()) {
290 ImGui::TextDisabled(
"-");
292 ImGui::TextDisabled(
"%s", window->shortcut_hint.c_str());