[go: nahoru, domu]

blob: cd7951720a474729833d19dadea3bb8ca75ee6e9 [file] [log] [blame]
Mihai Popab09b65c2019-10-14 13:04:21 +01001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.ui.layout.samples
18
19import androidx.compose.Composable
Mihai Popab09b65c2019-10-14 13:04:21 +010020import androidx.ui.core.Layout
21import androidx.ui.core.Modifier
Anastasia Soboleva2983fc42019-11-01 18:15:23 +000022import androidx.ui.core.VerticalAlignmentLine
Matvei Malkov59bac362020-02-13 20:23:13 +000023import androidx.ui.foundation.DrawBackground
Mihai Popab09b65c2019-10-14 13:04:21 +010024import androidx.ui.graphics.Color
George Mount842c8c12020-01-08 16:03:42 -080025import androidx.ui.unit.Dp
26import androidx.ui.unit.ipx
27import androidx.ui.unit.max
28import androidx.ui.unit.min
Mihai Popab09b65c2019-10-14 13:04:21 +010029
30/**
Matvei Malkov59bac362020-02-13 20:23:13 +000031 * Rect with two alignment lines [Start] and [End].
Mihai Popab09b65c2019-10-14 13:04:21 +010032 */
Matvei Malkov59bac362020-02-13 20:23:13 +000033// TODO (popam): remove this and make FlexSamples where it's being used copy-pastable
Anastasia Soboleva2983fc42019-11-01 18:15:23 +000034@Composable
35fun SizedRectangleWithLines(
36 modifier: Modifier = Modifier.None,
37 color: Color,
38 width: Dp? = null,
39 height: Dp? = null
40) {
Anastasia Soboleva9474ff82020-02-19 19:02:15 +000041 Layout(
42 children = { },
43 modifier = modifier + DrawBackground(color = color)
44 ) { _, constraints, _ ->
Anastasia Soboleva2983fc42019-11-01 18:15:23 +000045 val widthPx = max(width?.toIntPx() ?: constraints.maxWidth, constraints.minWidth)
46 val heightPx = max(height?.toIntPx() ?: constraints.maxHeight, constraints.minHeight)
47 layout(widthPx, heightPx, mapOf(Start to 0.ipx, End to widthPx)) {}
48 }
49}
50
51/**
Anastasia Soboleva2983fc42019-11-01 18:15:23 +000052 * Alignment lines for [SizedRectangleWithLines].
53 */
54internal val Start = VerticalAlignmentLine(::min)
55internal val End = VerticalAlignmentLine(::min)