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
17 package androidx.compose.material
18
19 import androidx.compose.foundation.shape.CornerBasedShape
20 import androidx.compose.foundation.shape.RoundedCornerShape
21 import androidx.compose.runtime.Immutable
22 import androidx.compose.runtime.staticCompositionLocalOf
23 import androidx.compose.ui.unit.dp
24
25 /**
26 * [Material Design shape](https://material.io/design/shape/about-shape.html)
27 *
28 * Material surfaces can be displayed in different shapes. Shapes direct attention, identify
29 * components, communicate state, and express brand.
30 *
31 * 
33 *
34 * Components are grouped into shape categories based on their size. These categories provide a way
35 * to change multiple component values at once, by changing the category’s values. Shape categories
36 * include:
37 * - Small components
38 * - Medium components
39 * - Large components
40 *
41 * See [Material shape specification](https://material.io/design/shape/applying-shape-to-ui.html)
42 */
43 @Immutable
44 class Shapes(
45 /**
46 * Shape used by small components like [Button] or [Snackbar]. Components like
47 * [FloatingActionButton], [ExtendedFloatingActionButton] use this shape, but override the
48 * corner size to be 50%. [TextField] uses this shape with overriding the bottom corners to
49 * zero.
50 */
51 val small: CornerBasedShape = RoundedCornerShape(4.dp),
52 /** Shape used by medium components like [Card] or [AlertDialog]. */
53 val medium: CornerBasedShape = RoundedCornerShape(4.dp),
54 /** Shape used by large components like [ModalDrawer] or [ModalBottomSheetLayout]. */
55 val large: CornerBasedShape = RoundedCornerShape(0.dp)
56 ) {
57
58 /** Returns a copy of this Shapes, optionally overriding some of the values. */
copynull59 fun copy(
60 small: CornerBasedShape = this.small,
61 medium: CornerBasedShape = this.medium,
62 large: CornerBasedShape = this.large
63 ): Shapes = Shapes(small = small, medium = medium, large = large)
64
65 override fun equals(other: Any?): Boolean {
66 if (this === other) return true
67 if (other !is Shapes) return false
68
69 if (small != other.small) return false
70 if (medium != other.medium) return false
71 if (large != other.large) return false
72
73 return true
74 }
75
hashCodenull76 override fun hashCode(): Int {
77 var result = small.hashCode()
78 result = 31 * result + medium.hashCode()
79 result = 31 * result + large.hashCode()
80 return result
81 }
82
toStringnull83 override fun toString(): String {
84 return "Shapes(small=$small, medium=$medium, large=$large)"
85 }
86 }
87
88 /** CompositionLocal used to specify the default shapes for the surfaces. */
<lambda>null89 internal val LocalShapes = staticCompositionLocalOf { Shapes() }
90