glanceables_view.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2022 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. #include "ash/glanceables/glanceables_view.h"
  5. #include <memory>
  6. #include "ash/glanceables/glanceables_weather_view.h"
  7. #include "ash/glanceables/glanceables_welcome_label.h"
  8. #include "ash/strings/grit/ash_strings.h"
  9. #include "third_party/skia/include/core/SkColor.h"
  10. #include "ui/base/l10n/l10n_util.h"
  11. #include "ui/gfx/font_list.h"
  12. #include "ui/gfx/geometry/insets.h"
  13. #include "ui/gfx/text_constants.h"
  14. #include "ui/views/controls/label.h"
  15. #include "ui/views/layout/box_layout.h"
  16. namespace ash {
  17. namespace {
  18. const gfx::FontList& GetSectionFontList() {
  19. static const base::NoDestructor<gfx::FontList> font_list("Google Sans, 18px");
  20. return *font_list;
  21. }
  22. // Configures a section label, like "Up next".
  23. void SetupSectionLabel(views::Label* label) {
  24. label->SetAutoColorReadabilityEnabled(false);
  25. label->SetFontList(GetSectionFontList());
  26. label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
  27. }
  28. } // namespace
  29. GlanceablesView::GlanceablesView() {
  30. // Inside border insets are set in OnBoundsChanged() when this view is added
  31. // to the widget.
  32. layout_ = SetLayoutManager(std::make_unique<views::BoxLayout>(
  33. views::BoxLayout::Orientation::kVertical));
  34. welcome_label_ = AddChildView(std::make_unique<GlanceablesWelcomeLabel>());
  35. weather_view_ = AddChildView(std::make_unique<GlanceablesWeatherView>());
  36. // Container for the left and right columns.
  37. views::View* container = AddChildView(std::make_unique<views::View>());
  38. const gfx::Insets container_insets = gfx::Insets::VH(36, 4);
  39. auto* container_layout =
  40. container->SetLayoutManager(std::make_unique<views::BoxLayout>(
  41. views::BoxLayout::Orientation::kHorizontal, container_insets));
  42. // Container for the views on the left.
  43. auto* left_column = container->AddChildView(std::make_unique<views::View>());
  44. left_column->SetLayoutManager(std::make_unique<views::BoxLayout>(
  45. views::BoxLayout::Orientation::kVertical));
  46. // The "Up next" label.
  47. up_next_label_ = left_column->AddChildView(std::make_unique<views::Label>());
  48. SetupSectionLabel(up_next_label_);
  49. up_next_label_->SetText(l10n_util::GetStringUTF16(IDS_GLANCEABLES_UP_NEXT));
  50. // TODO(crbug.com/1353119): Add calendar events.
  51. // Container for the views on the right.
  52. auto* right_column = container->AddChildView(std::make_unique<views::View>());
  53. right_column->SetLayoutManager(std::make_unique<views::BoxLayout>(
  54. views::BoxLayout::Orientation::kVertical));
  55. // The "Restore last session" label.
  56. restore_session_label_ =
  57. right_column->AddChildView(std::make_unique<views::Label>());
  58. SetupSectionLabel(restore_session_label_);
  59. restore_session_label_->SetText(
  60. l10n_util::GetStringUTF16(IDS_GLANCEABLES_RESTORE_SESSION));
  61. // TODO(crbug.com/1353119): Add restore session screenshot / button.
  62. // Share space equally between the two columns.
  63. container_layout->SetFlexForView(left_column, 1);
  64. container_layout->SetFlexForView(right_column, 1);
  65. }
  66. GlanceablesView::~GlanceablesView() = default;
  67. void GlanceablesView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
  68. gfx::Rect local_bounds = GetLocalBounds();
  69. // This view fills the screen, so the margins are a fraction of the screen
  70. // height and width.
  71. const int vertical_margin = local_bounds.height() / 6;
  72. const int horizontal_margin = local_bounds.width() / 6;
  73. layout_->set_inside_border_insets(
  74. gfx::Insets::VH(vertical_margin, horizontal_margin));
  75. }
  76. void GlanceablesView::OnThemeChanged() {
  77. views::View::OnThemeChanged();
  78. // TODO(crbug.com/1353119): Use color provider.
  79. up_next_label_->SetEnabledColor(SK_ColorWHITE);
  80. restore_session_label_->SetEnabledColor(SK_ColorWHITE);
  81. }
  82. } // namespace ash