Skip to content

Commit d7178ab

Browse files
Profiler Teamcopybara-github
authored andcommitted
Project import generated by Copybara
PiperOrigin-RevId: 837017280
1 parent 9bf450e commit d7178ab

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

frontend/app/components/trace_viewer_v2/timeline/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ cc_library(
9898
deps = [
9999
":constants",
100100
"//third_party/dear_imgui",
101+
"@com_google_absl//absl/strings:string_view",
101102
"@org_xprof//frontend/app/components/trace_viewer_v2/color:colors",
102103
],
103104
)

frontend/app/components/trace_viewer_v2/timeline/draw_utils.cc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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

1012
namespace traceviewer {
@@ -21,7 +23,32 @@ constexpr float kAnimationDuration = 3.0f;
2123
constexpr Pixel kProgressBarGap = 4.0f;
2224
// A scaling factor used in easing calculations for animation.
2325
constexpr 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.
2754
void 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

Comments
 (0)