Skip to content

Commit

Permalink
toolbar for browser window: refresh, login, logout, upload
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Jul 31, 2022
1 parent e2154bf commit 43b43ab
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
63 changes: 52 additions & 11 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "Viewport.h"
#include "TemporalControlWindow.h"
#include "MessageDialog.h"
#include "LoginDialog.h"
#include "UploadSimulationDialog.h"

_BrowserWindow::_BrowserWindow(
SimulationController const& simController,
Expand All @@ -42,6 +44,12 @@ _BrowserWindow::~_BrowserWindow()
_on = false;
}

void _BrowserWindow::registerCyclicReferences(LoginDialogWeakPtr const& loginDialog, UploadSimulationDialogWeakPtr const& uploadSimulationDialog)
{
_loginDialog = loginDialog;
_uploadSimulationDialog = uploadSimulationDialog;
}

void _BrowserWindow::onRefresh()
{
refreshIntern(false);
Expand Down Expand Up @@ -77,23 +85,63 @@ void _BrowserWindow::refreshIntern(bool firstTimeStartup)

void _BrowserWindow::processIntern()
{
processToolbar();
processTable();
processStatus();
processFilter();
processRefreshButton();
if(_scheduleRefresh) {
onRefresh();
_scheduleRefresh = false;
}
}

void _BrowserWindow::processToolbar()
{
if (AlienImGui::ToolbarButton(ICON_FA_SYNC)) {
onRefresh();
}
AlienImGui::Tooltip("Refresh");

ImGui::SameLine();
ImGui::BeginDisabled(_networkController->getLoggedInUserName().has_value());
if (AlienImGui::ToolbarButton(ICON_FA_SIGN_IN_ALT)) {
if (auto loginDialog = _loginDialog.lock()) {
loginDialog->show();
}
}
ImGui::EndDisabled();
AlienImGui::Tooltip("Login or register");

ImGui::SameLine();
ImGui::BeginDisabled(!_networkController->getLoggedInUserName());
if (AlienImGui::ToolbarButton(ICON_FA_SIGN_OUT_ALT)) {
if (auto loginDialog = _loginDialog.lock()) {
_networkController->logout();
onRefresh();
}
}
ImGui::EndDisabled();
AlienImGui::Tooltip("Logout");

ImGui::SameLine();
ImGui::BeginDisabled(!_networkController->getLoggedInUserName());
if (AlienImGui::ToolbarButton(ICON_FA_UPLOAD)) {
if (auto uploadSimulationDialog = _uploadSimulationDialog.lock()) {
uploadSimulationDialog->show();
}
}
ImGui::EndDisabled();
AlienImGui::Tooltip("Upload simulation");
AlienImGui::Separator();
}

void _BrowserWindow::processTable()
{
auto styleRepository = StyleRepository::getInstance();
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable
| ImGuiTableFlags_SortMulti | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody
| ImGuiTableFlags_ScrollY;
if (ImGui::BeginTable("Browser", 12, flags, ImVec2(0, ImGui::GetContentRegionAvail().y - styleRepository.scaleContent(90.0f)), 0.0f)) {
if (ImGui::BeginTable("Browser", 12, flags, ImVec2(0, ImGui::GetContentRegionAvail().y - styleRepository.scaleContent(63.0f)), 0.0f)) {
ImGui::TableSetupColumn(
"Actions", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthFixed, 0.0f, RemoteSimulationDataColumnId_Actions);
ImGui::TableSetupColumn(
Expand Down Expand Up @@ -150,7 +198,7 @@ void _BrowserWindow::processTable()
ImGui::TableNextRow();

ImGui::TableNextColumn();
if (ImGui::Button(ICON_FA_FOLDER_OPEN)) {
if (ImGui::Button(ICON_FA_DOWNLOAD)) {
onOpenSimulation(item->id);
}
ImGui::SameLine();
Expand Down Expand Up @@ -217,7 +265,7 @@ void _BrowserWindow::processStatus()
{
auto styleRepository = StyleRepository::getInstance();

if (ImGui::BeginChild("##", ImVec2(0, styleRepository.scaleContent(30.0f)), true, ImGuiWindowFlags_HorizontalScrollbar)) {
if (ImGui::BeginChild("##", ImVec2(0, styleRepository.scaleContent(33.0f)), true, ImGuiWindowFlags_HorizontalScrollbar)) {
ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)Const::LogMessageColor);
std::string statusText;
statusText += std::string(" " ICON_FA_INFO_CIRCLE " ");
Expand Down Expand Up @@ -252,13 +300,6 @@ void _BrowserWindow::processFilter()
}
}

void _BrowserWindow::processRefreshButton()
{
if (AlienImGui::Button("Refresh")) {
onRefresh();
}
}

void _BrowserWindow::processShortenedText(std::string const& text) {
auto styleRepository = StyleRepository::getInstance();
auto textSize = ImGui::CalcTextSize(text.c_str());
Expand Down
6 changes: 5 additions & 1 deletion source/Gui/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class _BrowserWindow : public _AlienWindow
TemporalControlWindow const& temporalControlWindow);
~_BrowserWindow();

void registerCyclicReferences(LoginDialogWeakPtr const& loginDialog, UploadSimulationDialogWeakPtr const& uploadSimulationDialog);

void onRefresh();

private:
Expand All @@ -27,7 +29,7 @@ class _BrowserWindow : public _AlienWindow
void processTable();
void processStatus();
void processFilter();
void processRefreshButton();
void processToolbar();
void processShortenedText(std::string const& text);
bool processDetailButton();

Expand Down Expand Up @@ -56,4 +58,6 @@ class _BrowserWindow : public _AlienWindow
StatisticsWindow _statisticsWindow;
Viewport _viewport;
TemporalControlWindow _temporalControlWindow;
LoginDialogWeakPtr _loginDialog;
UploadSimulationDialogWeakPtr _uploadSimulationDialog;
};
2 changes: 2 additions & 0 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ using NetworkController = std::shared_ptr<_NetworkController>;

class _LoginDialog;
using LoginDialog = std::shared_ptr<_LoginDialog>;
using LoginDialogWeakPtr = std::weak_ptr<_LoginDialog>;

class _UploadSimulationDialog;
using UploadSimulationDialog = std::shared_ptr<_UploadSimulationDialog>;
using UploadSimulationDialogWeakPtr = std::weak_ptr<_UploadSimulationDialog>;

class _CreateUserDialog;
using CreateUserDialog = std::shared_ptr<_CreateUserDialog>;
Expand Down
2 changes: 1 addition & 1 deletion source/Gui/LoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _LoginDialog::_LoginDialog(

{
auto& settings = GlobalSettings::getInstance();
_remember = settings.getBoolState("dialogs.login.remember", false);
_remember = settings.getBoolState("dialogs.login.remember", true);
if (_remember) {
settings.getStringState("dialogs.login.user name", "");
settings.getStringState("dialogs.login.password", "");
Expand Down
3 changes: 3 additions & 0 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ _MainWindow::_MainWindow(SimulationController const& simController, SimpleLogger
_networkSettingsDialog = std::make_shared<_NetworkSettingsDialog>(_browserWindow, _networkController);
_imageToPatternDialog = std::make_shared<_ImageToPatternDialog>(_viewport, _simController);

//cyclic references
_browserWindow->registerCyclicReferences(_loginDialog, _uploadSimulationDialog);

ifd::FileDialog::Instance().CreateTexture = [](uint8_t* data, int w, int h, char fmt) -> void* {
GLuint tex;

Expand Down

0 comments on commit 43b43ab

Please sign in to comment.