Skip to content

Commit

Permalink
Implement WindowsButton along with Typography and Theming
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsinghshubham777 committed Apr 6, 2024
1 parent 5ff0de1 commit bf24e95
Show file tree
Hide file tree
Showing 21 changed files with 1,483 additions and 926 deletions.
2 changes: 1 addition & 1 deletion adapt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 21
minSdk = 23
}
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
Expand Down

This file was deleted.

704 changes: 361 additions & 343 deletions adapt/src/androidMain/kotlin/design/adapt/previews/cupertino/Button.kt

Large diffs are not rendered by default.

154 changes: 154 additions & 0 deletions adapt/src/androidMain/kotlin/design/adapt/previews/winui/Button.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright 2023 Shubham Singh
*
* 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 design.adapt.previews.winui

import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.HoverInteraction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import design.adapt.R
import design.adapt.winui.WindowsButton
import design.adapt.winui.WindowsButtonIconSide
import design.adapt.winui.WindowsButtonSize
import design.adapt.winui.WindowsButtonStyle
import design.adapt.winui.WindowsIcon
import design.adapt.winui.WindowsText
import design.adapt.winui.WindowsTheme
import design.adapt.winui.darkWindowsColorScheme
import design.adapt.winui.lightWindowsColorScheme

@Preview(device = "spec:width=1080px,height=5000px,dpi=440")
@Composable
private fun LightButtons() {
WindowsTheme(
colorScheme = lightWindowsColorScheme(),
content = {
Box(
modifier = Modifier
.fillMaxSize()
.background(color = Color(0xFFFAFAFA))
) {
WindowsButtonPreviews()
}
},
)
}

@Preview(device = "spec:width=1080px,height=5000px,dpi=440")
@Composable
private fun DarkButtons() {
WindowsTheme(
colorScheme = darkWindowsColorScheme(),
content = {
Box(
modifier = Modifier
.fillMaxSize()
.background(color = Color(0xFF1C1C1C))
) {
WindowsButtonPreviews()
}
},
)
}

@Composable
private fun WindowsButtonPreviews() {
val text = remember {
movableContentOf { WindowsText(text = "Text") }
}

val icon = remember {
movableContentOf {
WindowsIcon(
modifier = Modifier.size(21.dp),
painter = painterResource(id = R.drawable.ic_checkbox_circle),
contentDescription = null,
)
}
}

val hoveredInteractionSource = remember {
MutableInteractionSource().apply {
tryEmit(HoverInteraction.Enter())
}
}

val commonColumn: @Composable (@Composable ColumnScope.() -> Unit) -> Unit = remember {
movableContentOf { content ->
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(72.dp),
content = content,
)
}
}

Row {
// Rest Buttons
commonColumn {
WindowsButton(onClick = {}, text = text, style = WindowsButtonStyle.Accent)
WindowsButton(onClick = {}, text = text, style = WindowsButtonStyle.Standard)
WindowsButton(onClick = {}, text = text, style = WindowsButtonStyle.Subtle)
WindowsButton(onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Accent, iconSide = WindowsButtonIconSide.Start)
WindowsButton(onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Accent, iconSide = WindowsButtonIconSide.End)
WindowsButton(onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Standard, iconSide = WindowsButtonIconSide.Start)
WindowsButton(onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Standard, iconSide = WindowsButtonIconSide.End)
WindowsButton(onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Subtle, iconSide = WindowsButtonIconSide.Start)
WindowsButton(onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Subtle, iconSide = WindowsButtonIconSide.End)
WindowsButton(onClick = {}, icon = icon, style = WindowsButtonStyle.Standard)
WindowsButton(onClick = {}, icon = icon, style = WindowsButtonStyle.Subtle)
WindowsButton(onClick = {}, text = text, style = WindowsButtonStyle.Standard, size = WindowsButtonSize.Compact)
}

// Disabled Buttons
commonColumn {
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, style = WindowsButtonStyle.Accent)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, style = WindowsButtonStyle.Standard)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, style = WindowsButtonStyle.Subtle)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Accent, iconSide = WindowsButtonIconSide.Start)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Accent, iconSide = WindowsButtonIconSide.End)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Standard, iconSide = WindowsButtonIconSide.Start)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Standard, iconSide = WindowsButtonIconSide.End)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Subtle, iconSide = WindowsButtonIconSide.Start)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, icon = icon, style = WindowsButtonStyle.Subtle, iconSide = WindowsButtonIconSide.End)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, icon = icon, style = WindowsButtonStyle.Standard)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, icon = icon, style = WindowsButtonStyle.Subtle)
WindowsButton(enabled = false, interactionSource = hoveredInteractionSource, onClick = {}, text = text, style = WindowsButtonStyle.Standard, size = WindowsButtonSize.Compact)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package design.adapt

// TODO: Learn how to write UI tests for common module's composables
class WindowsButtonTest {
}
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle

val LocalContentColor = compositionLocalOf { Color.Black }
val LocalTextStyle = compositionLocalOf { TextStyle() }
Loading

0 comments on commit bf24e95

Please sign in to comment.