Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[glass] Replace View with immediate mode #7253

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 52 additions & 50 deletions glass/src/app/native/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "glass/Context.h"
#include "glass/MainMenuBar.h"
#include "glass/Storage.h"
#include "glass/View.h"
#include "glass/Window.h"
#include "glass/networktables/NetworkTables.h"
#include "glass/networktables/NetworkTablesProvider.h"
#include "glass/networktables/NetworkTablesSettings.h"
Expand All @@ -43,10 +43,10 @@ static std::unique_ptr<glass::NetworkTablesProvider> gNtProvider;
static std::unique_ptr<glass::NetworkTablesModel> gNetworkTablesModel;
static std::unique_ptr<glass::NetworkTablesSettings> gNetworkTablesSettings;
static glass::LogData gNetworkTablesLog;
static std::unique_ptr<glass::Window> gNetworkTablesWindow;
static std::unique_ptr<glass::Window> gNetworkTablesInfoWindow;
static std::unique_ptr<glass::Window> gNetworkTablesSettingsWindow;
static std::unique_ptr<glass::Window> gNetworkTablesLogWindow;
static glass::Window* gNetworkTablesWindow;
static glass::Window* gNetworkTablesInfoWindow;
static glass::Window* gNetworkTablesSettingsWindow;
static glass::Window* gNetworkTablesLogWindow;

static glass::MainMenuBar gMainMenu;
static bool gAbout = false;
Expand Down Expand Up @@ -134,55 +134,34 @@ static void NtInitialize() {
}
});

gNetworkTablesLogWindow = std::make_unique<glass::Window>(
glass::GetStorageRoot().GetChild("NetworkTables Log"),
"NetworkTables Log", glass::Window::kHide);
gNetworkTablesLogWindow->SetView(
std::make_unique<glass::LogView>(&gNetworkTablesLog));
gNetworkTablesLogWindow = glass::imm::CreateWindow("NetworkTables Log", false,
glass::Window::kHide);
gNetworkTablesLogWindow->SetDefaultPos(250, 615);
gNetworkTablesLogWindow->SetDefaultSize(600, 130);
gNetworkTablesLogWindow->DisableRenamePopup();
gui::AddLateExecute([] { gNetworkTablesLogWindow->Display(); });

// NetworkTables table window
gNetworkTablesModel = std::make_unique<glass::NetworkTablesModel>();
gui::AddEarlyExecute([] { gNetworkTablesModel->Update(); });

gNetworkTablesWindow = std::make_unique<glass::Window>(
glass::GetStorageRoot().GetChild("NetworkTables View"), "NetworkTables");
gNetworkTablesWindow->SetView(
std::make_unique<glass::NetworkTablesView>(gNetworkTablesModel.get()));
gNetworkTablesWindow = glass::imm::CreateWindow("NetworkTables View");
gNetworkTablesWindow->SetDefaultPos(250, 277);
gNetworkTablesWindow->SetDefaultSize(750, 185);
gNetworkTablesWindow->DisableRenamePopup();
gui::AddLateExecute([] { gNetworkTablesWindow->Display(); });

// NetworkTables info window
gNetworkTablesInfoWindow = std::make_unique<glass::Window>(
glass::GetStorageRoot().GetChild("NetworkTables Info"),
"NetworkTables Info");
gNetworkTablesInfoWindow->SetView(glass::MakeFunctionView(
[&] { glass::DisplayNetworkTablesInfo(gNetworkTablesModel.get()); }));
gNetworkTablesInfoWindow = glass::imm::CreateWindow(
"NetworkTables Info", false, glass::Window::kHide);
gNetworkTablesInfoWindow->SetDefaultPos(250, 130);
gNetworkTablesInfoWindow->SetDefaultSize(750, 145);
gNetworkTablesInfoWindow->SetDefaultVisibility(glass::Window::kHide);
gNetworkTablesInfoWindow->DisableRenamePopup();
gui::AddLateExecute([] { gNetworkTablesInfoWindow->Display(); });

// NetworkTables settings window
gNetworkTablesSettings = std::make_unique<glass::NetworkTablesSettings>(
"glass", glass::GetStorageRoot().GetChild("NetworkTables Settings"));
gui::AddEarlyExecute([] { gNetworkTablesSettings->Update(); });

gNetworkTablesSettingsWindow = std::make_unique<glass::Window>(
glass::GetStorageRoot().GetChild("NetworkTables Settings"),
"NetworkTables Settings");
gNetworkTablesSettingsWindow->SetView(
glass::MakeFunctionView([] { gNetworkTablesSettings->Display(); }));
gNetworkTablesSettingsWindow =
glass::imm::CreateWindow("NetworkTables Settings");
gNetworkTablesSettingsWindow->SetDefaultPos(30, 30);
gNetworkTablesSettingsWindow->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
gNetworkTablesSettingsWindow->DisableRenamePopup();
gui::AddLateExecute([] { gNetworkTablesSettingsWindow->Display(); });

gui::AddWindowScaler([](float scale) {
// scale default window positions
Expand Down Expand Up @@ -236,8 +215,6 @@ int main(int argc, char** argv) {

glass::AddStandardNetworkTablesViews(*gNtProvider);

gui::AddLateExecute([] { gMainMenu.Display(); });

gMainMenu.AddMainMenu([] {
if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Set Enter Key")) {
Expand All @@ -249,18 +226,10 @@ int main(int argc, char** argv) {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("NetworkTables")) {
if (gNetworkTablesSettingsWindow) {
gNetworkTablesSettingsWindow->DisplayMenuItem("NetworkTables Settings");
}
if (gNetworkTablesWindow) {
gNetworkTablesWindow->DisplayMenuItem("NetworkTables View");
}
if (gNetworkTablesInfoWindow) {
gNetworkTablesInfoWindow->DisplayMenuItem("NetworkTables Info");
}
if (gNetworkTablesLogWindow) {
gNetworkTablesLogWindow->DisplayMenuItem("NetworkTables Log");
}
gNetworkTablesSettingsWindow->DisplayMenuItem("NetworkTables Settings");
gNetworkTablesWindow->DisplayMenuItem("NetworkTables View");
gNetworkTablesInfoWindow->DisplayMenuItem("NetworkTables Info");
gNetworkTablesLogWindow->DisplayMenuItem("NetworkTables Log");
ImGui::MenuItem("NetworkTables Debug Logging", nullptr,
&gNetworkTablesDebugLog);
ImGui::Separator();
Expand Down Expand Up @@ -295,6 +264,42 @@ int main(int argc, char** argv) {
});

gui::AddLateExecute([] {
gMainMenu.Display();

if (glass::imm::BeginWindow(gNetworkTablesLogWindow)) {
auto& settings = glass::GetStorage().GetOrNewData<glass::LogSettings>(
&gNetworkTablesLog);
if (glass::imm::BeginWindowSettingsPopup()) {
settings.DisplayMenu();
ImGui::EndPopup();
}
glass::DisplayLog(&gNetworkTablesLog, settings.IsAutoScroll());
}
glass::imm::EndWindow();

if (glass::imm::BeginWindow(gNetworkTablesWindow)) {
auto& settings =
glass::GetStorage().GetOrNewData<glass::NetworkTablesFlagsSettings>();
if (glass::imm::BeginWindowSettingsPopup()) {
settings.DisplayMenu();
glass::DisplayNetworkTablesAddMenu(gNetworkTablesModel.get(), {},
settings.GetFlags());
ImGui::EndPopup();
}
DisplayNetworkTables(gNetworkTablesModel.get(), settings.GetFlags());
}
glass::imm::EndWindow();

if (glass::imm::BeginWindow(gNetworkTablesInfoWindow)) {
glass::DisplayNetworkTablesInfo(gNetworkTablesModel.get());
}
glass::imm::EndWindow();

if (glass::imm::BeginWindow(gNetworkTablesSettingsWindow)) {
gNetworkTablesSettings->Display();
}
glass::imm::EndWindow();

if (gAbout) {
ImGui::OpenPopup("About");
gAbout = false;
Expand Down Expand Up @@ -359,9 +364,6 @@ int main(int argc, char** argv) {
}
gui::Main();

gNetworkTablesSettingsWindow.reset();
gNetworkTablesLogWindow.reset();
gNetworkTablesWindow.reset();
gNetworkTablesModel.reset();
gNtProvider.reset();
gPlotProvider.reset();
Expand Down
12 changes: 12 additions & 0 deletions glass/src/lib/native/cpp/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@

#include "glass/Model.h"

#include "glass/ContextInternal.h"

using namespace glass;

bool Model::IsReadOnly() {
return false;
}

Model* glass::AddModel(std::unique_ptr<Model> model) {
return gContext->models.emplace_back(std::move(model)).get();
}

void glass::UpdateModels() {
for (auto&& model : gContext->models) {
model->Update();
}
}
Loading
Loading