Skip to content

Commit

Permalink
Improved project manager
Browse files Browse the repository at this point in the history
  • Loading branch information
muit committed Feb 7, 2024
1 parent 21d15f7 commit 8beebf1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 59 deletions.
126 changes: 67 additions & 59 deletions Libs/Editor/Src/Utils/ProjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,87 @@

namespace rift::Editor
{
void TextCentered(const char* text)
{
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text).x;

ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text);
}

void DrawProjectManager(ast::Tree& ast)
{
// Center modal when appearing
UI::SetNextWindowPos(UI::GetMainViewport()->GetCenter(), ImGuiCond_Always, {0.5f, 0.5f});

p::v2 viewportSize = UI::GetMainViewport()->Size;
p::v2 modalSize = p::v2{600.f, 400.f};
p::v2 modalSize = p::v2{600.f, 0.f};
modalSize.x = p::Min(modalSize.x, viewportSize.x - 20.f);
modalSize.y = p::Min(modalSize.y, viewportSize.y - 20.f);

UI::SetNextWindowSize(modalSize, ImGuiCond_Always);

if (UI::BeginPopupModal("Project Manager", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize))
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize))
{
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
UI::Text("Projects");
UI::PushFont("WorkSans", UI::FontMode::Regular, 24.f);
TextCentered("Projects");
UI::PopFont();
UI::Separator();

UI::Spacing();
UI::Spacing();

static p::String folder;

ImGui::BeginTable("table", 2);
ImGui::TableNextColumn();
{
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
UI::Text("Open");
UI::PopFont();
UI::Separator();
UI::Spacing();

UI::SetItemDefaultFocus();
{
UI::Text("Recent projects:");
static const char* recentProjects[]{"Project.rift"};
static int selectedN = 0;
UI::SetNextItemWidth(-FLT_MIN);

for (int n = 0; n < IM_ARRAYSIZE(recentProjects); ++n)
{
const bool isSelected = (selectedN == n);
UI::BulletText(recentProjects[n]);
UI::SameLine(ImGui::GetContentRegionAvail().x - 30.f);
if (UI::SmallButton("open")) {}
}
}
UI::Dummy({10.f, 40.f});
}
ImGui::TableNextColumn();
{
UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
UI::Text("Create");
UI::PopFont();
UI::Separator();
UI::Spacing();

UI::PushItemWidth(-32.f);
UI::InputTextWithHint("##path", "project path...", folder);
UI::PopItemWidth();
UI::SameLine();
if (UI::Button("...", p::v2{24.f, 0.f}))
{
p::Path selectedFolder =
p::files::SelectFolderDialog("Select project folder", p::GetCurrentPath());
folder = p::ToString(selectedFolder);
}
}

ImGui::TableNextRow();
ImGui::TableNextColumn();
if (UI::Button("Open", p::v2{-FLT_MIN, 0.0f}))
{
p::String folder =
Expand All @@ -45,60 +105,7 @@ namespace rift::Editor
p::Strings::Format("Failed to open project at '{}'", p::ToString(folder))});
}
}
UI::SetItemDefaultFocus();
{
UI::Text("Recent Projects");
static const char* recentProjects[]{"One recent project"};
static int selectedN = 0;
UI::SetNextItemWidth(-FLT_MIN);
if (UI::BeginListBox("##RecentProjects"))
{
for (int n = 0; n < IM_ARRAYSIZE(recentProjects); ++n)
{
const bool isSelected = (selectedN == n);
if (UI::Selectable(recentProjects[n], isSelected))
{
selectedN = n;
}

// Set the initial focus when opening the combo (scrolling + keyboard
// navigation focus)
if (isSelected)
{
UI::SetItemDefaultFocus();
}
}
UI::EndListBox();
}
}


UI::Spacing();
UI::Spacing();
UI::Spacing();
UI::Spacing();

UI::PushFont("WorkSans", UI::FontMode::Regular, 18.f);
UI::Text("New");
UI::PopFont();
UI::Separator();
UI::Spacing();

UI::AlignTextToFramePadding();
UI::Text("Destination");
UI::SameLine();
static p::String folder;
UI::PushItemWidth(-32.f);
UI::InputText("##path", folder);
UI::PopItemWidth();
UI::SameLine();
if (UI::Button("...", p::v2{24.f, 0.f}))
{
p::Path selectedFolder =
p::files::SelectFolderDialog("Select project folder", p::GetCurrentPath());
folder = p::ToString(selectedFolder);
}

ImGui::TableNextColumn();
if (UI::Button("Create", p::v2{-FLT_MIN, 0.0f}))
{
if (Editor::Get().CreateProject(folder))
Expand All @@ -112,6 +119,7 @@ namespace rift::Editor
p::Strings::Format("Failed to create project at '{}'", folder)});
}
}
ImGui::EndTable();

UI::EndPopup();
}
Expand Down
2 changes: 2 additions & 0 deletions Libs/UI/Src/Style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ namespace rift::UI
"WorkSans", UI::FontMode::Regular, 14.f, resources / "Fonts/WorkSans-Regular.ttf");
AddTextFont(
"WorkSans", UI::FontMode::Regular, 18.f, resources / "Fonts/WorkSans-Regular.ttf");
AddTextFont(
"WorkSans", UI::FontMode::Regular, 24.f, resources / "Fonts/WorkSans-Regular.ttf");

// Karla
AddTextFont("Karla", UI::FontMode::Bold, 14.f, resources / "Fonts/Karla-Bold.ttf");
Expand Down

0 comments on commit 8beebf1

Please sign in to comment.