xref: /aosp_15_r20/external/perfetto/ui/src/components/tracks/slice_layout.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1// Copyright (C) 2021 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15export interface SliceLayoutBase {
16  readonly padding: number; // vertical pixel padding between slices and track.
17  readonly rowSpacing: number; // Spacing between rows.
18
19  // A *guess* at the depth
20  readonly depthGuess?: number;
21
22  // True iff the track is flat (all slices have the same depth
23  // we have an optimisation for this).
24  readonly isFlat?: boolean;
25
26  readonly titleSizePx?: number;
27  readonly subtitleSizePx?: number;
28}
29
30export const SLICE_LAYOUT_BASE_DEFAULTS: SliceLayoutBase = Object.freeze({
31  padding: 3,
32  rowSpacing: 0,
33});
34
35export interface SliceLayoutFixed extends SliceLayoutBase {
36  readonly heightMode: 'FIXED';
37  readonly fixedHeight: number; // Outer height of the track.
38}
39
40export const SLICE_LAYOUT_FIXED_DEFAULTS: SliceLayoutFixed = Object.freeze({
41  ...SLICE_LAYOUT_BASE_DEFAULTS,
42  heightMode: 'FIXED',
43  fixedHeight: 30,
44});
45
46export interface SliceLayoutFitContent extends SliceLayoutBase {
47  readonly heightMode: 'FIT_CONTENT';
48  readonly sliceHeight: number; // Only when heightMode = 'FIT_CONTENT'.
49}
50
51export const SLICE_LAYOUT_FIT_CONTENT_DEFAULTS: SliceLayoutFitContent =
52  Object.freeze({
53    ...SLICE_LAYOUT_BASE_DEFAULTS,
54    heightMode: 'FIT_CONTENT',
55    sliceHeight: 18,
56  });
57
58export interface SliceLayoutFlat extends SliceLayoutBase {
59  readonly heightMode: 'FIXED';
60  readonly fixedHeight: number; // Outer height of the track.
61  readonly depthGuess: 0;
62  readonly isFlat: true;
63}
64
65export const SLICE_LAYOUT_FLAT_DEFAULTS: SliceLayoutFlat = Object.freeze({
66  ...SLICE_LAYOUT_BASE_DEFAULTS,
67  depthGuess: 0,
68  isFlat: true,
69  heightMode: 'FIXED',
70  fixedHeight: 18,
71  titleSizePx: 10,
72  padding: 3,
73});
74
75export type SliceLayout =
76  | SliceLayoutFixed
77  | SliceLayoutFitContent
78  | SliceLayoutFlat;
79
80export const DEFAULT_SLICE_LAYOUT: SliceLayout =
81  SLICE_LAYOUT_FIT_CONTENT_DEFAULTS;
82