From 5c4bb7833dac48289d495941deaf8d435ae29e8d Mon Sep 17 00:00:00 2001 From: Aman Menda Date: Mon, 6 May 2024 22:59:53 +0100 Subject: [PATCH] feat: render username input box --- include/UI/HomePage.hpp | 4 ++++ src/UI/HomePage.cpp | 46 ++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/UI/HomePage.hpp b/include/UI/HomePage.hpp index f0acce4..6d6f2a5 100644 --- a/include/UI/HomePage.hpp +++ b/include/UI/HomePage.hpp @@ -36,6 +36,10 @@ namespace Stuckfish void Update(void); void RenderPopup(void); + void RenderChessBoard(void); + void RenderUsernameInputBox(bool isDisabled); + void RenderGameReview(void); + private: Core& _app; HomePageEvent _event; diff --git a/src/UI/HomePage.cpp b/src/UI/HomePage.cpp index ce1984c..54c2170 100644 --- a/src/UI/HomePage.cpp +++ b/src/UI/HomePage.cpp @@ -51,7 +51,6 @@ void HomePage::Render(void) _event = (_event != HomePageEvent::ON_GAME_SELECTION) ? HomePageEvent::NONE : _event; - ImVec2 buttonSize(confirmButtonSizeX, confirmButtonSizeY); ImGui::SetNextWindowPos(ImVec2(0, 0)); ImGui::SetNextWindowSize(ImVec2(_app.specs.width, _app.specs.height)); @@ -60,33 +59,11 @@ void HomePage::Render(void) ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoSavedSettings); - ImVec2 contentRegion = ImGui::GetContentRegionAvail(); - ImVec2 windowMiddlePos = ImVec2(contentRegion.x / 2.0f, contentRegion.y / 2.0f); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, roundingValue); - - // page title - ImGui::PushFont(_app.robotoFontHeader); - ImGui::SetCursorPos(ImVec2(windowMiddlePos.x - 225, windowMiddlePos.y - 140)); - ImGui::Text("Please provide your Chess.com username"); - ImGui::PopFont(); + RenderUsernameInputBox(isDisabled); - // input field - ImGui::SetCursorPos(ImVec2(windowMiddlePos.x - 200, windowMiddlePos.y - 90)); - ImGui::SetNextItemWidth(inputFieldWidth); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 10.0f)); - ImGui::InputTextWithHint("##input", "Chess.com username...", &_userData->username); - ImGui::PopStyleVar(); - - ImGui::SetCursorPos(ImVec2(windowMiddlePos.x - (buttonSize.x / 2.0f), windowMiddlePos.y - 40)); - if (ImGui::Button(ButtonsToString(Buttons::CONFIRM), buttonSize) && !isDisabled) { - _event = HomePageEvent::ON_USERNAME_SUBMITTED; - } - if (_event == HomePageEvent::ON_GAME_SELECTION) RenderPopup(); - ImGui::PopStyleVar(); ImGui::End(); } @@ -189,4 +166,25 @@ void HomePage::RenderPopup(void) ImGui::End(); } +void HomePage::RenderUsernameInputBox(bool isDisabled) +{ + ImVec2 contentRegion = ImGui::GetContentRegionAvail(); + ImVec2 windowMiddlePos = ImVec2(contentRegion.x / 2.0f, contentRegion.y / 2.0f); + ImVec2 buttonSize(confirmButtonSizeX, confirmButtonSizeY); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, roundingValue); + ImGui::SetCursorPos(ImVec2(windowMiddlePos.x - 200, windowMiddlePos.y - 90)); + ImGui::SetNextItemWidth(inputFieldWidth); + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 10.0f)); + ImGui::InputTextWithHint("##input", "Chess.com username...", &_userData->username); + ImGui::PopStyleVar(); + + ImGui::SetCursorPos(ImVec2(windowMiddlePos.x - (buttonSize.x / 2.0f), windowMiddlePos.y - 40)); + if (ImGui::Button(ButtonsToString(Buttons::CONFIRM), buttonSize) && !isDisabled) { + _event = HomePageEvent::ON_USERNAME_SUBMITTED; + } + ImGui::PopStyleVar(); +} + } \ No newline at end of file