50 const ImGuiViewport* viewport = ImGui::GetMainViewport();
51 ImVec2 max_window_size(1600.0f, 1000.0f);
52 ImVec2 default_window_size(1080.0f, 700.0f);
54 max_window_size = ImVec2(std::max(760.0f, viewport->WorkSize.x * 0.95f),
55 std::max(520.0f, viewport->WorkSize.y * 0.95f));
56 default_window_size = ImVec2(
57 std::clamp(viewport->WorkSize.x * 0.72f, 880.0f, max_window_size.x),
58 std::clamp(viewport->WorkSize.y * 0.76f, 600.0f, max_window_size.y));
59 const ImVec2 center(viewport->WorkPos.x + viewport->WorkSize.x * 0.5f,
60 viewport->WorkPos.y + viewport->WorkSize.y * 0.5f);
61 ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
64 ImGui::SetNextWindowSize(default_window_size, ImGuiCond_Appearing);
65 ImGui::SetNextWindowSizeConstraints(ImVec2(780, 520), max_window_size);
69 p_open, ImGuiWindowFlags_NoDocking)) {
70 std::vector<std::string> categories =
72 std::sort(categories.begin(), categories.end());
80 auto count_windows = [&](
const std::string& category,
81 bool visible_only) ->
int {
83 for (
const auto& window_id : all_windows) {
89 if (category !=
"All" && window->category != category) {
94 if (!visible_only || visible) {
100 auto set_filtered_windows_visible = [&](
const std::string& category,
102 for (
const auto& window_id : all_windows) {
108 if (category !=
"All" && window->category != category) {
119 ImGui::SetNextItemWidth(
120 std::max(280.0f, ImGui::GetContentRegionAvail().x * 0.45f));
121 ImGui::InputTextWithHint(
132 set_filtered_windows_visible(
"All",
true);
136 set_filtered_windows_visible(
"All",
false);
150 const float content_height = ImGui::GetContentRegionAvail().y;
151 const float max_sidebar_width =
152 std::max(220.0f, ImGui::GetContentRegionAvail().x * 0.50f);
153 float category_sidebar_width =
157 if (ImGui::BeginChild(
"##WindowBrowserCategories",
158 ImVec2(category_sidebar_width, content_height),
160 const int visible_total = count_windows(
"All",
true);
161 const int filtered_total = count_windows(
"All",
false);
162 std::string all_label =
164 visible_total, filtered_total);
170 for (
const auto& category : categories) {
171 const int category_total = count_windows(category,
false);
172 if (category_total <= 0) {
175 const int visible_in_category = count_windows(category,
true);
176 const std::string icon =
179 absl::StrFormat(
"%s %s (%d/%d)", icon.c_str(), category.c_str(),
180 visible_in_category, category_total);
188 ImGui::SameLine(0.0f, 0.0f);
190 const float splitter_width = 6.0f;
191 const ImVec2 splitter_pos = ImGui::GetCursorScreenPos();
192 ImGui::InvisibleButton(
"##WindowBrowserSplitter",
193 ImVec2(splitter_width, content_height));
194 const bool splitter_hovered = ImGui::IsItemHovered();
195 const bool splitter_active = ImGui::IsItemActive();
196 if (splitter_hovered || splitter_active) {
197 ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
199 if (splitter_hovered &&
200 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
203 category_sidebar_width =
207 if (splitter_active) {
208 category_sidebar_width =
209 std::clamp(category_sidebar_width + ImGui::GetIO().MouseDelta.x,
210 220.0f, max_sidebar_width);
212 ImGui::SetTooltip(tr(
"Width: %.0f px"), category_sidebar_width);
217 splitter_active ? 0.95f : (splitter_hovered ? 0.72f : 0.35f);
218 ImGui::GetWindowDrawList()->AddLine(
219 ImVec2(splitter_pos.x + splitter_width * 0.5f, splitter_pos.y),
220 ImVec2(splitter_pos.x + splitter_width * 0.5f,
221 splitter_pos.y + content_height),
222 ImGui::GetColorU32(splitter_color), splitter_active ? 2.0f : 1.0f);
224 ImGui::SameLine(0.0f, 0.0f);
226 if (ImGui::BeginChild(
"##WindowBrowserTable", ImVec2(0, content_height),
228 if (ImGui::BeginTable(
"##WindowTable", 5,
229 ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg |
230 ImGuiTableFlags_Borders |
231 ImGuiTableFlags_Resizable)) {
232 ImGui::TableSetupColumn(
"Visible", ImGuiTableColumnFlags_WidthFixed,
234 ImGui::TableSetupColumn(
"Pin", ImGuiTableColumnFlags_WidthFixed, 36);
235 ImGui::TableSetupColumn(
"Name", ImGuiTableColumnFlags_WidthStretch);
236 ImGui::TableSetupColumn(
"Category", ImGuiTableColumnFlags_WidthFixed,
238 ImGui::TableSetupColumn(
"Shortcut", ImGuiTableColumnFlags_WidthFixed,
240 ImGui::TableHeadersRow();
243 : std::vector<std::string>{};
247 windows.reserve(category_windows.size());
248 for (
const auto& window : category_windows) {
249 windows.push_back(window.card_id);
253 for (
const auto& window_id : windows) {
264 ImGui::TableNextRow();
266 ImGui::TableNextColumn();
267 if (window->visibility_flag) {
268 bool visible = *window->visibility_flag;
270 absl::StrFormat(
"##vis_%s", window->card_id).c_str(),
276 ImGui::TableNextColumn();
277 const bool is_pinned =
279 const ImVec4 pin_color =
281 const float pin_side =
284 absl::StrFormat(
"browser_pin_%s", window->card_id).c_str());
287 ImVec2(pin_side, pin_side),
288 is_pinned ?
"Unpin window" :
"Pin window", is_pinned,
289 pin_color,
"window_browser", window->card_id.c_str())) {
295 ImGui::TableNextColumn();
296 ImGui::Text(
"%s %s", window->icon.c_str(),
297 window->display_name.c_str());
298 if (ImGui::IsItemHovered() &&
299 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
301 const std::string window_name =
303 if (!window_name.empty()) {
304 ImGui::SetWindowFocus(window_name.c_str());
308 ImGui::TableNextColumn();
309 ImGui::TextUnformatted(window->category.c_str());
311 ImGui::TableNextColumn();
312 if (window->shortcut_hint.empty()) {
313 ImGui::TextDisabled(
"-");
315 ImGui::TextDisabled(
"%s", window->shortcut_hint.c_str());