10
10
11
11
namespace rift ::Editor
12
12
{
13
+ void TextCentered (const char * text)
14
+ {
15
+ auto windowWidth = ImGui::GetWindowSize ().x ;
16
+ auto textWidth = ImGui::CalcTextSize (text).x ;
17
+
18
+ ImGui::SetCursorPosX ((windowWidth - textWidth) * 0 .5f );
19
+ ImGui::Text (text);
20
+ }
21
+
13
22
void DrawProjectManager (ast::Tree& ast)
14
23
{
15
24
// Center modal when appearing
16
25
UI::SetNextWindowPos (UI::GetMainViewport ()->GetCenter (), ImGuiCond_Always, {0 .5f , 0 .5f });
17
26
18
27
p::v2 viewportSize = UI::GetMainViewport ()->Size ;
19
- p::v2 modalSize = p::v2{600 .f , 400 .f };
28
+ p::v2 modalSize = p::v2{600 .f , 0 .f };
20
29
modalSize.x = p::Min (modalSize.x , viewportSize.x - 20 .f );
21
30
modalSize.y = p::Min (modalSize.y , viewportSize.y - 20 .f );
22
31
23
32
UI::SetNextWindowSize (modalSize, ImGuiCond_Always);
24
33
25
34
if (UI::BeginPopupModal (" Project Manager" , nullptr ,
26
- ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize ))
35
+ ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize ))
27
36
{
28
- UI::PushFont (" WorkSans" , UI::FontMode::Regular, 18 .f );
29
- UI::Text (" Projects" );
37
+ UI::PushFont (" WorkSans" , UI::FontMode::Regular, 24 .f );
38
+ TextCentered (" Projects" );
30
39
UI::PopFont ();
31
- UI::Separator ();
40
+
41
+ UI::Spacing ();
32
42
UI::Spacing ();
33
43
44
+ static p::String folder;
45
+
46
+ ImGui::BeginTable (" table" , 2 );
47
+ ImGui::TableNextColumn ();
48
+ {
49
+ UI::PushFont (" WorkSans" , UI::FontMode::Regular, 18 .f );
50
+ UI::Text (" Open" );
51
+ UI::PopFont ();
52
+ UI::Separator ();
53
+ UI::Spacing ();
54
+
55
+ UI::SetItemDefaultFocus ();
56
+ {
57
+ UI::Text (" Recent projects:" );
58
+ static const char * recentProjects[]{" Project.rift" };
59
+ static int selectedN = 0 ;
60
+ UI::SetNextItemWidth (-FLT_MIN);
61
+
62
+ for (int n = 0 ; n < IM_ARRAYSIZE (recentProjects); ++n)
63
+ {
64
+ const bool isSelected = (selectedN == n);
65
+ UI::BulletText (recentProjects[n]);
66
+ UI::SameLine (ImGui::GetContentRegionAvail ().x - 30 .f );
67
+ if (UI::SmallButton (" open" )) {}
68
+ }
69
+ }
70
+ UI::Dummy ({10 .f , 40 .f });
71
+ }
72
+ ImGui::TableNextColumn ();
73
+ {
74
+ UI::PushFont (" WorkSans" , UI::FontMode::Regular, 18 .f );
75
+ UI::Text (" Create" );
76
+ UI::PopFont ();
77
+ UI::Separator ();
78
+ UI::Spacing ();
79
+
80
+ UI::PushItemWidth (-32 .f );
81
+ UI::InputTextWithHint (" ##path" , " project path..." , folder);
82
+ UI::PopItemWidth ();
83
+ UI::SameLine ();
84
+ if (UI::Button (" ..." , p::v2{24 .f , 0 .f }))
85
+ {
86
+ p::Path selectedFolder =
87
+ p::files::SelectFolderDialog (" Select project folder" , p::GetCurrentPath ());
88
+ folder = p::ToString (selectedFolder);
89
+ }
90
+ }
91
+
92
+ ImGui::TableNextRow ();
93
+ ImGui::TableNextColumn ();
34
94
if (UI::Button (" Open" , p::v2{-FLT_MIN, 0 .0f }))
35
95
{
36
96
p::String folder =
@@ -45,60 +105,7 @@ namespace rift::Editor
45
105
p::Strings::Format (" Failed to open project at '{}'" , p::ToString (folder))});
46
106
}
47
107
}
48
- UI::SetItemDefaultFocus ();
49
- {
50
- UI::Text (" Recent Projects" );
51
- static const char * recentProjects[]{" One recent project" };
52
- static int selectedN = 0 ;
53
- UI::SetNextItemWidth (-FLT_MIN);
54
- if (UI::BeginListBox (" ##RecentProjects" ))
55
- {
56
- for (int n = 0 ; n < IM_ARRAYSIZE (recentProjects); ++n)
57
- {
58
- const bool isSelected = (selectedN == n);
59
- if (UI::Selectable (recentProjects[n], isSelected))
60
- {
61
- selectedN = n;
62
- }
63
-
64
- // Set the initial focus when opening the combo (scrolling + keyboard
65
- // navigation focus)
66
- if (isSelected)
67
- {
68
- UI::SetItemDefaultFocus ();
69
- }
70
- }
71
- UI::EndListBox ();
72
- }
73
- }
74
-
75
-
76
- UI::Spacing ();
77
- UI::Spacing ();
78
- UI::Spacing ();
79
- UI::Spacing ();
80
-
81
- UI::PushFont (" WorkSans" , UI::FontMode::Regular, 18 .f );
82
- UI::Text (" New" );
83
- UI::PopFont ();
84
- UI::Separator ();
85
- UI::Spacing ();
86
-
87
- UI::AlignTextToFramePadding ();
88
- UI::Text (" Destination" );
89
- UI::SameLine ();
90
- static p::String folder;
91
- UI::PushItemWidth (-32 .f );
92
- UI::InputText (" ##path" , folder);
93
- UI::PopItemWidth ();
94
- UI::SameLine ();
95
- if (UI::Button (" ..." , p::v2{24 .f , 0 .f }))
96
- {
97
- p::Path selectedFolder =
98
- p::files::SelectFolderDialog (" Select project folder" , p::GetCurrentPath ());
99
- folder = p::ToString (selectedFolder);
100
- }
101
-
108
+ ImGui::TableNextColumn ();
102
109
if (UI::Button (" Create" , p::v2{-FLT_MIN, 0 .0f }))
103
110
{
104
111
if (Editor::Get ().CreateProject (folder))
@@ -112,6 +119,7 @@ namespace rift::Editor
112
119
p::Strings::Format (" Failed to create project at '{}'" , folder)});
113
120
}
114
121
}
122
+ ImGui::EndTable ();
115
123
116
124
UI::EndPopup ();
117
125
}
0 commit comments