From 1c56864ccbdfde5b392b3f4fe3d40d408a849179 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Mon, 9 Jan 2023 13:37:40 +0800 Subject: [PATCH] Centered timeline time indicators and keyframe icons --- .../AnimationEditor/SHAnimationEditor.cpp | 6 +++-- SHADE_Engine/src/Editor/SHEditorUI.cpp | 12 +++++++++ SHADE_Engine/src/Editor/SHEditorUI.h | 26 ++++++++++++++----- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AnimationEditor/SHAnimationEditor.cpp b/SHADE_Engine/src/Editor/EditorWindow/AnimationEditor/SHAnimationEditor.cpp index 0c6673fa..8e730b07 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AnimationEditor/SHAnimationEditor.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AnimationEditor/SHAnimationEditor.cpp @@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include #include "Editor/IconsMaterialDesign.h" +#include "Editor/SHEditorUI.h" namespace SHADE { @@ -144,7 +145,7 @@ namespace SHADE // Draw Text ImGui::SetCursorPos(ImVec2(X_OFFSET, TIMELINE_HEADER_START_POS.y)); std::string timeText = std::format("{:.{}f}", time, 1); - ImGui::Text(timeText.c_str()); + SHEditorUI::CenteredText(timeText.c_str()); // Draw line ImVec2 startPoint { WINDOW_POS.x + X_OFFSET, WINDOW_POS.y + TIMELINE_HEADER_START_POS.y }; @@ -172,7 +173,8 @@ namespace SHADE for (const auto& keyframe : channel.KeyFrames) { ImGui::SetCursorPos(ImVec2(START_POS.x + keyframe.TimeStamp * DIST_PER_SECOND, START_POS.y)); - ImGui::Text(ICON_MD_RADIO_BUTTON_CHECKED); + static constexpr float ICON_WIDTH = 6.0f; // We do this as ImGui gives the wrong width for icon fonts + SHEditorUI::OffsetText(ICON_MD_RADIO_BUTTON_CHECKED, -ICON_WIDTH * 0.5f); } ImGui::SetCursorPos(START_POS); } diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index b9783020..856a384a 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -137,6 +137,18 @@ namespace SHADE { ImGui::Text(title.c_str()); } + + void SHEditorUI::CenteredText(const std::string& title) + { + OffsetText(title, -ImGui::CalcTextSize(title.c_str()).x * 1.5f); + } + + void SHEditorUI::OffsetText(const std::string& title, float offset) + { + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + offset); + ImGui::Text(title.c_str()); + } + bool SHEditorUI::SmallButton(const std::string& title) { return ImGui::SmallButton(title.c_str()); diff --git a/SHADE_Engine/src/Editor/SHEditorUI.h b/SHADE_Engine/src/Editor/SHEditorUI.h index cd87f46b..5d2b1470 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.h +++ b/SHADE_Engine/src/Editor/SHEditorUI.h @@ -90,7 +90,7 @@ namespace SHADE /// True if the header is open, false otherwise. static bool CollapsingHeader(const std::string& title, bool* isHovered = nullptr); static void SameLine(); - static void Separator(); + static void Separator(); /*-----------------------------------------------------------------------------*/ /* ImGui Wrapper Functions - Queries */ @@ -98,9 +98,9 @@ namespace SHADE static bool IsItemHovered(); /*-----------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Menu */ - /*-----------------------------------------------------------------------------*/ - static bool BeginMenu(const std::string& label); + /* ImGui Wrapper Functions - Menu */ + /*-----------------------------------------------------------------------------*/ + static bool BeginMenu(const std::string& label); static bool BeginMenu(const std::string& label, const char* icon); static void EndMenu(); static void BeginTooltip(); @@ -150,6 +150,19 @@ namespace SHADE /// Text to display. static void Text(const std::string& title); /// + /// Creates a visual text widget that is visually centered about the current + /// cursor point. + /// + /// Text to display. + static void CenteredText(const std::string& title); + /// + /// Creates a visual text widget that is visually offset from the current cursor + /// point. + /// + /// Text to display. + /// Distance to offset. Positive is to the right. + static void OffsetText(const std::string& title, float offset); + /// /// Creates a small inline button widget. ///
/// Wraps up ImGui::SmallButton(). @@ -164,8 +177,8 @@ namespace SHADE ///
/// Text to display. /// True if button was pressed. - static bool Button(const std::string& title); - static bool Selectable(const std::string& label); + static bool Button(const std::string& title); + static bool Selectable(const std::string& label); static bool Selectable(const std::string& label, const char* icon); /// /// Creates a checkbox widget for boolean input. @@ -341,7 +354,6 @@ namespace SHADE /// Whether the value was modified. static bool InputEnumCombo(const std::string& label, int& v, const std::vector& enumNames, bool* isHovered = nullptr); - private: // Prevent instantiation of this static class SHEditorUI() = delete;