Skip to content

Commit

Permalink
Fix chat scrolling
Browse files Browse the repository at this point in the history
## Also
- Fix ImGui::BeginChild signature (changed in 1.90)
- Add spacing to prevent bottom of a char to be cropped (eg. letter "g")
  • Loading branch information
Deewarz committed Jan 11, 2025
1 parent b4dfb16 commit f4edabe
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions code/client/src/core/ui/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,31 @@ namespace MafiaMP::Core::UI {
void Chat::OnUpdate() {
bool _wasFocused = _isFocused;

if (gApplication->GetInput()->IsKeyPressed(FW_KEY_RETURN) && !_isFocused) {
_isFocused = true;
LockControls(true);
}

ImGui::SetNextWindowSize(ImVec2(400, 300));
ImGui::SetNextWindowPos(ImVec2(20, 20));
ImGui::Begin("Chat", NULL, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Begin("Chat", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

{
ImGui::BeginChild("##scrolling", ImVec2(ImGui::GetWindowWidth() * 0.95f, ImGui::GetWindowHeight() * 0.80f), false, _isFocused ? 0 : ImGuiWindowFlags_NoScrollbar);
ImGui::BeginChild("##messages", ImVec2(ImGui::GetWindowWidth() * 0.95f, ImGui::GetWindowHeight() * 0.80f), 0, _isFocused ? 0 : ImGuiWindowFlags_NoScrollbar);

if (!_chatMessages.empty()) {
for (const auto &msg : _chatMessages) {
ImGui::TextWrapped("%s", msg.c_str());
}
}

ImGui::Spacing();

if (_newMsgArrived) {
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
ImGui::SetScrollHereY(1.0f);
}
ImGui::SetScrollHereY(1.0f);
_newMsgArrived = false;
}

if (gApplication->GetInput()->IsKeyPressed(FW_KEY_RETURN) && !_isFocused) {
_isFocused = true;
LockControls(true);
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
ImGui::SetScrollHereY(1.0f);
}
}

ImGui::EndChild();
}

Expand Down Expand Up @@ -95,10 +92,6 @@ namespace MafiaMP::Core::UI {

_isFocused = false;
LockControls(false);

if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
ImGui::SetScrollHereY(1.0f);
}
}
}

Expand Down

0 comments on commit f4edabe

Please sign in to comment.