249 const ImGuiStyle& style = ImGui::GetStyle();
250 const float avail_width = ImGui::GetContentRegionAvail().x;
251 const float min_width = kDashboardRecentBaseWidth;
252 const float max_width =
253 kDashboardRecentBaseWidth * kDashboardRecentWidthMaxFactor;
255 std::max(kDashboardRecentBaseHeight, ImGui::GetFrameHeight());
256 const float spacing = style.ItemSpacing.x;
257 const bool stack_items = avail_width < min_width * 1.6f;
258 FlowLayout row_layout{};
260 row_layout.columns = 1;
261 row_layout.item_width = avail_width;
262 row_layout.item_height = height;
263 row_layout.spacing = spacing;
265 row_layout = ComputeFlowLayout(avail_width, min_width, max_width, height,
266 height, height / std::max(min_width, 1.0f),
267 spacing, kDashboardMaxRecentColumns,
271 ImGuiTableFlags table_flags =
272 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
273 const ImVec2 cell_padding(row_layout.spacing * 0.5f,
274 style.ItemSpacing.y * 0.4f);
276 if (ImGui::BeginTable(
"DashboardRecentGrid", row_layout.columns,
280 auto it = std::find_if(
282 [type](
const EditorInfo& info) { return info.type == type; });
288 ImGui::TableNextColumn();
290 const bool enabled =
has_rom_ || !it->requires_rom;
291 const float alpha = enabled ? 1.0f : 0.35f;
292 const ImVec4 base_color = GetEditorAccentColor(it->type, theme);
294 {{ImGuiCol_Button, ScaleColor(base_color, 0.5f, 0.7f * alpha)},
295 {ImGuiCol_ButtonHovered,
296 ScaleColor(base_color, 0.7f, 0.9f * alpha)},
297 {ImGuiCol_ButtonActive, WithAlpha(base_color, 1.0f * alpha)}});
300 stack_items ? avail_width : row_layout.item_width,
301 row_layout.item_height > 0.0f ? row_layout.item_height : height);
303 ImGui::BeginDisabled();
305 if (ImGui::Button(absl::StrCat(it->icon,
" ", it->name).c_str(),
315 ImGui::EndDisabled();
318 if (ImGui::IsItemHovered()) {
320 ImGui::SetTooltip(
"Load a ROM to open %s", it->name.c_str());
322 ImGui::SetTooltip(
"%s", it->description.c_str());
334 const ImGuiStyle& style = ImGui::GetStyle();
335 const float avail_width = ImGui::GetContentRegionAvail().x;
336 const float scale = ImGui::GetFontSize() / 16.0f;
337 const float compact_scale = avail_width < 620.0f ? 0.85f : 1.0f;
338 const float min_width =
339 kDashboardCardBaseWidth * kDashboardCardMinWidthFactor * scale *
341 const float max_width =
342 kDashboardCardBaseWidth * kDashboardCardWidthMaxFactor * scale *
344 const float min_height =
345 std::max(kDashboardCardBaseHeight * kDashboardCardMinHeightFactor * scale *
347 ImGui::GetFrameHeight() * 3.2f);
348 const float max_height =
349 kDashboardCardBaseHeight * kDashboardCardHeightMaxFactor * scale *
351 const float aspect_ratio =
352 kDashboardCardBaseHeight / std::max(kDashboardCardBaseWidth, 1.0f);
353 const float spacing = style.ItemSpacing.x;
355 FlowLayout layout = ComputeFlowLayout(
356 avail_width, min_width, max_width, min_height, max_height, aspect_ratio,
357 spacing, kDashboardMaxColumns,
static_cast<int>(
editors_.size()));
359 ImGuiTableFlags table_flags =
360 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
361 const ImVec2 cell_padding(layout.spacing * 0.5f, style.ItemSpacing.y * 0.5f);
363 if (ImGui::BeginTable(
"DashboardEditorGrid", layout.columns, table_flags)) {
364 for (
size_t i = 0; i <
editors_.size(); ++i) {
365 ImGui::TableNextColumn();
368 ImVec2(layout.item_width, layout.item_height), enabled);
375 const ImVec2& card_size,
bool enabled) {
376 ImGui::PushID(index);
379 const float disabled_alpha = enabled ? 1.0f : 0.35f;
380 const ImVec4 base_color = GetEditorAccentColor(info.
type, theme);
384 text_primary.w *= enabled ? 1.0f : 0.5f;
385 text_secondary.w *= enabled ? 1.0f : 0.5f;
386 ImFont* text_font = ImGui::GetFont();
387 const float text_font_size = ImGui::GetFontSize();
389 const ImGuiStyle& style = ImGui::GetStyle();
390 const float line_height = ImGui::GetTextLineHeight();
391 const float padding_x = std::max(style.FramePadding.x, card_size.x * 0.06f);
392 const float padding_y = std::max(style.FramePadding.y, card_size.y * 0.08f);
394 const float footer_height = info.
shortcut.empty() ? 0.0f : line_height;
395 const float footer_spacing =
396 info.
shortcut.empty() ? 0.0f : style.ItemSpacing.y;
397 const float available_icon_height = card_size.y - padding_y * 2.0f -
398 line_height - footer_height -
400 const float min_icon_radius = line_height * 0.9f;
401 float max_icon_radius = card_size.y * 0.24f;
402 max_icon_radius = std::max(max_icon_radius, min_icon_radius);
403 const float icon_radius = std::clamp(available_icon_height * 0.5f,
404 min_icon_radius, max_icon_radius);
406 const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
407 ImDrawList* draw_list = ImGui::GetWindowDrawList();
408 const ImVec2 icon_center(cursor_pos.x + card_size.x * 0.5f,
409 cursor_pos.y + padding_y + icon_radius);
410 float title_y = icon_center.y + icon_radius + style.ItemSpacing.y;
411 const float footer_y = cursor_pos.y + card_size.y - padding_y - footer_height;
412 if (title_y + line_height > footer_y - style.ItemSpacing.y) {
413 title_y = footer_y - line_height - style.ItemSpacing.y;
421 ImGui::GetColorU32(ScaleColor(base_color, 0.4f, 0.85f * disabled_alpha));
423 ImGui::GetColorU32(ScaleColor(base_color, 0.2f, 0.9f * disabled_alpha));
426 draw_list->AddRectFilledMultiColor(
428 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y), color_top,
429 color_top, color_bottom, color_bottom);
432 ImU32 border_color = is_recent
433 ? ImGui::GetColorU32(
434 WithAlpha(base_color, 1.0f * disabled_alpha))
435 : ImGui::GetColorU32(
436 ScaleColor(base_color, 0.6f,
437 0.7f * disabled_alpha));
438 const float rounding = std::max(style.FrameRounding, card_size.y * 0.05f);
439 const float border_thickness =
440 is_recent ? std::max(2.0f, style.FrameBorderSize + 1.0f)
441 : std::max(1.0f, style.FrameBorderSize);
444 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
445 border_color, rounding, 0, border_thickness);
449 const float badge_radius =
450 std::clamp(line_height * 0.6f, line_height * 0.4f, line_height);
451 ImVec2 badge_pos(cursor_pos.x + card_size.x - padding_x - badge_radius,
452 cursor_pos.y + padding_y + badge_radius);
453 draw_list->AddCircleFilled(badge_pos, badge_radius,
454 ImGui::GetColorU32(base_color), 16);
455 const ImU32 star_color = ImGui::GetColorU32(text_primary);
456 const ImVec2 star_size =
457 text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f,
ICON_MD_STAR);
458 const ImVec2 star_pos(badge_pos.x - star_size.x * 0.5f,
459 badge_pos.y - star_size.y * 0.5f);
460 draw_list->AddText(text_font, text_font_size, star_pos, star_color,
465 ImVec4 button_bg = ImGui::GetStyleColorVec4(ImGuiCol_Button);
468 {{ImGuiCol_Button, button_bg},
469 {ImGuiCol_ButtonHovered,
470 ScaleColor(base_color, 0.3f, enabled ? 0.5f : 0.2f)},
471 {ImGuiCol_ButtonActive,
472 ScaleColor(base_color, 0.5f, enabled ? 0.7f : 0.2f)}});
475 ImGui::BeginDisabled();
478 ImGui::Button(absl::StrCat(
"##", info.
name).c_str(), card_size);
480 ImGui::EndDisabled();
482 bool is_hovered = ImGui::IsItemHovered();
486 ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha));
487 draw_list->AddCircleFilled(icon_center, icon_radius, icon_bg, 32);
490 ImFont* icon_font = ImGui::GetFont();
491 if (ImGui::GetIO().Fonts->Fonts.size() > 2 &&
492 card_size.y >= kDashboardCardBaseHeight) {
493 icon_font = ImGui::GetIO().Fonts->Fonts[2];
494 }
else if (ImGui::GetIO().Fonts->Fonts.size() > 1) {
495 icon_font = ImGui::GetIO().Fonts->Fonts[1];
497 ImGui::PushFont(icon_font);
498 const float icon_font_size = ImGui::GetFontSize();
499 const ImVec2 icon_size = icon_font->CalcTextSizeA(icon_font_size, FLT_MAX,
500 0.0f, info.
icon.c_str());
502 const ImVec2 icon_text_pos(icon_center.x - icon_size.x * 0.5f,
503 icon_center.y - icon_size.y * 0.5f);
504 draw_list->AddText(icon_font, icon_font_size, icon_text_pos,
505 ImGui::GetColorU32(text_primary), info.
icon.c_str());
508 const ImVec2 name_size = text_font->CalcTextSizeA(text_font_size, FLT_MAX,
509 0.0f, info.
name.c_str());
510 float name_x = cursor_pos.x + (card_size.x - name_size.x) * 0.5f;
511 const float name_min_x = cursor_pos.x + padding_x;
512 const float name_max_x = cursor_pos.x + card_size.x - padding_x;
513 name_x = std::clamp(name_x, name_min_x, name_max_x);
514 const ImVec2 name_pos(name_x, title_y);
515 const ImVec4 name_clip(name_min_x, cursor_pos.y + padding_y, name_max_x,
518 text_font, text_font_size, name_pos,
519 ImGui::GetColorU32(WithAlpha(base_color, disabled_alpha)),
520 info.
name.c_str(),
nullptr, 0.0f, &name_clip);
524 const ImVec2 shortcut_pos(cursor_pos.x + padding_x, footer_y);
525 const ImVec4 shortcut_clip(cursor_pos.x + padding_x, footer_y,
526 cursor_pos.x + card_size.x - padding_x,
527 cursor_pos.y + card_size.y - padding_y);
528 draw_list->AddText(text_font, text_font_size, shortcut_pos,
529 ImGui::GetColorU32(text_secondary),
530 info.
shortcut.c_str(),
nullptr, 0.0f, &shortcut_clip);
536 ImGui::GetColorU32(ScaleColor(base_color, 1.0f,
537 enabled ? 0.18f : 0.08f));
538 draw_list->AddRectFilled(
540 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
541 glow_color, rounding);
546 const float tooltip_width = std::clamp(card_size.x * 1.4f, 240.0f, 340.0f);
547 ImGui::SetNextWindowSize(ImVec2(tooltip_width, 0), ImGuiCond_Always);
548 ImGui::BeginTooltip();
549 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
550 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
"%s %s",
551 info.
icon.c_str(), info.
name.c_str());
554 ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + tooltip_width - 20.0f);
556 ImGui::TextWrapped(
"Load a ROM to open this editor.");
558 ImGui::TextWrapped(
"%s", info.
description.c_str());
560 ImGui::PopTextWrapPos();
561 if (enabled && !info.
shortcut.empty()) {
563 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
568 ImGui::TextColored(accent,
ICON_MD_STAR " Recently used");
573 if (clicked && enabled) {