Skip to content

Commit 5dc48d9

Browse files
committed
Improve gui style
1 parent c4926d9 commit 5dc48d9

File tree

5 files changed

+92
-96
lines changed

5 files changed

+92
-96
lines changed

src/Game.cpp

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ void Game::render() {
7272
window_->clear(sf::Color::White);
7373

7474
if (!states_.empty()) {
75-
// guiTheme();
7675
ImGui::SetNextWindowPos(ImVec2(0.f, 0.f), ImGuiCond_FirstUseEver);
7776
ImGui::SetNextWindowSize(
7877
ImVec2(332.f, static_cast<float>(window_->getSize().y)),
@@ -83,6 +82,39 @@ void Game::render() {
8382
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar);
8483
renderGui();
8584
states_.top()->render();
85+
86+
if (ImGui::CollapsingHeader("Help")) {
87+
ImGui::Text("ABOUT THIS VISUALIZER:");
88+
ImGui::Text(
89+
"This project involves minimal implementations of\nthe popular "
90+
"planning algorithms, including\nboth graph-based and "
91+
"sampling-based planners.");
92+
93+
ImGui::Separator();
94+
95+
ImGui::Text("AVAILABLE PLANNERS:");
96+
97+
ImGui::BulletText("Graph-based Planners:");
98+
ImGui::Indent();
99+
ImGui::BulletText("Breadth-first search (BFS)");
100+
ImGui::BulletText("Depth-first search (DFS)");
101+
ImGui::BulletText("Dijkstra");
102+
ImGui::BulletText("A*");
103+
104+
ImGui::Unindent();
105+
ImGui::BulletText("Sampling-based Planners:");
106+
ImGui::Indent();
107+
ImGui::BulletText("Rapidly-exploring random trees (RRT)");
108+
ImGui::BulletText("RRT*");
109+
ImGui::Unindent();
110+
111+
ImGui::Separator();
112+
113+
ImGui::Text("USAGE GUIDE:");
114+
ImGui::BulletText("Left-click to place/remove obstacle cells");
115+
ImGui::BulletText("Left-SHIFT+left-click to change starting cell");
116+
ImGui::BulletText("Left-CTRL+left-click to change end cell");
117+
}
86118
ImGui::End();
87119
}
88120

@@ -100,6 +132,7 @@ void Game::initGuiTheme() {
100132

101133
ImGuiStyle* style = &ImGui::GetStyle();
102134
style->FramePadding = ImVec2(8.f, 8.f);
135+
style->ItemSpacing = ImVec2(4.0f, 4.0f);
103136

104137
// dark theme colors
105138
auto& colors = ImGui::GetStyle().Colors;
@@ -164,8 +197,9 @@ void Game::setSamplingBasedPlanner(const int id) {
164197
}
165198

166199
void Game::renderGui() {
167-
if (ImGui::Button("Choose Planner..")) ImGui::OpenPopup("planners_popup");
168-
ImGui::SameLine();
200+
if (ImGui::Button("Choose Planner", ImVec2(210.0f, 0.0f)))
201+
ImGui::OpenPopup("planners_popup");
202+
ImGui::SameLine(0.0f, 8.0f);
169203
ImGui::TextUnformatted(curr_planner_.c_str());
170204
if (ImGui::BeginPopup("planners_popup")) {
171205
if (ImGui::BeginMenu("Graph-based Planners")) {
@@ -199,28 +233,6 @@ void Game::renderGui() {
199233

200234
ImGui::EndPopup();
201235
}
202-
203-
// if (ImGui::BeginCombo("Select Planner", curr_planner_.c_str())) {
204-
// for (int n = 0; n < PLANNER_NAMES.size(); n++) {
205-
// bool is_selected = (curr_planner_ == PLANNER_NAMES[n]);
206-
// if (ImGui::Selectable(PLANNER_NAMES[n].c_str(), is_selected)) {
207-
// if (PLANNER_NAMES[n] != curr_planner_) {
208-
// // change the planner
209-
// setPlanner(n);
210-
// }
211-
// curr_planner_ = PLANNER_NAMES[n];
212-
// }
213-
214-
// if (is_selected)
215-
// ImGui::SetItemDefaultFocus(); // Set the initial focus when opening
216-
// the
217-
// // combo (scrolling + for keyboard
218-
// // navigation support in the upcoming
219-
// // navigation branch)
220-
// }
221-
// ImGui::EndCombo();
222-
// }
223-
ImGui::Spacing();
224236
}
225237

226238
} // namespace path_finding_visualizer

src/States/Algorithms/GraphBased/GraphBased.cpp

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void GraphBased::renderGui() {
201201
// RESET button
202202
{
203203
if (!disable_run_ || is_running_) ImGui::BeginDisabled();
204-
bool clicked = ImGui::Button("RESET", ImVec2(100.f, 40.f));
204+
bool clicked = ImGui::Button("RESET", ImVec2(103.0f, 0.0f));
205205
if (!disable_run_ || is_running_) ImGui::EndDisabled();
206206
if (clicked && !is_running_) {
207207
is_reset_ = true;
@@ -216,7 +216,7 @@ void GraphBased::renderGui() {
216216
// always disabled (not implemented yet)
217217
{
218218
if (true) ImGui::BeginDisabled();
219-
bool clicked = ImGui::Button("PAUSE", ImVec2(100.f, 40.f));
219+
bool clicked = ImGui::Button("PAUSE", ImVec2(103.0f, 0.0f));
220220
if (true) ImGui::EndDisabled();
221221
}
222222

@@ -225,7 +225,7 @@ void GraphBased::renderGui() {
225225
// RUN button
226226
{
227227
if (disable_run_) ImGui::BeginDisabled();
228-
bool clicked = ImGui::Button("RUN", ImVec2(100.f, 40.f));
228+
bool clicked = ImGui::Button("RUN", ImVec2(103.0f, 0.0f));
229229
if (disable_run_) ImGui::EndDisabled();
230230
if (clicked && !is_solved_) {
231231
is_running_ = true;
@@ -235,48 +235,41 @@ void GraphBased::renderGui() {
235235
}
236236
}
237237

238-
ImGui::Spacing();
239-
ImGui::Separator();
240-
ImGui::Spacing();
241-
242-
if (disable_gui_parameters_) ImGui::BeginDisabled();
238+
if (ImGui::CollapsingHeader("Configuration",
239+
ImGuiTreeNodeFlags_DefaultOpen)) {
240+
if (disable_gui_parameters_) ImGui::BeginDisabled();
241+
// grid size slider
242+
if (ImGui::SliderInt("Grid Size", &slider_grid_size_, 10, 100)) {
243+
gridSize_ = slider_grid_size_;
244+
initNodes(true, false);
245+
}
243246

244-
// grid size slider
245-
if (ImGui::SliderInt("Grid Size", &slider_grid_size_, 10, 100)) {
246-
gridSize_ = slider_grid_size_;
247-
initNodes(true, false);
248-
}
247+
// radio buttons for choosing 4 or 8 connected grids
248+
{
249+
bool a, b;
250+
a = ImGui::RadioButton("4-connected", &grid_connectivity_, 0);
251+
ImGui::SameLine();
252+
b = ImGui::RadioButton("8-connected", &grid_connectivity_, 1);
253+
if (a || b) {
254+
initNodes(false, true);
255+
}
256+
}
249257

250-
ImGui::Spacing();
258+
// virtual function renderParametersGui()
259+
// need to be implemented by derived class
260+
renderParametersGui();
251261

252-
// radio buttons for choosing 4 or 8 connected grids
253-
{
254-
bool a, b;
255-
a = ImGui::RadioButton("4-connected", &grid_connectivity_, 0);
256-
ImGui::SameLine();
257-
b = ImGui::RadioButton("8-connected", &grid_connectivity_, 1);
258-
if (a || b) {
259-
initNodes(false, true);
262+
{
263+
if (ImGui::Button("CLEAR OBSTACLES", ImVec2(156.5f, 0.f))) {
264+
clearObstacles();
265+
}
266+
ImGui::SameLine();
267+
if (ImGui::Button("RESET PARAMETERS", ImVec2(156.5f, 0.f))) {
268+
}
260269
}
261-
}
262270

263-
ImGui::Spacing();
264-
// virtual function renderParametersGui()
265-
// need to be implemented by derived class
266-
renderParametersGui();
267-
ImGui::Spacing();
268-
ImGui::Separator();
269-
ImGui::Spacing();
270-
{
271-
if (ImGui::Button("CLEAR OBSTACLES", ImVec2(154.f, 40.f))) {
272-
clearObstacles();
273-
}
274-
ImGui::SameLine();
275-
if (ImGui::Button("RESET PARAMETERS", ImVec2(154.f, 40.f))) {
276-
}
271+
if (disable_gui_parameters_) ImGui::EndDisabled();
277272
}
278-
279-
if (disable_gui_parameters_) ImGui::EndDisabled();
280273
}
281274

282275
void GraphBased::render() {

src/States/Algorithms/SamplingBased/RRT/RRT.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void RRT::renderParametersGui() {
102102
if (ImGui::InputDouble("range", &range_, 0.01, 1.0, "%.3f")) {
103103
if (range_ < 0) range_ = 0.01;
104104
}
105-
ImGui::Spacing();
106105
if (ImGui::InputDouble("goal_radius", &goal_radius_, 0.01, 1.0, "%.3f")) {
107106
if (goal_radius_ < 0.01) goal_radius_ = 0.01;
108107
}

src/States/Algorithms/SamplingBased/RRT_STAR/RRT_STAR.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ void RRT_STAR::renderParametersGui() {
5858
if (ImGui::InputDouble("range", &range_, 0.01, 1.0, "%.3f")) {
5959
if (range_ < 0.01) range_ = 0.01;
6060
}
61-
ImGui::Spacing();
6261
if (ImGui::InputDouble("rewire_factor", &rewire_factor_, 0.01, 0.1, "%.2f")) {
6362
if (rewire_factor_ < 1.0)
6463
rewire_factor_ = 1.0;
6564
else if (rewire_factor_ > 2.0)
6665
rewire_factor_ = 2.0;
6766
}
68-
ImGui::Spacing();
6967
if (ImGui::InputDouble("goal_radius", &goal_radius_, 0.01, 1.0, "%.3f")) {
7068
if (goal_radius_ < 0.01) goal_radius_ = 0.01;
7169
}

src/States/Algorithms/SamplingBased/SamplingBased.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void SamplingBased::renderGui() {
211211
// RESET button
212212
{
213213
if (!disable_run_ || is_running_) ImGui::BeginDisabled();
214-
bool clicked = ImGui::Button("RESET", ImVec2(100.f, 40.f));
214+
bool clicked = ImGui::Button("RESET", ImVec2(103.f, 0.f));
215215
if (!disable_run_ || is_running_) ImGui::EndDisabled();
216216
if (clicked && !is_running_) {
217217
is_reset_ = true;
@@ -226,7 +226,7 @@ void SamplingBased::renderGui() {
226226
// always disabled (not implemented yet)
227227
{
228228
if (true) ImGui::BeginDisabled();
229-
bool clicked = ImGui::Button("PAUSE", ImVec2(100.f, 40.f));
229+
bool clicked = ImGui::Button("PAUSE", ImVec2(103.f, 0.f));
230230
if (true) ImGui::EndDisabled();
231231
}
232232

@@ -235,7 +235,7 @@ void SamplingBased::renderGui() {
235235
// RUN button
236236
{
237237
if (disable_run_) ImGui::BeginDisabled();
238-
bool clicked = ImGui::Button("RUN", ImVec2(100.f, 40.f));
238+
bool clicked = ImGui::Button("RUN", ImVec2(103.f, 0.f));
239239
if (disable_run_) ImGui::EndDisabled();
240240
if (clicked && !is_solved_) {
241241
is_running_ = true;
@@ -245,45 +245,39 @@ void SamplingBased::renderGui() {
245245
}
246246
}
247247

248-
ImGui::Spacing();
249-
250248
{
251249
std::unique_lock<std::mutex> iter_no_lck(iter_no_mutex_);
252250
const float progress = static_cast<float>(
253251
utils::map(static_cast<double>(curr_iter_no_), 0.0,
254252
static_cast<double>(max_iterations_), 0.0, 1.0));
255253
const std::string buf =
256254
std::to_string(curr_iter_no_) + "/" + std::to_string(max_iterations_);
257-
ImGui::ProgressBar(progress, ImVec2(-1.0f, 0.0f), buf.c_str());
255+
ImGui::ProgressBar(progress, ImVec2(317.0f, 0.0f), buf.c_str());
258256
}
259257

260-
ImGui::Spacing();
261-
ImGui::Separator();
262-
ImGui::Spacing();
263-
264-
if (disable_gui_parameters_) ImGui::BeginDisabled();
258+
if (ImGui::CollapsingHeader("Configuration",
259+
ImGuiTreeNodeFlags_DefaultOpen)) {
260+
if (disable_gui_parameters_) ImGui::BeginDisabled();
265261

266-
if (ImGui::InputInt("max_iterations", &max_iterations_, 1, 1000)) {
267-
if (max_iterations_ < 1) max_iterations_ = 1;
268-
}
269-
ImGui::Spacing();
270-
// virtual function renderParametersGui()
271-
// need to be implemented by derived class
272-
renderParametersGui();
273-
ImGui::Spacing();
274-
ImGui::Separator();
275-
ImGui::Spacing();
276-
{
277-
if (ImGui::Button("CLEAR OBSTACLES", ImVec2(154.f, 40.f))) {
278-
clearObstacles();
262+
if (ImGui::InputInt("max_iterations", &max_iterations_, 1, 1000)) {
263+
if (max_iterations_ < 1) max_iterations_ = 1;
279264
}
280-
ImGui::SameLine();
281-
if (ImGui::Button("RESET PARAMETERS", ImVec2(154.f, 40.f))) {
282-
initParameters();
265+
// virtual function renderParametersGui()
266+
// need to be implemented by derived class
267+
renderParametersGui();
268+
269+
{
270+
if (ImGui::Button("CLEAR OBSTACLES", ImVec2(156.5f, 0.f))) {
271+
clearObstacles();
272+
}
273+
ImGui::SameLine();
274+
if (ImGui::Button("RESET PARAMETERS", ImVec2(156.5f, 0.f))) {
275+
initParameters();
276+
}
283277
}
284-
}
285278

286-
if (disable_gui_parameters_) ImGui::EndDisabled();
279+
if (disable_gui_parameters_) ImGui::EndDisabled();
280+
}
287281
}
288282

289283
void SamplingBased::render() {

0 commit comments

Comments
 (0)