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, ScaleColor(base_color, 0.7f, 0.9f * alpha)},
296 {ImGuiCol_ButtonActive, WithAlpha(base_color, 1.0f * alpha)}});
299 stack_items ? avail_width : row_layout.item_width,
300 row_layout.item_height > 0.0f ? row_layout.item_height : height);
302 ImGui::BeginDisabled();
304 if (ImGui::Button(absl::StrCat(it->icon,
" ", it->name).c_str(),
314 ImGui::EndDisabled();
317 if (ImGui::IsItemHovered()) {
319 ImGui::SetTooltip(
"Load a ROM to open %s", it->name.c_str());
321 ImGui::SetTooltip(
"%s", it->description.c_str());
333 const ImGuiStyle& style = ImGui::GetStyle();
334 const float avail_width = ImGui::GetContentRegionAvail().x;
335 const float scale = ImGui::GetFontSize() / 16.0f;
336 const float compact_scale = avail_width < 620.0f ? 0.85f : 1.0f;
337 const float min_width = kDashboardCardBaseWidth *
338 kDashboardCardMinWidthFactor * scale * compact_scale;
339 const float max_width = kDashboardCardBaseWidth *
340 kDashboardCardWidthMaxFactor * scale * compact_scale;
341 const float min_height =
342 std::max(kDashboardCardBaseHeight * kDashboardCardMinHeightFactor *
343 scale * compact_scale,
344 ImGui::GetFrameHeight() * 3.2f);
345 const float max_height = kDashboardCardBaseHeight *
346 kDashboardCardHeightMaxFactor * scale *
348 const float aspect_ratio =
349 kDashboardCardBaseHeight / std::max(kDashboardCardBaseWidth, 1.0f);
350 const float spacing = style.ItemSpacing.x;
352 FlowLayout layout = ComputeFlowLayout(
353 avail_width, min_width, max_width, min_height, max_height, aspect_ratio,
354 spacing, kDashboardMaxColumns,
static_cast<int>(
editors_.size()));
356 ImGuiTableFlags table_flags =
357 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoPadOuterX;
358 const ImVec2 cell_padding(layout.spacing * 0.5f, style.ItemSpacing.y * 0.5f);
360 if (ImGui::BeginTable(
"DashboardEditorGrid", layout.columns, table_flags)) {
361 for (
size_t i = 0; i <
editors_.size(); ++i) {
362 ImGui::TableNextColumn();
365 ImVec2(layout.item_width, layout.item_height), enabled);
372 const ImVec2& card_size,
bool enabled) {
373 ImGui::PushID(index);
376 const float disabled_alpha = enabled ? 1.0f : 0.35f;
377 const ImVec4 base_color = GetEditorAccentColor(info.
type, theme);
381 text_primary.w *= enabled ? 1.0f : 0.5f;
382 text_secondary.w *= enabled ? 1.0f : 0.5f;
383 ImFont* text_font = ImGui::GetFont();
384 const float text_font_size = ImGui::GetFontSize();
386 const ImGuiStyle& style = ImGui::GetStyle();
387 const float line_height = ImGui::GetTextLineHeight();
388 const float padding_x = std::max(style.FramePadding.x, card_size.x * 0.06f);
389 const float padding_y = std::max(style.FramePadding.y, card_size.y * 0.08f);
391 const float footer_height = info.
shortcut.empty() ? 0.0f : line_height;
392 const float footer_spacing =
393 info.
shortcut.empty() ? 0.0f : style.ItemSpacing.y;
394 const float available_icon_height = card_size.y - padding_y * 2.0f -
395 line_height - footer_height -
397 const float min_icon_radius = line_height * 0.9f;
398 float max_icon_radius = card_size.y * 0.24f;
399 max_icon_radius = std::max(max_icon_radius, min_icon_radius);
400 const float icon_radius = std::clamp(available_icon_height * 0.5f,
401 min_icon_radius, max_icon_radius);
403 const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
404 ImDrawList* draw_list = ImGui::GetWindowDrawList();
405 const ImVec2 icon_center(cursor_pos.x + card_size.x * 0.5f,
406 cursor_pos.y + padding_y + icon_radius);
407 float title_y = icon_center.y + icon_radius + style.ItemSpacing.y;
408 const float footer_y = cursor_pos.y + card_size.y - padding_y - footer_height;
409 if (title_y + line_height > footer_y - style.ItemSpacing.y) {
410 title_y = footer_y - line_height - style.ItemSpacing.y;
418 ImGui::GetColorU32(ScaleColor(base_color, 0.4f, 0.85f * disabled_alpha));
420 ImGui::GetColorU32(ScaleColor(base_color, 0.2f, 0.9f * disabled_alpha));
423 draw_list->AddRectFilledMultiColor(
425 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y), color_top,
426 color_top, color_bottom, color_bottom);
431 ? ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha))
432 : ImGui::GetColorU32(
433 ScaleColor(base_color, 0.6f, 0.7f * disabled_alpha));
434 const float rounding = std::max(style.FrameRounding, card_size.y * 0.05f);
435 const float border_thickness =
436 is_recent ? std::max(2.0f, style.FrameBorderSize + 1.0f)
437 : std::max(1.0f, style.FrameBorderSize);
440 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
441 border_color, rounding, 0, border_thickness);
445 const float badge_radius =
446 std::clamp(line_height * 0.6f, line_height * 0.4f, line_height);
447 ImVec2 badge_pos(cursor_pos.x + card_size.x - padding_x - badge_radius,
448 cursor_pos.y + padding_y + badge_radius);
449 draw_list->AddCircleFilled(badge_pos, badge_radius,
450 ImGui::GetColorU32(base_color), 16);
451 const ImU32 star_color = ImGui::GetColorU32(text_primary);
452 const ImVec2 star_size =
453 text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f,
ICON_MD_STAR);
454 const ImVec2 star_pos(badge_pos.x - star_size.x * 0.5f,
455 badge_pos.y - star_size.y * 0.5f);
456 draw_list->AddText(text_font, text_font_size, star_pos, star_color,
461 ImVec4 button_bg = ImGui::GetStyleColorVec4(ImGuiCol_Button);
464 {{ImGuiCol_Button, button_bg},
465 {ImGuiCol_ButtonHovered,
466 ScaleColor(base_color, 0.3f, enabled ? 0.5f : 0.2f)},
467 {ImGuiCol_ButtonActive,
468 ScaleColor(base_color, 0.5f, enabled ? 0.7f : 0.2f)}});
471 ImGui::BeginDisabled();
474 ImGui::Button(absl::StrCat(
"##", info.
name).c_str(), card_size);
476 ImGui::EndDisabled();
478 bool is_hovered = ImGui::IsItemHovered();
482 ImGui::GetColorU32(WithAlpha(base_color, 1.0f * disabled_alpha));
483 draw_list->AddCircleFilled(icon_center, icon_radius, icon_bg, 32);
486 ImFont* icon_font = ImGui::GetFont();
487 if (ImGui::GetIO().Fonts->Fonts.size() > 2 &&
488 card_size.y >= kDashboardCardBaseHeight) {
489 icon_font = ImGui::GetIO().Fonts->Fonts[2];
490 }
else if (ImGui::GetIO().Fonts->Fonts.size() > 1) {
491 icon_font = ImGui::GetIO().Fonts->Fonts[1];
493 ImGui::PushFont(icon_font);
494 const float icon_font_size = ImGui::GetFontSize();
495 const ImVec2 icon_size = icon_font->CalcTextSizeA(icon_font_size, FLT_MAX,
496 0.0f, info.
icon.c_str());
498 const ImVec2 icon_text_pos(icon_center.x - icon_size.x * 0.5f,
499 icon_center.y - icon_size.y * 0.5f);
500 draw_list->AddText(icon_font, icon_font_size, icon_text_pos,
501 ImGui::GetColorU32(text_primary), info.
icon.c_str());
504 const ImVec2 name_size = text_font->CalcTextSizeA(text_font_size, FLT_MAX,
505 0.0f, info.
name.c_str());
506 float name_x = cursor_pos.x + (card_size.x - name_size.x) * 0.5f;
507 const float name_min_x = cursor_pos.x + padding_x;
508 const float name_max_x = cursor_pos.x + card_size.x - padding_x;
509 name_x = std::clamp(name_x, name_min_x, name_max_x);
510 const ImVec2 name_pos(name_x, title_y);
511 const ImVec4 name_clip(name_min_x, cursor_pos.y + padding_y, name_max_x,
513 draw_list->AddText(text_font, text_font_size, name_pos,
514 ImGui::GetColorU32(WithAlpha(base_color, disabled_alpha)),
515 info.
name.c_str(),
nullptr, 0.0f, &name_clip);
519 const ImVec2 shortcut_pos(cursor_pos.x + padding_x, footer_y);
520 const ImVec4 shortcut_clip(cursor_pos.x + padding_x, footer_y,
521 cursor_pos.x + card_size.x - padding_x,
522 cursor_pos.y + card_size.y - padding_y);
523 draw_list->AddText(text_font, text_font_size, shortcut_pos,
524 ImGui::GetColorU32(text_secondary),
525 info.
shortcut.c_str(),
nullptr, 0.0f, &shortcut_clip);
530 ImU32 glow_color = ImGui::GetColorU32(
531 ScaleColor(base_color, 1.0f, enabled ? 0.18f : 0.08f));
532 draw_list->AddRectFilled(
534 ImVec2(cursor_pos.x + card_size.x, cursor_pos.y + card_size.y),
535 glow_color, rounding);
540 const float tooltip_width = std::clamp(card_size.x * 1.4f, 240.0f, 340.0f);
541 ImGui::SetNextWindowSize(ImVec2(tooltip_width, 0), ImGuiCond_Always);
542 ImGui::BeginTooltip();
543 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
544 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
"%s %s",
545 info.
icon.c_str(), info.
name.c_str());
548 ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + tooltip_width - 20.0f);
550 ImGui::TextWrapped(
"Load a ROM to open this editor.");
552 ImGui::TextWrapped(
"%s", info.
description.c_str());
554 ImGui::PopTextWrapPos();
555 if (enabled && !info.
shortcut.empty()) {
557 ImGui::TextColored(WithAlpha(base_color, disabled_alpha),
562 ImGui::TextColored(accent,
ICON_MD_STAR " Recently used");
567 if (clicked && enabled) {