mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-03 22:28:45 +00:00
Add help
This commit is contained in:
@@ -54,13 +54,40 @@ void UCogWindow::Render(float DeltaTime)
|
||||
ImGuiWindowFlags WindowFlags = 0;
|
||||
PreRender(WindowFlags);
|
||||
|
||||
if (ImGui::Begin(TCHAR_TO_ANSI(*GetTitle()), &bIsVisible, WindowFlags))
|
||||
const FString WindowTitle = GetTitle() + "##" + Name;
|
||||
|
||||
if (ImGui::Begin(TCHAR_TO_ANSI(*WindowTitle), &bIsVisible, WindowFlags))
|
||||
{
|
||||
if (Owner->GetShowHelp())
|
||||
{
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_PopupBg, IM_COL32(29, 42, 62, 240));
|
||||
const float HelpWidth = FCogWindowWidgets::GetFontWidth() * 80;
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(HelpWidth / 2.0f, 0.0f),
|
||||
ImVec2(HelpWidth, FLT_MAX));
|
||||
if (ImGui::BeginTooltip())
|
||||
{
|
||||
ImGui::PushTextWrapPos(HelpWidth - 1 * FCogWindowWidgets::GetFontWidth());
|
||||
RenderHelp();
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
RenderContent();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::RenderHelp()
|
||||
{
|
||||
ImGui::Text("No help available.");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::RenderTick(float DeltaTime)
|
||||
{
|
||||
@@ -75,20 +102,20 @@ void UCogWindow::GameTick(float DeltaTime)
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::DrawMenuItem(const FString& MenuItemName)
|
||||
{
|
||||
if (bShowInsideMenu && bIsVisible == false)
|
||||
if (bShowInsideMenu)
|
||||
{
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(FCogWindowWidgets::TextBaseWidth * 40, FCogWindowWidgets::TextBaseHeight * 1),
|
||||
ImVec2(FCogWindowWidgets::TextBaseWidth * 50, FCogWindowWidgets::TextBaseHeight * 60));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(FCogWindowWidgets::GetFontWidth() * 40, ImGui::GetTextLineHeightWithSpacing() * 1),
|
||||
ImVec2(FCogWindowWidgets::GetFontWidth() * 50, ImGui::GetTextLineHeightWithSpacing() * 60));
|
||||
|
||||
if (ImGui::BeginMenu(TCHAR_TO_ANSI(*MenuItemName)))
|
||||
{
|
||||
RenderContent();
|
||||
ImGui::EndMenu();
|
||||
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
bIsVisible = !bIsVisible;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
bIsVisible = !bIsVisible;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -66,9 +66,6 @@ void UCogWindowManager::Tick(float DeltaTime)
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindowManager::Render(float DeltaTime)
|
||||
{
|
||||
FCogWindowWidgets::TextBaseWidth = ImGui::CalcTextSize("A").x;
|
||||
FCogWindowWidgets::TextBaseHeight = ImGui::GetTextLineHeightWithSpacing();
|
||||
|
||||
ImGui::DockSpaceOverViewport(0, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingInCentralNode);
|
||||
|
||||
bool bCompactSaved = bCompactMode;
|
||||
@@ -272,6 +269,7 @@ void UCogWindowManager::DrawMainMenu()
|
||||
ImGui::Text("DPI Scale");
|
||||
ImGui::SameLine();
|
||||
FCogWindowWidgets::PushStyleCompact();
|
||||
FCogWindowWidgets::SetNextItemToShortWidth();
|
||||
ImGui::SliderFloat("", &DPIScale, 0.5f, 2.0f, "%.1f");
|
||||
if (ImGui::IsItemDeactivatedAfterEdit())
|
||||
{
|
||||
@@ -287,7 +285,15 @@ void UCogWindowManager::DrawMainMenu()
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::MenuItem("Show Window Help", nullptr, &bShowHelp);
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted("Should some help be displayed when the mouse is over a window title ?");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
float FCogWindowWidgets::TextBaseWidth = 0.0f;
|
||||
float FCogWindowWidgets::TextBaseHeight = 0.0f;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogWindowWidgets::BeginTableTooltip()
|
||||
{
|
||||
@@ -196,4 +192,17 @@ void FCogWindowWidgets::PushBackColor(const ImVec4& Color)
|
||||
void FCogWindowWidgets::PopBackColor()
|
||||
{
|
||||
ImGui::PopStyleColor(9);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogWindowWidgets::SetNextItemToShortWidth()
|
||||
{
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 10);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
float FCogWindowWidgets::GetFontWidth()
|
||||
{
|
||||
return ImGui::GetFontSize() * 0.5f;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ protected:
|
||||
|
||||
virtual const FString& GetTitle() const { return Name; }
|
||||
|
||||
virtual void RenderHelp();
|
||||
|
||||
virtual void PreRender(ImGuiWindowFlags& WindowFlags) {}
|
||||
|
||||
virtual void RenderContent() {}
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
|
||||
bool GetCompactMode() const { return bCompactMode; }
|
||||
|
||||
bool GetShowHelp() const { return bShowHelp; }
|
||||
|
||||
private:
|
||||
|
||||
struct FMenu
|
||||
@@ -97,6 +99,9 @@ private:
|
||||
UPROPERTY(Config)
|
||||
float DPIScale = 1.0f;
|
||||
|
||||
UPROPERTY(Config)
|
||||
bool bShowHelp = true;
|
||||
|
||||
TSharedPtr<SCogImguiWidget> ImGuiWidget;
|
||||
|
||||
TWeakObjectPtr<UWorld> World;
|
||||
|
||||
@@ -25,13 +25,13 @@ public:
|
||||
|
||||
static void AddTextWithShadow(ImDrawList* DrawList, const ImVec2& Position, ImU32 Color, const char* TextBegin, const char* TextEnd = NULL);
|
||||
|
||||
static float TextBaseWidth;
|
||||
|
||||
static float TextBaseHeight;
|
||||
|
||||
static void MenuSearchBar(ImGuiTextFilter& Filter);
|
||||
|
||||
static void PushBackColor(const ImVec4& Color);
|
||||
|
||||
static void PopBackColor();
|
||||
|
||||
static void SetNextItemToShortWidth();
|
||||
|
||||
static float GetFontWidth();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user