250 const ImGuiStyle& style = ImGui::GetStyle();
251 const float avail_width = ImGui::GetContentRegionAvail().x;
252 const float min_width = kDashboardRecentBaseWidth;
253 const float max_width =
254 kDashboardRecentBaseWidth * kDashboardRecentWidthMaxFactor;
256 std::max(kDashboardRecentBaseHeight, ImGui::GetFrameHeight());
257 const float spacing = style.ItemSpacing.x;
258 const bool stack_items = avail_width < min_width * 1.6f;
259 FlowLayout row_layout{};
261 row_layout.columns = 1;
262 row_layout.item_width = avail_width;
263 row_layout.item_height = height;
264 row_layout.spacing = spacing;
266 row_layout = ComputeFlowLayout(avail_width, min_width, max_width, height,
267 height, height / std::max(min_width, 1.0f),
268 spacing, kDashboardMaxRecentColumns,
272 ImGuiTableFlags table_flags =
273 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
274 const ImVec2 cell_padding(row_layout.spacing * 0.5f,
275 style.ItemSpacing.y * 0.4f);
277 if (ImGui::BeginTable(
"DashboardRecentGrid", row_layout.columns,
281 auto it = std::find_if(
283 [type](
const EditorInfo& info) { return info.type == type; });
289 ImGui::TableNextColumn();
291 const bool enabled =
has_rom_ || !it->requires_rom;
292 const float alpha = enabled ? 1.0f : 0.35f;
293 const ImVec4 base_color = GetEditorAccentColor(it->type, theme);
295 {{ImGuiCol_Button, ScaleColor(base_color, 0.5f, 0.7f * alpha)},
296 {ImGuiCol_ButtonHovered, 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(tr(
"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 = kDashboardCardBaseWidth *
339 kDashboardCardMinWidthFactor * scale * compact_scale;
340 const float max_width = kDashboardCardBaseWidth *
341 kDashboardCardWidthMaxFactor * scale * compact_scale;
342 const float min_height =
343 std::max(kDashboardCardBaseHeight * kDashboardCardMinHeightFactor *
344 scale * compact_scale,
345 ImGui::GetFrameHeight() * 3.2f);
346 const float max_height = kDashboardCardBaseHeight *
347 kDashboardCardHeightMaxFactor * scale *
349 const float aspect_ratio =
350 kDashboardCardBaseHeight / std::max(kDashboardCardBaseWidth, 1.0f);
351 const float spacing = style.ItemSpacing.x;
353 FlowLayout layout = ComputeFlowLayout(
354 avail_width, min_width, max_width, min_height, max_height, aspect_ratio,
355 spacing, kDashboardMaxColumns,
static_cast<int>(
editors_.size()));
357 ImGuiTableFlags table_flags =
358 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
359 const ImVec2 cell_padding(layout.spacing * 0.5f, style.ItemSpacing.y * 0.5f);
361 if (ImGui::BeginTable(
"DashboardEditorGrid", layout.columns, table_flags)) {
362 for (
size_t i = 0; i <
editors_.size(); ++i) {
363 ImGui::TableNextColumn();
366 ImVec2(layout.item_width, layout.item_height), enabled);
373 const ImVec2& card_size,
bool enabled) {
374 ImGui::PushID(index);
377 const float disabled_alpha = enabled ? 1.0f : 0.35f;
378 const ImVec4 base_color = GetEditorAccentColor(info.
type, theme);
382 text_primary.w *= enabled ? 1.0f : 0.5f;
383 text_secondary.w *= enabled ? 1.0f : 0.5f;
384 ImFont* text_font = ImGui::GetFont();
385 const float text_font_size = ImGui::GetFontSize();
387 const ImGuiStyle& style = ImGui::GetStyle();
388 const float line_height = ImGui::GetTextLineHeight();
389 const float padding_x = std::max(style.FramePadding.x, card_size.x * 0.06f);
390 const float padding_y = std::max(style.FramePadding.y, card_size.y * 0.08f);
392 const float footer_height = info.
shortcut.empty() ? 0.0f : line_height;
393 const float footer_spacing =
394 info.
shortcut.empty() ? 0.0f : style.ItemSpacing.y;
395 const float available_icon_height = card_size.y - padding_y * 2.0f -
396 line_height - footer_height -
398 const float min_icon_radius = line_height * 0.9f;
399 float max_icon_radius = card_size.y * 0.24f;
400 max_icon_radius = std::max(max_icon_radius, min_icon_radius);
401 const float icon_radius = std::clamp(available_icon_height * 0.5f,
402 min_icon_radius, max_icon_radius);
404 const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
405 ImDrawList* draw_list = ImGui::GetWindowDrawList();
406 const ImVec2 icon_center(cursor_pos.x + card_size.x * 0.5f,
407 cursor_pos.y + padding_y + icon_radius);
408 float title_y = icon_center.y + icon_radius + style.ItemSpacing.y;
409 const float footer_y = cursor_pos.y + card_size.y - padding_y - footer_height;
410 if (title_y + line_height > footer_y - style.ItemSpacing.y) {
411 title_y = footer_y - line_height - style.ItemSpacing.y;
419 ImGui::GetColorU32(ScaleColor(base_color, 0.4f, 0.85f * disabled_alpha));
421 ImGui::GetColorU32(ScaleColor(base_color, 0.2f, 0.9f * disabled_alpha));
424 draw_list->AddRectFilledMultiColor(
426 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y), color_top,
427 color_top, color_bottom, color_bottom);
432 ? ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha))
433 : ImGui::GetColorU32(
434 ScaleColor(base_color, 0.6f, 0.7f * disabled_alpha));
435 const float rounding = std::max(style.FrameRounding, card_size.y * 0.05f);
436 const float border_thickness =
437 is_recent ? std::max(2.0f, style.FrameBorderSize + 1.0f)
438 : std::max(1.0f, style.FrameBorderSize);
441 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
442 border_color, rounding, 0, border_thickness);
446 const float badge_radius =
447 std::clamp(line_height * 0.6f, line_height * 0.4f, line_height);
448 ImVec2 badge_pos(cursor_pos.x + card_size.x - padding_x - badge_radius,
449 cursor_pos.y + padding_y + badge_radius);
450 draw_list->AddCircleFilled(badge_pos, badge_radius,
451 ImGui::GetColorU32(base_color), 16);
452 const ImU32 star_color = ImGui::GetColorU32(text_primary);
453 const ImVec2 star_size =
454 text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f,
ICON_MD_STAR);
455 const ImVec2 star_pos(badge_pos.x - star_size.x * 0.5f,
456 badge_pos.y - star_size.y * 0.5f);
457 draw_list->AddText(text_font, text_font_size, star_pos, star_color,
462 ImVec4 button_bg = ImGui::GetStyleColorVec4(ImGuiCol_Button);
465 {{ImGuiCol_Button, button_bg},
466 {ImGuiCol_ButtonHovered,
467 ScaleColor(base_color, 0.3f, enabled ? 0.5f : 0.2f)},
468 {ImGuiCol_ButtonActive,
469 ScaleColor(base_color, 0.5f, enabled ? 0.7f : 0.2f)}});
472 ImGui::BeginDisabled();
475 ImGui::Button(absl::StrCat(
"##", info.
name).c_str(), card_size);
477 ImGui::EndDisabled();
479 bool is_hovered = ImGui::IsItemHovered();
483 ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha));
484 draw_list->AddCircleFilled(icon_center, icon_radius, icon_bg, 32);
487 ImFont* icon_font = ImGui::GetFont();
488 if (ImGui::GetIO().Fonts->Fonts.size() > 2 &&
489 card_size.y >= kDashboardCardBaseHeight) {
490 icon_font = ImGui::GetIO().Fonts->Fonts[2];
491 }
else if (ImGui::GetIO().Fonts->Fonts.size() > 1) {
492 icon_font = ImGui::GetIO().Fonts->Fonts[1];
494 ImGui::PushFont(icon_font);
495 const float icon_font_size = ImGui::GetFontSize();
496 const ImVec2 icon_size = icon_font->CalcTextSizeA(icon_font_size, FLT_MAX,
497 0.0f, info.
icon.c_str());
499 const ImVec2 icon_text_pos(icon_center.x - icon_size.x * 0.5f,
500 icon_center.y - icon_size.y * 0.5f);
501 draw_list->AddText(icon_font, icon_font_size, icon_text_pos,
502 ImGui::GetColorU32(text_primary), info.
icon.c_str());
505 const ImVec2 name_size = text_font->CalcTextSizeA(text_font_size, FLT_MAX,
506 0.0f, info.
name.c_str());
507 float name_x = cursor_pos.x + (card_size.x - name_size.x) * 0.5f;
508 const float name_min_x = cursor_pos.x + padding_x;
509 const float name_max_x = cursor_pos.x + card_size.x - padding_x;
510 name_x = std::clamp(name_x, name_min_x, name_max_x);
511 const ImVec2 name_pos(name_x, title_y);
512 const ImVec4 name_clip(name_min_x, cursor_pos.y + padding_y, name_max_x,
514 draw_list->AddText(text_font, text_font_size, name_pos,
515 ImGui::GetColorU32(WithAlpha(base_color, disabled_alpha)),
516 info.
name.c_str(),
nullptr, 0.0f, &name_clip);
520 const ImVec2 shortcut_pos(cursor_pos.x + padding_x, footer_y);
521 const ImVec4 shortcut_clip(cursor_pos.x + padding_x, footer_y,
522 cursor_pos.x + card_size.x - padding_x,
523 cursor_pos.y + card_size.y - padding_y);
524 draw_list->AddText(text_font, text_font_size, shortcut_pos,
525 ImGui::GetColorU32(text_secondary),
526 info.
shortcut.c_str(),
nullptr, 0.0f, &shortcut_clip);
531 ImU32 glow_color = ImGui::GetColorU32(
532 ScaleColor(base_color, 1.0f, enabled ? 0.18f : 0.08f));
533 draw_list->AddRectFilled(
535 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
536 glow_color, rounding);
541 const float tooltip_width = std::clamp(card_size.x * 1.4f, 240.0f, 340.0f);
542 ImGui::SetNextWindowSize(ImVec2(tooltip_width, 0), ImGuiCond_Always);
543 ImGui::BeginTooltip();
544 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
545 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
"%s %s",
546 info.
icon.c_str(), info.
name.c_str());
549 ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + tooltip_width - 20.0f);
551 ImGui::TextWrapped(tr(
"Load a ROM to open this editor."));
553 ImGui::TextWrapped(
"%s", info.
description.c_str());
555 ImGui::PopTextWrapPos();
556 if (enabled && !info.
shortcut.empty()) {
558 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
563 ImGui::TextColored(accent,
ICON_MD_STAR " Recently used");
568 if (clicked && enabled) {