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.foundation.shape 18 19 import androidx.compose.ui.geometry.Size 20 import androidx.compose.ui.graphics.Outline 21 import androidx.compose.ui.graphics.Path 22 import androidx.compose.ui.graphics.Shape 23 import androidx.compose.ui.unit.Density 24 import androidx.compose.ui.unit.LayoutDirection 25 26 /** 27 * Creates [Shape] defined by applying the provided [builder] on a [Path]. 28 * 29 * @param builder the builder lambda to apply on a [Path] 30 */ 31 class GenericShape( 32 private val builder: Path.(size: Size, layoutDirection: LayoutDirection) -> Unit 33 ) : Shape { 34 createOutlinenull35 override fun createOutline( 36 size: Size, 37 layoutDirection: LayoutDirection, 38 density: Density 39 ): Outline { 40 val path = 41 Path().apply { 42 builder(size, layoutDirection) 43 close() 44 } 45 return Outline.Generic(path) 46 } 47 equalsnull48 override fun equals(other: Any?): Boolean { 49 if (this === other) return true 50 return (other as? GenericShape)?.builder === builder 51 } 52 hashCodenull53 override fun hashCode(): Int { 54 return builder.hashCode() 55 } 56 } 57