Mihai Popa | f4b6020 | 2019-07-05 18:53:39 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 17 | package androidx.compose.foundation.layout.samples |
Mihai Popa | f4b6020 | 2019-07-05 18:53:39 +0100 | [diff] [blame] | 18 | |
| 19 | import androidx.annotation.Sampled |
| 20 | import androidx.compose.Composable |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 21 | import androidx.ui.core.Alignment |
| 22 | import androidx.ui.core.Modifier |
Louis Pullen-Freilich | ddda7be | 2020-07-17 18:28:12 +0100 | [diff] [blame] | 23 | import androidx.compose.foundation.Box |
Louis Pullen-Freilich | 4dc4dac | 2020-07-22 14:39:14 +0100 | [diff] [blame^] | 24 | import androidx.compose.ui.graphics.Color |
Louis Pullen-Freilich | 623e405 | 2020-07-19 20:24:03 +0100 | [diff] [blame] | 25 | import androidx.compose.foundation.layout.Stack |
| 26 | import androidx.compose.foundation.layout.fillMaxSize |
| 27 | import androidx.compose.foundation.layout.padding |
| 28 | import androidx.compose.foundation.layout.preferredSize |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 29 | import androidx.ui.unit.dp |
Mihai Popa | f4b6020 | 2019-07-05 18:53:39 +0100 | [diff] [blame] | 30 | |
| 31 | @Sampled |
| 32 | @Composable |
| 33 | fun SimpleStack() { |
| 34 | Stack { |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 35 | Box(Modifier.fillMaxSize(), backgroundColor = Color.Cyan) |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 36 | Box( |
Adam Powell | 1899fa9 | 2020-04-02 11:05:15 -0700 | [diff] [blame] | 37 | Modifier.matchParentSize().padding(top = 20.dp, bottom = 20.dp), |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 38 | backgroundColor = Color.Yellow |
Anastasia Soboleva | d7779a2 | 2019-11-21 16:34:26 +0000 | [diff] [blame] | 39 | ) |
Adam Powell | 1899fa9 | 2020-04-02 11:05:15 -0700 | [diff] [blame] | 40 | Box(Modifier.matchParentSize().padding(40.dp), backgroundColor = Color.Magenta) |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 41 | Box( |
Adam Powell | 999a89b | 2020-03-11 09:08:07 -0700 | [diff] [blame] | 42 | Modifier.gravity(Alignment.Center).preferredSize(300.dp, 300.dp), |
| 43 | backgroundColor = Color.Green |
| 44 | ) |
| 45 | Box( |
| 46 | Modifier.gravity(Alignment.TopStart).preferredSize(150.dp, 150.dp), |
| 47 | backgroundColor = Color.Red |
| 48 | ) |
| 49 | Box( |
| 50 | Modifier.gravity(Alignment.BottomEnd).preferredSize(150.dp, 150.dp), |
Matvei Malkov | 59bac36 | 2020-02-13 20:23:13 +0000 | [diff] [blame] | 51 | backgroundColor = Color.Blue |
Anastasia Soboleva | d7779a2 | 2019-11-21 16:34:26 +0000 | [diff] [blame] | 52 | ) |
Mihai Popa | f4b6020 | 2019-07-05 18:53:39 +0100 | [diff] [blame] | 53 | } |
| 54 | } |