Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
fix modern theme a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Mar 20, 2024
1 parent 9fff10b commit 745e23b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
30 changes: 22 additions & 8 deletions src/shared/gui/themes/modern/modern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ namespace openhack::gui {
}

bool ModernTheme::inputFloat(const char *label, float *value, float min, float max, const char *format) {
// Transparent background with a line border on the bottom
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(0, 0, 0, 0));
Expand All @@ -82,15 +81,30 @@ namespace openhack::gui {

auto color = config::get<Color>("menu.color.primary");
color.a = 0.4f;
drawList->AddLine(ImVec2(cursorPos.x, cursorPos.y + 20), ImVec2(cursorPos.x + availWidth, cursorPos.y + 20), color);
bool changed = ImGui::InputFloat(label, value, 0.0f, 0.0f, format);

auto scale = config::getGlobal<float>("UIScale");
drawList->AddLine(ImVec2(cursorPos.x, cursorPos.y + 24 * scale), ImVec2(cursorPos.x + availWidth, cursorPos.y + 24 * scale), color);
bool changed = Theme::inputFloat(label, value, min, max, format);
ImGui::PopStyleColor(3);
return changed;
}

bool ModernTheme::inputText(const char *label, std::string *value, int bufferSize, const char *placeholder, ImGuiTextFlags flags) {
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(0, 0, 0, 0));

// Add a line border on the bottom
auto drawList = ImGui::GetWindowDrawList();
auto cursorPos = ImGui::GetCursorScreenPos();
auto availWidth = ImGui::CalcItemWidth();

if (*value < min)
*value = min;
if (*value > max)
*value = max;
auto color = config::get<Color>("menu.color.primary");
color.a = 0.4f;
auto scale = config::getGlobal<float>("UIScale");
drawList->AddLine(ImVec2(cursorPos.x, cursorPos.y + 24 * scale), ImVec2(cursorPos.x + availWidth, cursorPos.y + 24 * scale), color);
bool changed = Theme::inputText(label, value, bufferSize, placeholder, flags);
ImGui::PopStyleColor(5);
ImGui::PopStyleVar();
return changed;
}

Expand Down
2 changes: 2 additions & 0 deletions src/shared/gui/themes/modern/modern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace openhack::gui {

void loadPalette() override;

bool inputText(const char *label, std::string *value, int bufferSize, const char *placeholder, ImGuiTextFlags flags) override;

bool inputFloat(const char *label, float *value, float min, float max, const char *format) override;

bool button(const char *label, const ImVec2 &size) override;
Expand Down
8 changes: 4 additions & 4 deletions src/shared/gui/themes/themes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ namespace openhack::gui
{
/// @brief Classic ImGui theme.
Classic = 0,
/// @brief Modern UI theme.
Modern = 1,
/// @brief Theme based on the MegaHack v8
MegaHack = 2,
MegaHack = 1,
/// @brief Modern UI theme.
Modern = 2,
};

/// @brief The names of the themes.
const char *const THEME_NAMES[] = {
"Classic",
"Modern",
"MegaHack",
"Modern",
};

/// @brief The count of the themes.
Expand Down

0 comments on commit 745e23b

Please sign in to comment.