imgui-frontend-engineer: refine editor card text rendering
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "app/editor/ui/dashboard_panel.h"
|
#include "app/editor/ui/dashboard_panel.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cfloat>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -347,6 +348,8 @@ void DashboardPanel::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
const ImVec4 text_primary = gui::ConvertColorToImVec4(theme.text_primary);
|
const ImVec4 text_primary = gui::ConvertColorToImVec4(theme.text_primary);
|
||||||
const ImVec4 text_secondary = gui::ConvertColorToImVec4(theme.text_secondary);
|
const ImVec4 text_secondary = gui::ConvertColorToImVec4(theme.text_secondary);
|
||||||
const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
|
const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
|
||||||
|
ImFont* text_font = ImGui::GetFont();
|
||||||
|
const float text_font_size = ImGui::GetFontSize();
|
||||||
|
|
||||||
const ImGuiStyle& style = ImGui::GetStyle();
|
const ImGuiStyle& style = ImGui::GetStyle();
|
||||||
const float line_height = ImGui::GetTextLineHeight();
|
const float line_height = ImGui::GetTextLineHeight();
|
||||||
@@ -410,11 +413,14 @@ void DashboardPanel::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
cursor_pos.y + padding_y + badge_radius);
|
cursor_pos.y + padding_y + badge_radius);
|
||||||
draw_list->AddCircleFilled(badge_pos, badge_radius,
|
draw_list->AddCircleFilled(badge_pos, badge_radius,
|
||||||
ImGui::GetColorU32(base_color), 16);
|
ImGui::GetColorU32(base_color), 16);
|
||||||
ImVec2 star_size = ImGui::CalcTextSize(ICON_MD_STAR);
|
const ImU32 star_color = ImGui::GetColorU32(text_primary);
|
||||||
ImGui::SetCursorScreenPos(
|
const ImVec2 star_size =
|
||||||
ImVec2(badge_pos.x - star_size.x * 0.5f,
|
text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f,
|
||||||
badge_pos.y - star_size.y * 0.5f));
|
ICON_MD_STAR);
|
||||||
ImGui::TextColored(text_primary, ICON_MD_STAR);
|
const ImVec2 star_pos(badge_pos.x - star_size.x * 0.5f,
|
||||||
|
badge_pos.y - star_size.y * 0.5f);
|
||||||
|
draw_list->AddText(text_font, text_font_size, star_pos, star_color,
|
||||||
|
ICON_MD_STAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make button transparent (we draw our own background)
|
// Make button transparent (we draw our own background)
|
||||||
@@ -426,11 +432,9 @@ void DashboardPanel::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
||||||
ScaleColor(base_color, 0.5f, 0.7f));
|
ScaleColor(base_color, 0.5f, 0.7f));
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(cursor_pos);
|
|
||||||
bool clicked =
|
bool clicked =
|
||||||
ImGui::Button(absl::StrCat("##", info.name).c_str(), card_size);
|
ImGui::Button(absl::StrCat("##", info.name).c_str(), card_size);
|
||||||
bool is_hovered = ImGui::IsItemHovered();
|
bool is_hovered = ImGui::IsItemHovered();
|
||||||
const ImVec2 after_button = ImGui::GetCursorScreenPos();
|
|
||||||
|
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
@@ -447,27 +451,40 @@ void DashboardPanel::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
icon_font = ImGui::GetIO().Fonts->Fonts[1];
|
icon_font = ImGui::GetIO().Fonts->Fonts[1];
|
||||||
}
|
}
|
||||||
ImGui::PushFont(icon_font);
|
ImGui::PushFont(icon_font);
|
||||||
ImVec2 icon_size = ImGui::CalcTextSize(info.icon.c_str());
|
const float icon_font_size = ImGui::GetFontSize();
|
||||||
ImGui::SetCursorScreenPos(
|
const ImVec2 icon_size =
|
||||||
ImVec2(icon_center.x - icon_size.x / 2, icon_center.y - icon_size.y / 2));
|
icon_font->CalcTextSizeA(icon_font_size, FLT_MAX, 0.0f,
|
||||||
ImGui::TextColored(text_primary, "%s", info.icon.c_str());
|
info.icon.c_str());
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
const ImVec2 icon_text_pos(icon_center.x - icon_size.x * 0.5f,
|
||||||
|
icon_center.y - icon_size.y * 0.5f);
|
||||||
|
draw_list->AddText(icon_font, icon_font_size, icon_text_pos,
|
||||||
|
ImGui::GetColorU32(text_primary), info.icon.c_str());
|
||||||
|
|
||||||
// Draw name
|
// Draw name
|
||||||
const float name_wrap_width = card_size.x - padding_x * 2.0f;
|
const ImVec2 name_size =
|
||||||
ImGui::PushTextWrapPos(cursor_pos.x + card_size.x - padding_x);
|
text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f,
|
||||||
ImVec2 name_size =
|
info.name.c_str());
|
||||||
ImGui::CalcTextSize(info.name.c_str(), nullptr, false, name_wrap_width);
|
float name_x = cursor_pos.x + (card_size.x - name_size.x) * 0.5f;
|
||||||
ImGui::SetCursorScreenPos(ImVec2(
|
const float name_min_x = cursor_pos.x + padding_x;
|
||||||
cursor_pos.x + (card_size.x - name_size.x) / 2.0f, title_y));
|
const float name_max_x = cursor_pos.x + card_size.x - padding_x;
|
||||||
ImGui::TextColored(base_color, "%s", info.name.c_str());
|
name_x = std::clamp(name_x, name_min_x, name_max_x);
|
||||||
ImGui::PopTextWrapPos();
|
const ImVec2 name_pos(name_x, title_y);
|
||||||
|
const ImVec4 name_clip(name_min_x, cursor_pos.y + padding_y, name_max_x,
|
||||||
|
footer_y);
|
||||||
|
draw_list->AddText(text_font, text_font_size, name_pos,
|
||||||
|
ImGui::GetColorU32(base_color), info.name.c_str(), nullptr,
|
||||||
|
0.0f, &name_clip);
|
||||||
|
|
||||||
// Draw shortcut hint if available
|
// Draw shortcut hint if available
|
||||||
if (!info.shortcut.empty()) {
|
if (!info.shortcut.empty()) {
|
||||||
ImGui::SetCursorScreenPos(
|
const ImVec2 shortcut_pos(cursor_pos.x + padding_x, footer_y);
|
||||||
ImVec2(cursor_pos.x + padding_x, footer_y));
|
const ImVec4 shortcut_clip(cursor_pos.x + padding_x, footer_y,
|
||||||
ImGui::TextColored(text_secondary, "%s", info.shortcut.c_str());
|
cursor_pos.x + card_size.x - padding_x,
|
||||||
|
cursor_pos.y + card_size.y - padding_y);
|
||||||
|
draw_list->AddText(text_font, text_font_size, shortcut_pos,
|
||||||
|
ImGui::GetColorU32(text_secondary),
|
||||||
|
info.shortcut.c_str(), nullptr, 0.0f, &shortcut_clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hover glow effect
|
// Hover glow effect
|
||||||
@@ -512,7 +529,6 @@ void DashboardPanel::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(after_button);
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "app/editor/ui/editor_selection_dialog.h"
|
#include "app/editor/ui/editor_selection_dialog.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cfloat>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -378,6 +379,8 @@ void EditorSelectionDialog::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
const ImVec4 text_primary = gui::ConvertColorToImVec4(theme.text_primary);
|
const ImVec4 text_primary = gui::ConvertColorToImVec4(theme.text_primary);
|
||||||
const ImVec4 text_secondary = gui::ConvertColorToImVec4(theme.text_secondary);
|
const ImVec4 text_secondary = gui::ConvertColorToImVec4(theme.text_secondary);
|
||||||
const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
|
const ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
|
||||||
|
ImFont* text_font = ImGui::GetFont();
|
||||||
|
const float text_font_size = ImGui::GetFontSize();
|
||||||
|
|
||||||
const ImGuiStyle& style = ImGui::GetStyle();
|
const ImGuiStyle& style = ImGui::GetStyle();
|
||||||
const float line_height = ImGui::GetTextLineHeight();
|
const float line_height = ImGui::GetTextLineHeight();
|
||||||
@@ -442,11 +445,14 @@ void EditorSelectionDialog::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
cursor_pos.y + padding_y + badge_radius);
|
cursor_pos.y + padding_y + badge_radius);
|
||||||
draw_list->AddCircleFilled(badge_pos, badge_radius,
|
draw_list->AddCircleFilled(badge_pos, badge_radius,
|
||||||
ImGui::GetColorU32(base_color), 16);
|
ImGui::GetColorU32(base_color), 16);
|
||||||
ImVec2 star_size = ImGui::CalcTextSize(ICON_MD_STAR);
|
const ImU32 star_color = ImGui::GetColorU32(text_primary);
|
||||||
ImGui::SetCursorScreenPos(
|
const ImVec2 star_size =
|
||||||
ImVec2(badge_pos.x - star_size.x * 0.5f,
|
text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f,
|
||||||
badge_pos.y - star_size.y * 0.5f));
|
ICON_MD_STAR);
|
||||||
ImGui::TextColored(text_primary, ICON_MD_STAR);
|
const ImVec2 star_pos(badge_pos.x - star_size.x * 0.5f,
|
||||||
|
badge_pos.y - star_size.y * 0.5f);
|
||||||
|
draw_list->AddText(text_font, text_font_size, star_pos, star_color,
|
||||||
|
ICON_MD_STAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make button transparent (we draw our own background)
|
// Make button transparent (we draw our own background)
|
||||||
@@ -458,11 +464,9 @@ void EditorSelectionDialog::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
||||||
ScaleColor(base_color, 0.5f, 0.7f));
|
ScaleColor(base_color, 0.5f, 0.7f));
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(cursor_pos);
|
|
||||||
bool clicked =
|
bool clicked =
|
||||||
ImGui::Button(absl::StrCat("##", info.name).c_str(), card_size);
|
ImGui::Button(absl::StrCat("##", info.name).c_str(), card_size);
|
||||||
bool is_hovered = ImGui::IsItemHovered();
|
bool is_hovered = ImGui::IsItemHovered();
|
||||||
const ImVec2 after_button = ImGui::GetCursorScreenPos();
|
|
||||||
|
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
@@ -471,28 +475,45 @@ void EditorSelectionDialog::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
draw_list->AddCircleFilled(icon_center, icon_radius, icon_bg, 32);
|
draw_list->AddCircleFilled(icon_center, icon_radius, icon_bg, 32);
|
||||||
|
|
||||||
// Draw icon
|
// Draw icon
|
||||||
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[2]); // Larger font for icon
|
ImFont* icon_font = ImGui::GetFont();
|
||||||
ImVec2 icon_size = ImGui::CalcTextSize(info.icon);
|
if (ImGui::GetIO().Fonts->Fonts.size() > 2) {
|
||||||
ImGui::SetCursorScreenPos(
|
icon_font = ImGui::GetIO().Fonts->Fonts[2];
|
||||||
ImVec2(icon_center.x - icon_size.x / 2, icon_center.y - icon_size.y / 2));
|
} else if (ImGui::GetIO().Fonts->Fonts.size() > 1) {
|
||||||
ImGui::TextColored(text_primary, "%s", info.icon);
|
icon_font = ImGui::GetIO().Fonts->Fonts[1];
|
||||||
|
}
|
||||||
|
ImGui::PushFont(icon_font);
|
||||||
|
const float icon_font_size = ImGui::GetFontSize();
|
||||||
|
const ImVec2 icon_size =
|
||||||
|
icon_font->CalcTextSizeA(icon_font_size, FLT_MAX, 0.0f, info.icon);
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
const ImVec2 icon_text_pos(icon_center.x - icon_size.x * 0.5f,
|
||||||
|
icon_center.y - icon_size.y * 0.5f);
|
||||||
|
draw_list->AddText(icon_font, icon_font_size, icon_text_pos,
|
||||||
|
ImGui::GetColorU32(text_primary), info.icon);
|
||||||
|
|
||||||
// Draw name
|
// Draw name
|
||||||
const float name_wrap_width = card_size.x - padding_x * 2.0f;
|
const ImVec2 name_size =
|
||||||
ImGui::PushTextWrapPos(cursor_pos.x + card_size.x - padding_x);
|
text_font->CalcTextSizeA(text_font_size, FLT_MAX, 0.0f, info.name);
|
||||||
ImVec2 name_size =
|
float name_x = cursor_pos.x + (card_size.x - name_size.x) * 0.5f;
|
||||||
ImGui::CalcTextSize(info.name, nullptr, false, name_wrap_width);
|
const float name_min_x = cursor_pos.x + padding_x;
|
||||||
ImGui::SetCursorScreenPos(ImVec2(
|
const float name_max_x = cursor_pos.x + card_size.x - padding_x;
|
||||||
cursor_pos.x + (card_size.x - name_size.x) / 2.0f, title_y));
|
name_x = std::clamp(name_x, name_min_x, name_max_x);
|
||||||
ImGui::TextColored(base_color, "%s", info.name);
|
const ImVec2 name_pos(name_x, title_y);
|
||||||
ImGui::PopTextWrapPos();
|
const ImVec4 name_clip(name_min_x, cursor_pos.y + padding_y, name_max_x,
|
||||||
|
footer_y);
|
||||||
|
draw_list->AddText(text_font, text_font_size, name_pos,
|
||||||
|
ImGui::GetColorU32(base_color), info.name, nullptr, 0.0f,
|
||||||
|
&name_clip);
|
||||||
|
|
||||||
// Draw shortcut hint if available
|
// Draw shortcut hint if available
|
||||||
if (!info.shortcut.empty()) {
|
if (!info.shortcut.empty()) {
|
||||||
ImGui::SetCursorScreenPos(
|
const ImVec2 shortcut_pos(cursor_pos.x + padding_x, footer_y);
|
||||||
ImVec2(cursor_pos.x + padding_x, footer_y));
|
const ImVec4 shortcut_clip(cursor_pos.x + padding_x, footer_y,
|
||||||
ImGui::TextColored(text_secondary, "%s", info.shortcut.c_str());
|
cursor_pos.x + card_size.x - padding_x,
|
||||||
|
cursor_pos.y + card_size.y - padding_y);
|
||||||
|
draw_list->AddText(text_font, text_font_size, shortcut_pos,
|
||||||
|
ImGui::GetColorU32(text_secondary),
|
||||||
|
info.shortcut.c_str(), nullptr, 0.0f, &shortcut_clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hover glow effect
|
// Hover glow effect
|
||||||
@@ -532,7 +553,6 @@ void EditorSelectionDialog::DrawEditorPanel(const EditorInfo& info, int index,
|
|||||||
selected_editor_ = info.type;
|
selected_editor_ = info.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(after_button);
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,39 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>SchemeUserState</key>
|
|
||||||
<dict>
|
|
||||||
<key>example_apple_metal_ios.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>2</integer>
|
|
||||||
</dict>
|
|
||||||
<key>example_apple_metal_macos.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
</dict>
|
|
||||||
<key>imgui_apple_metal_ios.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>2</integer>
|
|
||||||
</dict>
|
|
||||||
<key>imgui_apple_metal_macos.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>0</integer>
|
|
||||||
</dict>
|
|
||||||
<key>yaze_ios.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>10</integer>
|
|
||||||
</dict>
|
|
||||||
<key>yaze_macos.xcscheme_^#shared#^_</key>
|
|
||||||
<dict>
|
|
||||||
<key>orderHint</key>
|
|
||||||
<integer>11</integer>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
Reference in New Issue
Block a user