Skip to content

Commit 27e3d3a

Browse files
committed
tweaks to about dialog and fps idling
1 parent 2fa0a69 commit 27e3d3a

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

src/app.cpp

+63-63
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static bool g_show_modal = false;
6262
static const vector<pair<string, string>> g_help_strings = {
6363
{"h", "Show this help window"},
6464
{"Left click+drag", "Rotate the camera"},
65-
{"Scroll mouse", "Zoom the camera"},
65+
{"Scroll mouse/pinch", "Zoom the camera"},
6666
{"1", "Switch to XY orthographic view"},
6767
{"2", "Switch to XZ orthographic view"},
6868
{"3", "Switch to ZY orthographic view"},
@@ -84,6 +84,23 @@ static const vector<pair<string, string>> g_help_strings = {
8484
{"p", "Toggle display of 1D X, Y, Z projections of the points"}};
8585
static const map<string, string> g_tooltip_map(g_help_strings.begin(), g_help_strings.end());
8686

87+
static auto tooltip(const char *text, float wrap_width = 400.f)
88+
{
89+
if (ImGui::BeginItemTooltip())
90+
{
91+
ImGui::PushTextWrapPos(wrap_width);
92+
ImGui::TextUnformatted(text);
93+
ImGui::PopTextWrapPos();
94+
ImGui::EndTooltip();
95+
}
96+
}
97+
98+
static auto hotkey_tooltip(const char *name, float wrap_width = 400.f)
99+
{
100+
if (auto t = g_tooltip_map.find(name); t != g_tooltip_map.end())
101+
tooltip(fmt::format("{}.\nKey: {}", t->second, t->first).c_str(), wrap_width);
102+
}
103+
87104
static float4x4 layout_2d_matrix(int num_dims, int2 dims)
88105
{
89106
float cell_spacing = 1.f / (num_dims - 1);
@@ -305,8 +322,9 @@ SampleViewer::SampleViewer()
305322
m_params.callbacks.ShowStatus = [this]()
306323
{
307324
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ImGui::GetFontSize() * 0.15f);
308-
ImGui::Text("Reset + randomize: %3.3f ms | Sampling: %3.3f ms | Total: %3.3f ms (%3.0f pps)", m_time1,
309-
m_time2, m_time1 + m_time2, m_point_count / (m_time1 + m_time2));
325+
ImGui::Text("%3.3f / %3.3f ms (%3.0f pps)", m_time2, m_time1 + m_time2, m_point_count / (m_time1 + m_time2));
326+
tooltip("Shows A/B (points per second) where A is how long it took to call Sampler::sample(), and B includes "
327+
"other setup costs.");
310328
// ImGui::SameLine();
311329
ImGui::SameLine(ImGui::GetIO().DisplaySize.x - 16.f * ImGui::GetFontSize());
312330
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ImGui::GetFontSize() * 0.15f);
@@ -470,17 +488,20 @@ void SampleViewer::draw_about_dialog()
470488
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
471489
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
472490
ImGui::SetNextWindowFocus();
491+
const float2 col_width = {11 * HelloImGui::EmSize(), 32 * HelloImGui::EmSize()};
492+
ImGui::SetNextWindowContentSize(float2{col_width[0] + col_width[1], 0});
473493

474-
if (ImGui::BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
494+
if (ImGui::BeginPopupModal("About", nullptr,
495+
ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NoSavedSettings |
496+
ImGuiWindowFlags_AlwaysAutoResize))
475497
{
476-
const int col_width[2] = {11, 34};
477498

478499
ImGui::Spacing();
479500

480501
if (ImGui::BeginTable("about_table1", 2))
481502
{
482-
ImGui::TableSetupColumn("one", ImGuiTableColumnFlags_WidthFixed, HelloImGui::EmSize() * col_width[0]);
483-
ImGui::TableSetupColumn("two", ImGuiTableColumnFlags_WidthFixed, HelloImGui::EmSize() * col_width[1]);
503+
ImGui::TableSetupColumn("icon", ImGuiTableColumnFlags_WidthFixed, col_width[0]);
504+
ImGui::TableSetupColumn("description", ImGuiTableColumnFlags_WidthFixed, col_width[1]);
484505

485506
ImGui::TableNextRow();
486507
ImGui::TableNextColumn();
@@ -494,7 +515,7 @@ void SampleViewer::draw_about_dialog()
494515
HelloImGui::ImageFromAsset("app_settings/icon.png", {128, 128}); // show the app icon
495516

496517
ImGui::TableNextColumn();
497-
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + HelloImGui::EmSize() * col_width[1]);
518+
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + col_width[1]);
498519

499520
ImGui::PushFont(m_bold[30]);
500521
ImGui::Text("Samplin' Safari");
@@ -520,7 +541,7 @@ void SampleViewer::draw_about_dialog()
520541

521542
ImGui::Spacing();
522543

523-
ImGui::Text("It is developed by Wojciech Jarosz, and is freely available under a 3-clause BSD license.");
544+
ImGui::Text("It is developed by Wojciech Jarosz, and is available under a 3-clause BSD license.");
524545

525546
ImGui::PopTextWrapPos();
526547
ImGui::EndTable();
@@ -529,7 +550,7 @@ void SampleViewer::draw_about_dialog()
529550
auto right_align = [](const string &text)
530551
{
531552
auto posX = (ImGui::GetCursorPosX() + ImGui::GetColumnWidth() - ImGui::CalcTextSize(text.c_str()).x -
532-
ImGui::GetScrollX() - 2 * ImGui::GetStyle().ItemSpacing.x);
553+
2 * ImGui::GetStyle().ItemSpacing.x);
533554
if (posX > ImGui::GetCursorPosX())
534555
ImGui::SetCursorPosX(posX);
535556
ImGui::Text(text);
@@ -545,17 +566,38 @@ void SampleViewer::draw_about_dialog()
545566
ImGui::PopFont();
546567

547568
ImGui::TableNextColumn();
548-
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + HelloImGui::EmSize() * (col_width[1] - 1));
569+
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + col_width[1] - HelloImGui::EmSize());
549570
ImGui::PushFont(m_regular[14]);
550571
ImGui::Text(desc);
551572
ImGui::PopFont();
552573
};
553574

554575
if (ImGui::BeginTabBar("AboutTabBar"))
555576
{
577+
if (ImGui::BeginTabItem("Keybindings", nullptr))
578+
{
579+
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + col_width[0] + col_width[1]);
580+
ImGui::Text("The following keyboard shortcuts are available (these are also described in tooltips over "
581+
"their respective controls).");
582+
583+
ImGui::Spacing();
584+
ImGui::PopTextWrapPos();
585+
586+
if (ImGui::BeginTable("about_table3", 2))
587+
{
588+
ImGui::TableSetupColumn("Key", ImGuiTableColumnFlags_WidthFixed, col_width[0]);
589+
ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthFixed, col_width[1]);
590+
591+
for (auto item : g_help_strings)
592+
item_and_description(item.first, item.second);
593+
594+
ImGui::EndTable();
595+
}
596+
ImGui::EndTabItem();
597+
}
556598
if (ImGui::BeginTabItem("Credits"))
557599
{
558-
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + HelloImGui::EmSize() * (col_width[0] + col_width[1]));
600+
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + col_width[0] + col_width[1]);
559601
ImGui::Text("Samplin' Safari was originally created as part of the publication:");
560602

561603
ImGui::Spacing();
@@ -576,10 +618,8 @@ void SampleViewer::draw_about_dialog()
576618

577619
if (ImGui::BeginTable("about_table2", 2))
578620
{
579-
ImGui::TableSetupColumn("one", ImGuiTableColumnFlags_WidthFixed,
580-
HelloImGui::EmSize() * col_width[0]);
581-
ImGui::TableSetupColumn("two", ImGuiTableColumnFlags_WidthFixed,
582-
HelloImGui::EmSize() * col_width[1]);
621+
ImGui::TableSetupColumn("one", ImGuiTableColumnFlags_WidthFixed, col_width[0]);
622+
ImGui::TableSetupColumn("two", ImGuiTableColumnFlags_WidthFixed, col_width[1]);
583623

584624
item_and_description("bitcount",
585625
"Mike Pedersen's MIT-licensed fast, cross-platform bit counting functions.");
@@ -618,29 +658,6 @@ void SampleViewer::draw_about_dialog()
618658
}
619659
ImGui::EndTabItem();
620660
}
621-
if (ImGui::BeginTabItem("Keybindings", nullptr))
622-
{
623-
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + HelloImGui::EmSize() * (col_width[0] + col_width[1]));
624-
ImGui::Text("The following keyboard shortcuts are available (these are also described in tooltips over "
625-
"their respective controls).");
626-
627-
ImGui::Spacing();
628-
ImGui::PopTextWrapPos();
629-
630-
if (ImGui::BeginTable("about_table3", 2))
631-
{
632-
ImGui::TableSetupColumn("Key", ImGuiTableColumnFlags_WidthFixed,
633-
HelloImGui::EmSize() * col_width[0]);
634-
ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthFixed,
635-
HelloImGui::EmSize() * col_width[1]);
636-
637-
for (auto item : g_help_strings)
638-
item_and_description(item.first, item.second);
639-
640-
ImGui::EndTable();
641-
}
642-
ImGui::EndTabItem();
643-
}
644661
ImGui::EndTabBar();
645662
}
646663

@@ -669,23 +686,6 @@ void SampleViewer::draw_editor()
669686
return ret;
670687
};
671688

672-
auto tooltip = [](const char *text, float wrap_width = 400.f)
673-
{
674-
if (ImGui::BeginItemTooltip())
675-
{
676-
ImGui::PushTextWrapPos(wrap_width);
677-
ImGui::TextUnformatted(text);
678-
ImGui::PopTextWrapPos();
679-
ImGui::EndTooltip();
680-
}
681-
};
682-
683-
auto hotkey_tooltip = [tooltip](const char *name, float wrap_width = 400.f)
684-
{
685-
if (auto t = g_tooltip_map.find(name); t != g_tooltip_map.end())
686-
tooltip(fmt::format("{}.\nKey: {}", t->second, t->first).c_str(), wrap_width);
687-
};
688-
689689
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.7f);
690690

691691
// =========================================================
@@ -1352,10 +1352,10 @@ void SampleViewer::draw_scene()
13521352
camera.persp_factor = lerp(camera0.persp_factor, camera1.persp_factor, t);
13531353
if (t >= 1.0f)
13541354
{
1355-
camera.camera_type = camera1.camera_type;
1356-
// m_params.fpsIdling.fpsIdle = 9.f; // animation is done, reduce FPS
1357-
if (m_animate_start_time != 0.0f)
1358-
m_params.fpsIdling.enableIdling = m_idling_backup;
1355+
camera.camera_type = camera1.camera_type;
1356+
m_params.fpsIdling.fpsIdle = 9.f; // animation is done, reduce FPS
1357+
// if (m_animate_start_time != 0.0f)
1358+
// m_params.fpsIdling.enableIdling = m_idling_backup;
13591359
m_animate_start_time = 0.f;
13601360
}
13611361

@@ -1439,9 +1439,9 @@ void SampleViewer::set_view(CameraType view)
14391439
m_camera[CAMERA_CURRENT].camera_type = (view == m_camera[CAMERA_CURRENT].camera_type) ? view : CAMERA_CURRENT;
14401440
m_view = view;
14411441

1442-
// m_params.fpsIdling.fpsIdle = 0.f; // during animation, increase FPS
1443-
m_idling_backup = m_params.fpsIdling.enableIdling;
1444-
m_params.fpsIdling.enableIdling = false;
1442+
m_params.fpsIdling.fpsIdle = 0.f; // during animation, increase FPS
1443+
m_idling_backup = m_params.fpsIdling.enableIdling;
1444+
// m_params.fpsIdling.enableIdling = false;
14451445
}
14461446
}
14471447

0 commit comments

Comments
 (0)