GUI
This commit is contained in:
parent
b3d06906ff
commit
b0d5226915
7 changed files with 317 additions and 52 deletions
|
|
@ -1,46 +1,89 @@
|
|||
|
||||
#include "ClientGui.hpp"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
using namespace tp;
|
||||
using namespace ImGui;
|
||||
|
||||
void ClientGUI::draw(ChatAPI& api) {
|
||||
DockSpaceOverViewport(GetWindowViewport());
|
||||
|
||||
if (Begin("window_name")) {
|
||||
if (api.isLogged()) {
|
||||
drawChat(api);
|
||||
|
||||
if (api.isLogged()) {
|
||||
} else {
|
||||
if (Begin("Authentication")) {
|
||||
InputText("Name", mCredentials.name, ChatAPI::Credentials::SIZE);
|
||||
InputText("Pass", mCredentials.pass, ChatAPI::Credentials::SIZE);
|
||||
|
||||
static int item_current1 = 0;
|
||||
const char *items1[] = {"Never", "Gonna", "Give", "You", "Up"};
|
||||
Combo("User", &item_current1, items1, IM_ARRAYSIZE(items1));
|
||||
if (mInvalidCredentials) {
|
||||
Text("Invalid Credentials");
|
||||
}
|
||||
|
||||
BeginListBox("History");
|
||||
Text("as");
|
||||
Text("asa");
|
||||
EndListBox();
|
||||
if (Button("Login")) {
|
||||
api.login(mCredentials);
|
||||
mInvalidCredentials = !api.isLogged();
|
||||
}
|
||||
}
|
||||
End();
|
||||
}
|
||||
}
|
||||
|
||||
static char buff[1000];
|
||||
InputTextMultiline("Message", buff, 1000);
|
||||
void ClientGUI::drawChat(tp::ChatAPI& api) {
|
||||
if (Begin("Chats")) {
|
||||
if (Button("Logout", {GetContentRegionAvail().x, 0})) {
|
||||
api.logout();
|
||||
mCredentials.pass[0] = 0;
|
||||
mActiveChatName = "Not Selected";
|
||||
}
|
||||
|
||||
if (Button("Send")) {
|
||||
if (BeginListBox("##chats", GetContentRegionAvail())) {
|
||||
auto chats = api.getChatsList();
|
||||
if (chats) {
|
||||
for (auto user : *chats) {
|
||||
if (Selectable(user->read())) {
|
||||
mActiveChatName = user.data();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text("Error");
|
||||
}
|
||||
|
||||
}
|
||||
EndListBox();
|
||||
}
|
||||
}
|
||||
End();
|
||||
|
||||
} else {
|
||||
if (Begin("History")) {
|
||||
Text("%s", mActiveChatName.read());
|
||||
|
||||
InputText("Name", mCredentials.name, ChatAPI::Credentials::SIZE);
|
||||
InputText("Pass", mCredentials.pass, ChatAPI::Credentials::SIZE);
|
||||
auto history = api.getChatHistory(mActiveChatName);
|
||||
|
||||
if (mInvalidCredentials) {
|
||||
Text("Invalid Credentials");
|
||||
}
|
||||
if (history) {
|
||||
if (BeginListBox("##History", GetContentRegionAvail())) {
|
||||
for (auto message : *history) {
|
||||
Text("%s : %s", message->user.read(), message->text.read());
|
||||
Separator();
|
||||
}
|
||||
}
|
||||
|
||||
if (Button("Login")) {
|
||||
api.login(mCredentials);
|
||||
mInvalidCredentials = !api.isLogged();
|
||||
}
|
||||
}
|
||||
EndListBox();
|
||||
} else {
|
||||
Text("No History");
|
||||
}
|
||||
}
|
||||
End();
|
||||
|
||||
} End();
|
||||
}
|
||||
if (Begin("Message")) {
|
||||
if (Button("Send")) {
|
||||
if (String::Logic::calcLength(mMessageBuff) > 0) {
|
||||
api.send(mActiveChatName, {mCredentials.name, mMessageBuff});
|
||||
}
|
||||
mMessageBuff[0] = 0;
|
||||
}
|
||||
|
||||
InputTextMultiline("##Message", mMessageBuff, MESSAGE_SIZE, GetContentRegionAvail());
|
||||
}
|
||||
End();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue