Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
| 17 | package androidx.ui.material.studies.rally |
| 18 | |
| 19 | import androidx.compose.Composable |
| 20 | import androidx.ui.core.Modifier |
Nader Jawad | 4dd1188 | 2020-03-09 18:22:06 -0700 | [diff] [blame^] | 21 | import androidx.ui.core.asModifier |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 22 | import androidx.ui.foundation.Box |
| 23 | import androidx.ui.foundation.Clickable |
| 24 | import androidx.ui.graphics.Color |
Nader Jawad | 4dd1188 | 2020-03-09 18:22:06 -0700 | [diff] [blame^] | 25 | import androidx.ui.graphics.ColorFilter |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 26 | import androidx.ui.graphics.vector.VectorAsset |
Nader Jawad | 4dd1188 | 2020-03-09 18:22:06 -0700 | [diff] [blame^] | 27 | import androidx.ui.graphics.vector.VectorPainter |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 28 | import androidx.ui.layout.LayoutHeight |
| 29 | import androidx.ui.layout.LayoutWidth |
| 30 | import androidx.ui.material.ripple.Ripple |
Clara Bayarri | 7372573 | 2020-02-12 18:27:38 +0000 | [diff] [blame] | 31 | import androidx.ui.unit.Dp |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 32 | import androidx.ui.unit.dp |
| 33 | |
Clara Bayarri | 581b24d | 2020-02-10 16:15:28 +0000 | [diff] [blame] | 34 | /** |
| 35 | * A button made with a 24x24dp icon |
| 36 | */ |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 37 | @Composable |
Clara Bayarri | 255d76a | 2020-02-12 12:23:09 +0000 | [diff] [blame] | 38 | fun IconButton( |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 39 | vectorImage: VectorAsset, |
| 40 | onClick: () -> Unit, |
| 41 | modifier: Modifier = Modifier.None |
| 42 | ) { |
| 43 | Box(modifier = modifier) { |
| 44 | Ripple(bounded = false) { |
| 45 | Clickable(onClick) { |
Clara Bayarri | 255d76a | 2020-02-12 12:23:09 +0000 | [diff] [blame] | 46 | Icon(vectorImage) |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | } |
Clara Bayarri | 581b24d | 2020-02-10 16:15:28 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
| 53 | * 24x24dp icon from a resource id. |
| 54 | */ |
| 55 | @Composable |
Clara Bayarri | 7372573 | 2020-02-12 18:27:38 +0000 | [diff] [blame] | 56 | fun Icon( |
| 57 | vectorImage: VectorAsset, |
| 58 | tintColor: Color = Color.White, |
| 59 | modifier: Modifier = Modifier.None, |
| 60 | size: Dp = 24.dp |
| 61 | ) { |
George Mount | 11777a5 | 2020-02-29 14:04:22 -0800 | [diff] [blame] | 62 | Box( |
| 63 | modifier = LayoutHeight(size) + LayoutWidth(size) + modifier + |
Nader Jawad | 4dd1188 | 2020-03-09 18:22:06 -0700 | [diff] [blame^] | 64 | VectorPainter(vectorImage).asModifier( |
| 65 | colorFilter = ColorFilter.tint(tintColor) |
George Mount | 11777a5 | 2020-02-29 14:04:22 -0800 | [diff] [blame] | 66 | ) |
| 67 | ) |
Clara Bayarri | 5bace4e | 2020-02-06 16:42:21 +0000 | [diff] [blame] | 68 | } |