Skip to content

Commit

Permalink
Update Bui
Browse files Browse the repository at this point in the history
  • Loading branch information
doyaGu committed Jul 8, 2024
1 parent b038592 commit 104898f
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions include/BML/Bui.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ namespace Bui {
bool IsHovered() const { return m_Hovered; }

void SetVisibility(bool visible) {
if (m_Visible != visible)
if (m_Visible != visible) {
m_Visible = visible;
if (m_Visible) {
OnShow();
} else {
OnHide();
}
}
}
void ToggleVisibility() { SetVisibility(!m_Visible); }
void Show() { SetVisibility(true); }
Expand Down Expand Up @@ -155,6 +161,8 @@ namespace Bui {
virtual void OnAfterBegin() {}
virtual void OnDraw() = 0;
virtual void OnEnd() {}
virtual void OnShow() {}
virtual void OnHide() {}

protected:
std::string m_Name;
Expand Down Expand Up @@ -246,39 +254,28 @@ namespace Bui {
}

static bool BackButton(const std::string &label, const ImVec2 &pos = ImVec2(0.4031f, 0.85f)) {
auto oldPos = ImGui::GetCursorScreenPos();
ImGui::SetCursorScreenPos(Bui::CoordToPixel(pos));
bool result = (Bui::BackButton(label.c_str()) || ImGui::IsKeyPressed(ImGuiKey_Escape));
ImGui::SetCursorScreenPos(oldPos);
return result;
return (Bui::BackButton(label.c_str()) || ImGui::IsKeyPressed(ImGuiKey_Escape));
}

static bool LeftButton(const std::string &label, const ImVec2 &pos = ImVec2(0.36f, 0.124f)) {
auto oldPos = ImGui::GetCursorScreenPos();
ImGui::SetCursorScreenPos(Bui::CoordToPixel(pos));
bool result = (Bui::LeftButton(label.c_str()) || ImGui::IsKeyPressed(ImGuiKey_PageUp));
ImGui::SetCursorScreenPos(oldPos);
return result;
return (Bui::LeftButton(label.c_str()) || ImGui::IsKeyPressed(ImGuiKey_PageUp));
}

static bool RightButton(const std::string &label, const ImVec2 &pos = ImVec2(0.6038f, 0.124f)) {
auto oldPos = ImGui::GetCursorScreenPos();
ImGui::SetCursorScreenPos(Bui::CoordToPixel(pos));
bool result = (Bui::RightButton(label.c_str()) || ImGui::IsKeyPressed(ImGuiKey_PageDown));
ImGui::SetCursorScreenPos(oldPos);
return result;
return (Bui::RightButton(label.c_str()) || ImGui::IsKeyPressed(ImGuiKey_PageDown));
}

static void WrappedText(const char *text, float length, float scale = 1.0f) {
if (!text || text[0] == '\0')
return;

float oldPosX = ImGui::GetCursorPosX();

const float width = ImGui::CalcTextSize(text).x;
const float indent = (length - width) * 0.5f;
if (indent > 0) {
ImGui::SetCursorPosX(oldPosX + indent);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + indent);
}

ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + length);
Expand All @@ -295,8 +292,6 @@ namespace Bui {
}

ImGui::PopTextWrapPos();

ImGui::SetCursorPosX(oldPosX);
}

static void DrawCenteredText(const char *text, float y = 0.13f, float scale = 1.5f, ImU32 color = IM_COL32_WHITE) {
Expand Down

0 comments on commit 104898f

Please sign in to comment.