1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193

ash / style / style_viewer / tab_slider_instances_grid_view_factory.cc [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/style/style_viewer/system_ui_components_grid_view_factories.h"

#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/style/style_viewer/system_ui_components_grid_view.h"
#include "ash/style/tab_slider.h"
#include "ash/style/tab_slider_button.h"

namespace ash {

namespace {

// Configurations of grid view for `TabSlider` instances.
constexpr size_t kGridViewRowNum = 9;
constexpr size_t kGridViewColNum = 1;
constexpr size_t kGridViewRowGroupSize = 3;
constexpr size_t kGirdViewColGroupSize = 1;

}  // namespace

std::unique_ptr<SystemUIComponentsGridView> CreateTabSliderInstancesGridView() {
  auto grid_view = std::make_unique<SystemUIComponentsGridView>(
      kGridViewRowNum, kGridViewColNum, kGridViewRowGroupSize,
      kGirdViewColGroupSize);

  // Create an instance of icon slider with two buttons, a slider background,
  // the recommended layout, and a selector animation.
  auto icon_slider_two = std::make_unique<TabSlider>(/*max_tab_num=*/2);
  // Add the buttons with `IconSliderButton` unique pointer.
  auto* image_button =
      icon_slider_two->AddButton(std::make_unique<IconSliderButton>(
          IconSliderButton::PressedCallback(), &kCaptureModeImageIcon,
          u"image mode"));
  image_button->SetSelected(true);
  icon_slider_two->AddButton(std::make_unique<IconSliderButton>(
      IconSliderButton::PressedCallback(), &kCaptureModeCameraIcon,
      u"video mode"));

  // Create an instance of icon slider with three buttons, no background, a
  // customized layout, and no slider animation.
  TabSlider::InitParams params = TabSlider::kDefaultParams;
  params.internal_border_padding = 0;
  params.between_buttons_spacing = 16;
  params.has_background = false;
  params.has_selector_animation = false;
  auto icon_slider_three = std::make_unique<TabSlider>(
      /*max_tab_num=*/3, params);
  auto* fullscreen_button = icon_slider_three->AddButton<IconSliderButton>(
      IconSliderButton::PressedCallback(), &kCaptureModeFullscreenIcon,
      u"fullscreen mode");
  fullscreen_button->SetSelected(true);
  icon_slider_three->AddButton<IconSliderButton>(
      IconSliderButton::PressedCallback(), &kCaptureModeRegionIcon,
      u"region mode");
  icon_slider_three->AddButton<IconSliderButton>(
      IconSliderButton::PressedCallback(), &kCaptureModeWindowIcon,
      u"window mode");

  // Create an instance of disabled icon slider with two buttons.
  auto icon_slider_two_disabled =
      std::make_unique<TabSlider>(/*max_tab_num=*/2);
  auto* disabled_image_button =
      icon_slider_two_disabled->AddButton<IconSliderButton>(
          IconSliderButton::PressedCallback(), &kCaptureModeImageIcon,
          u"image mode");
  disabled_image_button->SetSelected(true);
  icon_slider_two_disabled->AddButton<IconSliderButton>(
      IconSliderButton::PressedCallback(), &kCaptureModeCameraIcon,
      u"video mode");
  icon_slider_two_disabled->SetEnabled(false);

  // Create an instance of label slider with two buttons and unevenly
  // distributed space.
  params = TabSlider::kDefaultParams;
  params.distribute_space_evenly = false;
  auto label_slider_two_unevenly = std::make_unique<TabSlider>(
      /*max_tab_num=*/2, params);
  // Add the buttons with `TabSliderButton` unique pointer.
  auto* label_button =
      label_slider_two_unevenly->AddButton(std::make_unique<LabelSliderButton>(
          LabelSliderButton::PressedCallback(), u"one", u"label 1"));
  label_button->SetSelected(true);
  label_slider_two_unevenly->AddButton(std::make_unique<LabelSliderButton>(
      LabelSliderButton::PressedCallback(), u"one two three", u"label 2"));

  // Create an instance of label slider with two buttons and evenly distributed
  // space.
  auto label_slider_two = std::make_unique<TabSlider>(/*max_tab_num=*/2);
  auto* label_button_two_1 = label_slider_two->AddButton<LabelSliderButton>(
      LabelSliderButton::PressedCallback(), u"one", u"label 1");
  label_button_two_1->SetSelected(true);
  label_slider_two->AddButton<LabelSliderButton>(
      LabelSliderButton::PressedCallback(), u"one two three", u"label 2");

  // Create an instance of label slider with three buttons and evenly
  // distributed space.
  auto label_slider_three = std::make_unique<TabSlider>(/*max_tab_num=*/3);
  auto* label_button_three_1 = label_slider_three->AddButton<LabelSliderButton>(
      LabelSliderButton::PressedCallback(), u"one", u"label 1");
  label_button_three_1->SetSelected(true);
  label_slider_three->AddButton<LabelSliderButton>(
      LabelSliderButton::PressedCallback(), u"one two three", u"label 2");
  label_slider_three->AddButton<LabelSliderButton>(
      LabelSliderButton::PressedCallback(), u"one two three four five",
      u"label 3");

  // Create an instance of icon + label slider with two buttons and unevenly
  // distributed space.
  params = IconLabelSliderButton::kSliderParams;
  params.distribute_space_evenly = false;
  auto icon_label_slider_two_unevenly = std::make_unique<TabSlider>(
      /*max_tab_num=*/2, params);
  auto* icon_label_button =
      icon_label_slider_two_unevenly->AddButton<IconLabelSliderButton>(
          IconLabelSliderButton::PressedCallback(),
          &kPrivacyIndicatorsCameraIcon, u"one", u"button 1");
  icon_label_button->SetSelected(true);
  icon_label_slider_two_unevenly->AddButton<IconLabelSliderButton>(
      IconLabelSliderButton::PressedCallback(),
      &kPrivacyIndicatorsMicrophoneIcon, u"one two three", u"button 2");

  // Create an instance of icon + label slider with three buttons and evenly
  // distributed space.
  auto icon_label_slider_three = std::make_unique<TabSlider>(
      /*max_tab_num=*/3, IconLabelSliderButton::kSliderParams);
  auto* icon_label_button_1 =
      icon_label_slider_three->AddButton<IconLabelSliderButton>(
          IconLabelSliderButton::PressedCallback(),
          &kPrivacyIndicatorsMicrophoneIcon, u"one", u"button 1");
  icon_label_button_1->SetSelected(true);
  icon_label_slider_three->AddButton<IconLabelSliderButton>(
      IconLabelSliderButton::PressedCallback(),
      &kPrivacyIndicatorsMicrophoneIcon, u"one two three", u"button 2");
  icon_label_slider_three->AddButton<IconLabelSliderButton>(
      IconLabelSliderButton::PressedCallback(),
      &kPrivacyIndicatorsMicrophoneIcon, u"ont two three four five",
      u"button 3");

  // Create an instance of disabled icon + label slider with two buttons.
  auto icon_label_slider_two_disabled =
      std::make_unique<TabSlider>(/*max_tab_num=*/2);
  auto* icon_label_button_disabled =
      icon_label_slider_two_disabled->AddButton<IconLabelSliderButton>(
          IconLabelSliderButton::PressedCallback(),
          &kPrivacyIndicatorsCameraIcon, u"one", u"button 1");
  icon_label_button_disabled->SetSelected(true);
  icon_label_slider_two_disabled->AddButton<IconLabelSliderButton>(
      IconLabelSliderButton::PressedCallback(),
      &kPrivacyIndicatorsMicrophoneIcon, u"one two three", u"button 2");
  icon_label_slider_two_disabled->SetEnabled(false);

  grid_view->AddInstance(
      u"Icon tab slider with 2 buttons, recommended layout, selector \n"
      u"animation, and background",
      std::move(icon_slider_two));
  grid_view->AddInstance(
      u"Icon tab slider with 3 buttons, custom layout, no selector \n"
      u"animation, and no background",
      std::move(icon_slider_three));
  grid_view->AddInstance(u"Disabled icon slider with 2 buttons",
                         std::move(icon_slider_two_disabled));

  grid_view->AddInstance(
      u"Label tab slider with 2 buttons, recommended layout, selector \n"
      u"animation, background, and unevenly distributed spaces",
      std::move(label_slider_two_unevenly));
  grid_view->AddInstance(
      u"Label tab slider with 2 buttons, recommended layout, selector \n"
      u"animation, background, and evenly distributed space",
      std::move(label_slider_two));
  grid_view->AddInstance(
      u"Label tab slider with 3 buttons, recommended layout, selector \n"
      u"animation, background, and evenly distributed space",
      std::move(label_slider_three));

  grid_view->AddInstance(
      u"Icon + label tab slider with 2 buttons, recommended layout, selector \n"
      u"animation, background, and unevenly distributed space",
      std::move(icon_label_slider_two_unevenly));
  grid_view->AddInstance(
      u"Icon + label tab slider with 3 buttons, recommended layout, selector \n"
      u"animation, background, and evenly distributed space",
      std::move(icon_label_slider_three));
  grid_view->AddInstance(u"Disabled icon + label slider with 2 buttons",
                         std::move(icon_label_slider_two_disabled));

  return grid_view;
}

}  // namespace ash