Warning, /network/kdeconnect-android/src/org/kde/kdeconnect/UserInterface/compose/Buttons.kt is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Dmitry Yudin <dgyudin@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect.UserInterface.compose 0008 0009 import androidx.compose.foundation.layout.PaddingValues 0010 import androidx.compose.foundation.layout.Spacer 0011 import androidx.compose.foundation.layout.width 0012 import androidx.compose.foundation.shape.RoundedCornerShape 0013 import androidx.compose.material.icons.Icons 0014 import androidx.compose.material.icons.filled.Build 0015 import androidx.compose.material3.* 0016 import androidx.compose.runtime.Composable 0017 import androidx.compose.ui.Modifier 0018 import androidx.compose.ui.graphics.Color 0019 import androidx.compose.ui.graphics.vector.ImageVector 0020 import androidx.compose.ui.text.style.TextOverflow.Companion.Ellipsis 0021 import androidx.compose.ui.tooling.preview.Preview 0022 import androidx.compose.ui.unit.dp 0023 0024 @Composable 0025 fun KdeTextButton( 0026 onClick: () -> Unit, 0027 modifier: Modifier, 0028 text: String, 0029 enabled: Boolean = true, 0030 contentPadding: PaddingValues = PaddingValues(16.dp), 0031 iconLeft: ImageVector? = null, 0032 ) { 0033 TextButton( 0034 onClick = onClick, 0035 modifier = modifier, 0036 enabled = enabled, 0037 contentPadding = contentPadding, 0038 content = { 0039 iconLeft?.let { 0040 Icon(imageVector = it, contentDescription = null) 0041 Spacer(Modifier.width(16.dp)) 0042 } 0043 Text(text = text) 0044 } 0045 ) 0046 } 0047 0048 @Composable 0049 fun KdeButton( 0050 onClick: () -> Unit, 0051 modifier: Modifier = Modifier, 0052 colors: ButtonColors = ButtonDefaults.buttonColors(), 0053 text: String? = null, 0054 icon: ImageVector? = null, 0055 ) { 0056 //TODO uncomment when button is widely used 0057 // val interactionSource = remember { MutableInteractionSource() } 0058 // val pressedState = interactionSource.collectIsPressedAsState() 0059 // val cornerSize by animateDpAsState( 0060 // targetValue = if (pressedState.value) 24.dp else 48.dp, 0061 // label = "Corner size change on press" 0062 // ) 0063 0064 Button( 0065 onClick = onClick, 0066 modifier = modifier, 0067 // shape = RoundedCornerShape(cornerSize), 0068 shape = RoundedCornerShape(24.dp), 0069 colors = colors, 0070 // interactionSource = interactionSource, 0071 content = { 0072 icon?.let { Icon(imageVector = it, contentDescription = text) } 0073 text?.let { Text(it, maxLines = 1, overflow = Ellipsis) } 0074 } 0075 ) 0076 } 0077 0078 @Preview 0079 @Composable 0080 fun IconButtonPreview() { 0081 KdeButton( 0082 {}, 0083 Modifier.width(120.dp), 0084 ButtonDefaults.buttonColors(Color.Gray, Color.DarkGray), 0085 "Button Text", 0086 Icons.Default.Build, 0087 ) 0088 }