blob: 2113a276ba139c07a4f013ec548b53bd028d1ca9 [file] [log] [blame]
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.wear.compose.material3
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
/**
* Icon component that draws [imageVector] using [tint], defaulting to [LocalContentColor]. For a
* clickable icon, see Button.
*
* @param imageVector [ImageVector] to draw inside this Icon
* @param contentDescription Text used by accessibility services to describe what this icon
* represents. This should always be provided unless this icon is used for decorative purposes,
* and does not represent a meaningful action that a user can take. This text should be
* localized, such as by using [androidx.compose.ui.res.stringResource] or similar
* @param modifier Optional [Modifier] for this Icon
* @param tint Tint to be applied to [imageVector]. If [Color.Unspecified] is provided, then no
* tint is applied
*/
@Composable
fun Icon(
imageVector: ImageVector,
contentDescription: String?,
modifier: Modifier = Modifier,
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
) {
Icon(
painter = rememberVectorPainter(imageVector),
contentDescription = contentDescription,
modifier = modifier,
tint = tint
)
}
/**
* Icon component that draws [bitmap] using [tint], defaulting to [LocalContentColor]. For a
* clickable icon, see Button.
*
* @param bitmap [ImageBitmap] to draw inside this Icon
* @param contentDescription Text used by accessibility services to describe what this icon
* represents. This should always be provided unless this icon is used for decorative purposes,
* and does not represent a meaningful action that a user can take. This text should be
* localized, such as by using [androidx.compose.ui.res.stringResource] or similar
* @param modifier Optional [Modifier] for this Icon
* @param tint Tint to be applied to [bitmap]. If [Color.Unspecified] is provided, then no
* tint is applied
*/
@Composable
fun Icon(
bitmap: ImageBitmap,
contentDescription: String?,
modifier: Modifier = Modifier,
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
) {
val painter = remember(bitmap) { BitmapPainter(bitmap) }
Icon(
painter = painter,
contentDescription = contentDescription,
modifier = modifier,
tint = tint
)
}
/**
* Icon component that draws a [painter] using [tint], defaulting to [LocalContentColor]. For a
* clickable icon, see Button.
*
* @param painter [Painter] to draw inside this Icon
* @param contentDescription Text used by accessibility services to describe what this icon
* represents. This should always be provided unless this icon is used for decorative purposes,
* and does not represent a meaningful action that a user can take. This text should be
* localized, such as by using [androidx.compose.ui.res.stringResource] or similar
* @param modifier Optional [Modifier] for this Icon
* @param tint Tint to be applied to [painter]. If [Color.Unspecified] is provided, then no
* tint is applied
*/
@Composable
fun Icon(
painter: Painter,
contentDescription: String?,
modifier: Modifier = Modifier,
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
) {
androidx.wear.compose.materialcore.Icon(
painter = painter,
contentDescription = contentDescription,
tint = tint,
modifier = modifier
)
}