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
ash / style / style_viewer / checkbox_group_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/style/checkbox.h"
#include "ash/style/checkbox_group.h"
#include "ash/style/style_viewer/system_ui_components_grid_view.h"
namespace ash {
namespace {
// Conigure of grid view for `CheckboxGroup` instances. We have 3 instances in
// one column.
constexpr size_t kGridViewRowNum = 3;
constexpr size_t kGridViewColNum = 1;
constexpr size_t kGridViewRowGroupSize = 3;
constexpr size_t kGirdViewColGroupSize = 1;
constexpr int kCheckboxGroupWidth = 198;
} // namespace
std::unique_ptr<SystemUIComponentsGridView>
CreateCheckboxGroupInstancesGridView() {
auto grid_view = std::make_unique<SystemUIComponentsGridView>(
kGridViewRowNum, kGridViewColNum, kGridViewRowGroupSize,
kGirdViewColGroupSize);
// A normal checkbox group with 4 options.
std::unique_ptr<CheckboxGroup> checkbox_group =
std::make_unique<CheckboxGroup>(kCheckboxGroupWidth);
checkbox_group->AddButton(Checkbox::PressedCallback(), u"Test Button1");
checkbox_group->AddButton(Checkbox::PressedCallback(), u"Test Button2");
checkbox_group->AddButton(Checkbox::PressedCallback(), u"Test Button3");
checkbox_group->AddButton(Checkbox::PressedCallback(), u"Test Button4");
// A checkbox group with 4 options and the third one is disabled.
std::unique_ptr<CheckboxGroup> checkbox_group_with_disabled_button =
std::make_unique<CheckboxGroup>(
kCheckboxGroupWidth,
/*inside_border_insets=*/gfx::Insets(2),
/*between_child_spacing=*/2,
/*checkbox_padding*/ gfx::Insets::TLBR(8, 24, 8, 12),
/*image_label_spacing=*/16);
checkbox_group_with_disabled_button->AddButton(Checkbox::PressedCallback(),
u"Test Button1");
checkbox_group_with_disabled_button->AddButton(Checkbox::PressedCallback(),
u"Test Button2");
auto* disabel_buttton = checkbox_group_with_disabled_button->AddButton(
Checkbox::PressedCallback(), u"Test Button3");
disabel_buttton->SetEnabled(false);
checkbox_group_with_disabled_button->AddButton(Checkbox::PressedCallback(),
u"Test Button4");
// A checkbox group with 4 options and all options are disabled.
std::unique_ptr<CheckboxGroup> disabled_checkbox_group =
std::make_unique<CheckboxGroup>(kCheckboxGroupWidth);
disabled_checkbox_group->AddButton(Checkbox::PressedCallback(),
u"Test Button1");
auto* button = disabled_checkbox_group->AddButton(Checkbox::PressedCallback(),
u"Test Button2");
button->SetSelected(true);
disabled_checkbox_group->AddButton(Checkbox::PressedCallback(),
u"Test Button3");
disabled_checkbox_group->AddButton(Checkbox::PressedCallback(),
u"Test Button4");
disabled_checkbox_group->SetEnabled(false);
grid_view->AddInstance(u"CheckboxGroup with default layout",
std::move(checkbox_group));
grid_view->AddInstance(
u"CheckboxGroup with customized layout and a disabled button",
std::move(checkbox_group_with_disabled_button));
grid_view->AddInstance(u"Disabled CheckboxGroup with default layout",
std::move(disabled_checkbox_group));
return grid_view;
}
} // namespace ash