legend.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_HUD_DISPLAY_LEGEND_H_
  5. #define ASH_HUD_DISPLAY_LEGEND_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "ui/views/view.h"
  10. namespace ash {
  11. namespace hud_display {
  12. class Graph;
  13. // Draws legend view.
  14. class Legend : public views::View {
  15. public:
  16. using Formatter = base::RepeatingCallback<std::u16string(float)>;
  17. METADATA_HEADER(Legend);
  18. struct Entry {
  19. Entry(const Graph& graph,
  20. std::u16string label,
  21. std::u16string tooltip,
  22. Formatter formatter);
  23. Entry(const Entry&);
  24. ~Entry();
  25. const Graph& graph;
  26. std::u16string label;
  27. std::u16string tooltip;
  28. Formatter formatter; // formatting function
  29. };
  30. explicit Legend(const std::vector<Entry>& contents);
  31. Legend(const Legend&) = delete;
  32. Legend& operator=(const Legend&) = delete;
  33. ~Legend() override;
  34. // views::View:
  35. void Layout() override;
  36. // Display values for the given index. |index| is always interpreted as
  37. // "negative", i.e. "0" - current data, "1" - previous graph data, 2 - two
  38. // steps ago. I.e. it's number of graph points from the right graph edge.
  39. void SetValuesIndex(size_t index);
  40. // Update displayed values after data was updated.
  41. void RefreshValues();
  42. };
  43. } // namespace hud_display
  44. } // namespace ash
  45. #endif // ASH_HUD_DISPLAY_LEGEND_H_