[go: nahoru, domu]

blob: 1c9f57740534249948fe7d2d35c7b371237227d6 [file] [log] [blame]
Clara Bayarri5bace4e2020-02-06 16:42:21 +00001/*
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
17package androidx.ui.material.studies.rally
18
19import androidx.compose.Composable
20import androidx.ui.core.Modifier
21import androidx.ui.foundation.Box
22import androidx.ui.foundation.Clickable
23import androidx.ui.graphics.Color
24import androidx.ui.graphics.vector.DrawVector
25import androidx.ui.graphics.vector.VectorAsset
26import androidx.ui.layout.LayoutHeight
27import androidx.ui.layout.LayoutWidth
28import androidx.ui.material.ripple.Ripple
Clara Bayarri73725732020-02-12 18:27:38 +000029import androidx.ui.unit.Dp
Clara Bayarri5bace4e2020-02-06 16:42:21 +000030import androidx.ui.unit.dp
31
Clara Bayarri581b24d2020-02-10 16:15:28 +000032/**
33 * A button made with a 24x24dp icon
34 */
Clara Bayarri5bace4e2020-02-06 16:42:21 +000035@Composable
Clara Bayarri255d76a2020-02-12 12:23:09 +000036fun IconButton(
Clara Bayarri5bace4e2020-02-06 16:42:21 +000037 vectorImage: VectorAsset,
38 onClick: () -> Unit,
39 modifier: Modifier = Modifier.None
40) {
41 Box(modifier = modifier) {
42 Ripple(bounded = false) {
43 Clickable(onClick) {
Clara Bayarri255d76a2020-02-12 12:23:09 +000044 Icon(vectorImage)
Clara Bayarri5bace4e2020-02-06 16:42:21 +000045 }
46 }
47 }
Clara Bayarri581b24d2020-02-10 16:15:28 +000048}
49
50/**
51 * 24x24dp icon from a resource id.
52 */
53@Composable
Clara Bayarri73725732020-02-12 18:27:38 +000054fun Icon(
55 vectorImage: VectorAsset,
56 tintColor: Color = Color.White,
57 modifier: Modifier = Modifier.None,
58 size: Dp = 24.dp
59) {
60 Box(modifier = LayoutHeight(size) + LayoutWidth(size) + modifier) {
Clara Bayarri581b24d2020-02-10 16:15:28 +000061 DrawVector(
62 vectorImage = vectorImage,
63 tintColor = tintColor
64 )
65 }
Clara Bayarri5bace4e2020-02-06 16:42:21 +000066}