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.compose.foundation
18
19 import androidx.compose.runtime.Immutable
20 import androidx.compose.runtime.Stable
21 import androidx.compose.ui.graphics.Brush
22 import androidx.compose.ui.graphics.Color
23 import androidx.compose.ui.graphics.SolidColor
24 import androidx.compose.ui.unit.Dp
25
26 /**
27 * Class to specify the stroke to draw border with.
28 *
29 * @param width width of the border in [Dp]. Use [Dp.Hairline] for one-pixel border.
30 * @param brush brush to paint the border with
31 */
32 @Immutable
33 class BorderStroke(val width: Dp, val brush: Brush) {
equalsnull34 override fun equals(other: Any?): Boolean {
35 if (this === other) return true
36 if (other !is BorderStroke) return false
37
38 if (width != other.width) return false
39 if (brush != other.brush) return false
40
41 return true
42 }
43
hashCodenull44 override fun hashCode(): Int {
45 var result = width.hashCode()
46 result = 31 * result + brush.hashCode()
47 return result
48 }
49
toStringnull50 override fun toString(): String {
51 return "BorderStroke(width=$width, brush=$brush)"
52 }
53
copynull54 fun copy(width: Dp = this.width, brush: Brush = this.brush): BorderStroke {
55 return BorderStroke(width = width, brush = brush)
56 }
57 }
58
59 /**
60 * Create [BorderStroke] class with width and [Color]
61 *
62 * @param width width of the border in [Dp]. Use [Dp.Hairline] for one-pixel border.
63 * @param color color to paint the border with
64 */
BorderStrokenull65 @Stable fun BorderStroke(width: Dp, color: Color) = BorderStroke(width, SolidColor(color))
66