• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  padding: number;     // top/bottom pixel padding between slices and track.
17  rowSpacing: number;  // Spacing between rows.
18  minDepth: number;    // Minimum depth a slice can be (normally zero)
19  // Maximum depth a slice can be plus 1 (a half open range with minDepth).
20  // We have a optimization for when maxDepth - minDepth == 1 so it is useful
21  // to set this correctly:
22  maxDepth: number;
23}
24
25export const SLICE_LAYOUT_BASE_DEFAULTS: SliceLayoutBase = Object.freeze({
26  padding: 3,
27  rowSpacing: 0,
28  minDepth: 0,
29  // A realistic bound to avoid tracks with unlimited height. If somebody wants
30  // extremely deep tracks they need to change this explicitly.
31  maxDepth: 128,
32});
33
34export interface SliceLayoutFixed extends SliceLayoutBase {
35  heightMode: 'FIXED';
36  fixedHeight: number;  // Outer height of the track.
37}
38
39export const SLICE_LAYOUT_FIXED_DEFAULTS: SliceLayoutFixed = Object.freeze({
40  ...SLICE_LAYOUT_BASE_DEFAULTS,
41  heightMode: 'FIXED',
42  fixedHeight: 30,
43});
44
45export interface SliceLayoutFitContent extends SliceLayoutBase {
46  heightMode: 'FIT_CONTENT';
47  sliceHeight: number;  // Only when heightMode = 'FIT_CONTENT'.
48}
49
50export const SLICE_LAYOUT_FIT_CONTENT_DEFAULTS: SliceLayoutFitContent =
51    Object.freeze({
52      ...SLICE_LAYOUT_BASE_DEFAULTS,
53      heightMode: 'FIT_CONTENT',
54      sliceHeight: 18,
55    });
56
57export interface SliceLayoutFlat extends SliceLayoutBase {
58  heightMode: 'FIXED';
59  fixedHeight: number;  // Outer height of the track.
60  minDepth: 0;
61  maxDepth: 1;
62}
63
64export const SLICE_LAYOUT_FLAT_DEFAULTS: SliceLayoutFlat = Object.freeze({
65  ...SLICE_LAYOUT_BASE_DEFAULTS,
66  minDepth: 0,
67  maxDepth: 1,
68  heightMode: 'FIXED',
69  fixedHeight: 30,
70});
71
72export type SliceLayout =
73    SliceLayoutFixed|SliceLayoutFitContent|SliceLayoutFlat;
74
75export const DEFAULT_SLICE_LAYOUT: SliceLayout =
76    SLICE_LAYOUT_FIT_CONTENT_DEFAULTS;
77