Centered timeline time indicators and keyframe icons

This commit is contained in:
Kah Wei 2023-01-09 13:37:40 +08:00
parent b93dfe3ba4
commit 1c56864ccb
3 changed files with 35 additions and 9 deletions

View File

@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited.
// External Dependencies
#include <imgui.h>
#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);
}

View File

@ -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());

View File

@ -90,7 +90,7 @@ namespace SHADE
/// <returns>True if the header is open, false otherwise.</returns>
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
/// <param name="title">Text to display.</param>
static void Text(const std::string& title);
/// <summary>
/// Creates a visual text widget that is visually centered about the current
/// cursor point.
/// </summary>
/// <param name="title">Text to display.</param>
static void CenteredText(const std::string& title);
/// <summary>
/// Creates a visual text widget that is visually offset from the current cursor
/// point.
/// </summary>
/// <param name="title">Text to display.</param>
/// <param name="offset">Distance to offset. Positive is to the right.</param>
static void OffsetText(const std::string& title, float offset);
/// <summary>
/// Creates a small inline button widget.
/// <br/>
/// Wraps up ImGui::SmallButton().
@ -164,8 +177,8 @@ namespace SHADE
/// </summary>
/// <param name="title">Text to display.</param>
/// <returns>True if button was pressed.</returns>
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);
/// <summary>
/// Creates a checkbox widget for boolean input.
@ -341,7 +354,6 @@ namespace SHADE
/// <returns>Whether the value was modified.</returns>
static bool InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered = nullptr);
private:
// Prevent instantiation of this static class
SHEditorUI() = delete;