22
33#include < algorithm>
44#include < cmath>
5+ #include < iterator>
56
67#include " xprof/frontend/app/components/trace_viewer_v2/color/colors.h"
78#include " xprof/frontend/app/components/trace_viewer_v2/timeline/constants.h"
9+ #include " absl/strings/string_view.h"
810#include " third_party/dear_imgui/imgui.h"
911
1012namespace traceviewer {
@@ -21,7 +23,32 @@ constexpr float kAnimationDuration = 3.0f;
2123constexpr Pixel kProgressBarGap = 4 .0f ;
2224// A scaling factor used in easing calculations for animation.
2325constexpr float kProgressScale = 2 .0f ;
24- constexpr Pixel kTextOffsetY = 16 .0f ;
26+ constexpr Pixel kTextOffsetY = 8 .0f ;
27+
28+ // Tutorial messages displayed in the loading indicator.
29+ constexpr absl::string_view kTutorials [] = {
30+ " Pan: A/D or Shift+Scroll" ,
31+ " Zoom: W/S or Ctrl+Scroll" ,
32+ " Scroll: Up/Down Arrow or Scroll" ,
33+ };
34+ // The interval in seconds to display each tutorial message.
35+ constexpr float kTutorialInterval = 1 .5f ;
36+ // The padding adding a gap between the progress indicator and the tutorial text
37+ constexpr float kTutorialTextPaddingTop = 32 .0f ;
38+
39+ void DrawTutorialText (ImDrawList* draw_list, ImVec2 center, float time) {
40+ int num_tutorials = std::size (kTutorials );
41+ int tutorial_index =
42+ static_cast <int >(time / kTutorialInterval ) % num_tutorials;
43+ absl::string_view tutorial = kTutorials [tutorial_index];
44+
45+ ImVec2 text_size =
46+ ImGui::CalcTextSize (tutorial.data (), tutorial.data () + tutorial.size ());
47+ ImVec2 text_pos =
48+ ImVec2 (center.x - text_size.x / 2 .0f , center.y + kTutorialTextPaddingTop );
49+ draw_list->AddText (text_pos, kBlackColor , tutorial.data (),
50+ tutorial.data () + tutorial.size ());
51+ }
2552
2653// Draws a "Loading data..." text message centered below the progress bar.
2754void DrawLoadingText (const ImGuiViewport* viewport) {
@@ -104,6 +131,8 @@ void DrawLoadingIndicator(const ImGuiViewport* viewport) {
104131 }
105132
106133 DrawLoadingText (viewport);
134+
135+ DrawTutorialText (draw_list, center, time);
107136}
108137
109138} // namespace traceviewer
0 commit comments