Skip to content

Commit

Permalink
feat: render username input box
Browse files Browse the repository at this point in the history
  • Loading branch information
AmanMenda committed May 6, 2024
1 parent ec56603 commit 5c4bb78
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
4 changes: 4 additions & 0 deletions include/UI/HomePage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 22 additions & 24 deletions src/UI/HomePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

}

0 comments on commit 5c4bb78

Please sign in to comment.