Skip to content

Commit

Permalink
improve About dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tope99 committed Dec 23, 2023
1 parent c7033ba commit 7d6f90d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 69 deletions.
137 changes: 74 additions & 63 deletions src/ui_about_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,78 @@ AboutDlg aboutDlg;
void AboutDlg::OpenPopup(std::function<void(ImRad::ModalResult)> clb)
{
callback = clb;
requestClose = false;
ImGui::OpenPopup(ID); // must be called here from current Begin-stack

// Add your init code here
modalResult = ImRad::None;
animator.Start(ImRad::Animator::OpenPopup);
ImGui::OpenPopup(ID);
Init();
}

void AboutDlg::ClosePopup()
void AboutDlg::ClosePopup(ImRad::ModalResult mr)
{
requestClose = true; // CloseCurrentPopup must be called later from our Begin-stack
modalResult = mr;
animator.Start(ImRad::Animator::ClosePopup);
}

void AboutDlg::Draw()
{
/// @style Dark
/// @unit px
/// @begin TopWindow
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
ID = ImGui::GetID("About");
auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;
ID = ImGui::GetID("###AboutDlg");
ImGui::PushStyleColor(ImGuiCol_PopupBg, ImGui::GetStyleColorVec4(ImGuiCol_TitleBgActive));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 10, 10 });
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 10, 7 });
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), 0, { 0.5f, 0.5f }); //Center
ImGui::SetNextWindowSize({ 0, 0 });
bool tmpOpen = true;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0, 0 });
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 10, 7 });
if (ImGui::BeginPopupModal("About", &tmpOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize))
if (ImGui::BeginPopupModal("About###AboutDlg", &tmpOpen, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize))
{
if (requestClose) ImGui::CloseCurrentPopup();
if (modalResult != ImRad::None)
{
ImGui::CloseCurrentPopup();
if (modalResult != ImRad::Cancel) callback(modalResult);
}
/// @separator

/// @begin Child
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyle().Colors[ImGuiCol_TitleBgActive]);
ImGui::BeginChild("child", { -1, 50 });
{
/// @begin Text
ImGui::Indent(1 * ImGui::GetStyle().ItemSpacing.x);
ImGui::Spacing();
ImGui::PushFont(ImRad::GetFontByName("imrad.H1"));
ImGui::TextUnformatted(VER_STR.c_str());
ImGui::PopFont();
/// @end Text

/// @separator
ImGui::EndChild();
}
ImGui::PopStyleColor();
/// @end Child
// TODO: Add Draw calls of dependent popup windows here

/// @begin Text
ImRad::Spacing(1);
ImGui::Indent(1 * ImGui::GetStyle().IndentSpacing / 2);
ImGui::PushFont(ImRad::GetFontByName("imrad.H1"));
ImGui::TextUnformatted(ImRad::Format("{}", VER_STR).c_str());
ImGui::PopFont();
/// @end Text

/// @begin Text
ImGui::Indent(1 * ImGui::GetStyle().ItemSpacing.x);
ImGui::Spacing();
ImGui::TextUnformatted("visit");
ImGui::TextUnformatted(ImRad::Format("build with ImGui {}", IMGUI_VERSION).c_str());
/// @end Text

/// @begin Text
ImGui::SameLine(0, 0.5f * ImGui::GetStyle().ItemSpacing.x);
ImGui::PushStyleColor(ImGuiCol_Text, 0xffff9018);
ImGui::TextUnformatted(GITHUB_URL.c_str());
ImRad::Spacing(2);
ImGui::PushStyleColor(ImGuiCol_Text, 0xffff6633);
ImGui::TextUnformatted(ImRad::Format("{}", GITHUB_URL).c_str());
ImGui::PopStyleColor();
if (ImGui::IsItemHovered())
ImGui::SetMouseCursor(7);
if (ImGui::IsItemClicked())
OpenURL();
/// @end Text

/// @begin Child
ImGui::SameLine();
ImGui::BeginChild("child1725042201601", { ImGui::GetStyle().ItemSpacing.x, 10 }, false);
{
/// @separator
/// @begin Child
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);
ImGui::BeginChild("child1", { ImGui::GetStyle().ItemSpacing.x, 10 }, ImGuiChildFlags_None, ImGuiWindowFlags_NoSavedSettings);
{
/// @separator

/// @separator
ImGui::EndChild();
}
/// @end Child
/// @separator
ImGui::EndChild();
}
/// @end Child

/// @begin Child
ImGui::BeginChild("child1725042201600", { -100, 10 }, false);
ImGui::BeginChild("child2", { -100, 10 }, ImGuiChildFlags_None, ImGuiWindowFlags_NoSavedSettings);
{
/// @separator

Expand All @@ -90,30 +89,37 @@ void AboutDlg::Draw()
}
/// @end Child

/// @begin Button
ImGui::SetCursorPosX(10 + (ImGui::GetContentRegionAvail().x - 120) / 2);
if (ImGui::Button("OK", { 120, 35 }) ||
ImGui::IsKeyPressed(ImGuiKey_Escape))
/// @begin Table
if (ImGui::BeginTable("table3", 3, ImGuiTableFlags_NoPadOuterX | ImGuiTableFlags_NoPadInnerX, { 0, 0 }))
{
ClosePopup();
callback(ImRad::Ok);
}
/// @end Button
ImGui::TableSetupColumn("left-stretch", ImGuiTableColumnFlags_WidthStretch, 0);
ImGui::TableSetupColumn("content", ImGuiTableColumnFlags_WidthFixed, 0);
ImGui::TableSetupColumn("right-stretch", ImGuiTableColumnFlags_WidthStretch, 0);
ImGui::TableNextRow(0, 0);
ImGui::TableSetColumnIndex(0);
/// @separator

/// @begin Button
ImRad::TableNextColumn(1);
if (ImGui::Button("OK", { 100, 32 }) ||
(!ImRad::IsItemDisabled() && ImGui::IsKeyPressed(ImGuiKey_Escape, false)))
{
ClosePopup(ImRad::Ok);
}
/// @end Button

/// @begin Child
ImGui::BeginChild("child1725042201609", { 10, ImGui::GetStyle().ItemSpacing.y }, false);
{
/// @separator

/// @separator
ImGui::EndChild();
}
/// @end Child
/// @separator
ImGui::EndTable();
}
/// @end Table

/// @separator
ImGui::EndPopup();
}
ImGui::PopStyleVar(2);
ImGui::PopStyleVar();
ImGui::PopStyleVar();
ImGui::PopStyleColor();
/// @end TopWindow
}

Expand All @@ -122,3 +128,8 @@ void AboutDlg::OpenURL()
{
ShellExec(GITHUB_URL);
}

void AboutDlg::Init()
{
// TODO: Add your code here
}
16 changes: 10 additions & 6 deletions src/ui_about_dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
class AboutDlg
{
public:
/// @interface
/// @begin interface
void OpenPopup(std::function<void(ImRad::ModalResult)> clb = [](ImRad::ModalResult){});
void ClosePopup();
void ClosePopup(ImRad::ModalResult mr);
void Draw();

void OpenURL();
/// @end interface

private:
/// @impl
void OpenURL();
/// @begin impl
void Init();

ImGuiID ID;
bool requestClose = false;
ImGuiID ID = 0;
ImRad::ModalResult modalResult;
ImRad::Animator animator;
std::function<void(ImRad::ModalResult)> callback;

/// @end impl
};

extern AboutDlg aboutDlg;

0 comments on commit 7d6f90d

Please sign in to comment.