Browse Source

Merge pull request #305 from JetBrains/textfields

Textfields
pull/298/head
Roman Sedaikin 4 years ago committed by GitHub
parent
commit
a9bbe0b9cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt
  2. 9
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Color.kt
  3. 11
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Shape.kt
  4. 47
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Theme.kt
  5. 43
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Type.kt
  6. 9
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt
  7. 6
      examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/widgets/TextInputs.kt

8
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt

@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Surface
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.AnActionEvent
@ -12,6 +14,7 @@ import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.layout.panel import com.intellij.ui.layout.panel
import com.jetbrains.compose.theme.WidgetTheme
import com.jetbrains.compose.widgets.Buttons import com.jetbrains.compose.widgets.Buttons
import com.jetbrains.compose.widgets.LazyScrollable import com.jetbrains.compose.widgets.LazyScrollable
import com.jetbrains.compose.widgets.Loaders import com.jetbrains.compose.widgets.Loaders
@ -45,12 +48,15 @@ class ComposeDemoAction : DumbAwareAction() {
panel = this, panel = this,
preferredSize = IntSize(800, 600) preferredSize = IntSize(800, 600)
) { ) {
WidgetTheme(darkTheme = true) {
Surface(modifier = Modifier.fillMaxSize()) {
Row { Row {
Column( Column(
modifier = Modifier.fillMaxHeight().weight(1f) modifier = Modifier.fillMaxHeight().weight(1f)
) { ) {
Buttons() Buttons()
Loaders() Loaders()
TextInputs()
Toggles() Toggles()
} }
Box( Box(
@ -64,4 +70,6 @@ class ComposeDemoAction : DumbAwareAction() {
} }
} }
} }
}
}
} }

9
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Color.kt

@ -0,0 +1,9 @@
package com.jetbrains.compose.theme
import androidx.compose.ui.graphics.Color
val green200 = Color(0xffa5d6a7)
val green500 = Color(0xff4caf50)
val green700 = Color(0xff388e3c)
val teal200 = Color(0xff80deea)

11
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Shape.kt

@ -0,0 +1,11 @@
package com.jetbrains.compose.theme
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp
val shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)

47
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Theme.kt

@ -0,0 +1,47 @@
package com.jetbrains.compose.theme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
private val DarkGreenColorPalette = darkColors(
primary = green200,
primaryVariant = green700,
secondary = teal200,
background = Color.Black,
surface = Color(74, 74, 74),
onPrimary = Color.Black,
onSecondary = Color.White,
onBackground = Color.White,
onSurface = Color.White,
error = Color.Red,
)
private val LightGreenColorPalette = lightColors(
primary = green500,
primaryVariant = green700,
secondary = teal200,
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black
)
@Composable
fun WidgetTheme(
darkTheme: Boolean = false,
content: @Composable() () -> Unit,
) {
val colors = if (darkTheme) DarkGreenColorPalette else LightGreenColorPalette
MaterialTheme(
colors = colors,
typography = typography,
shapes = shapes,
content = content
)
}

43
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/theme/Type.kt

@ -0,0 +1,43 @@
package com.jetbrains.compose.theme
import androidx.compose.material.Typography
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
val typography = Typography(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
),
body2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp
),
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp,
),
subtitle1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
color = Color.Gray
),
subtitle2 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
color = Color.Gray
),
)

9
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/widgets/LazyScrollable.kt

@ -13,9 +13,11 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.rememberScrollbarAdapter import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.VerticalScrollbar import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -29,7 +31,6 @@ fun LazyScrollable() {
DesktopTheme { DesktopTheme {
Box( Box(
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
.background(color = Color(180, 180, 180))
.padding(10.dp) .padding(10.dp)
) { ) {
@ -57,13 +58,17 @@ fun LazyScrollable() {
@Composable @Composable
private fun TextBox(text: String = "Item") { private fun TextBox(text: String = "Item") {
Surface(
color = Color(135, 135, 135, 40),
shape = RoundedCornerShape(4.dp)
) {
Box( Box(
modifier = Modifier.height(32.dp) modifier = Modifier.height(32.dp)
.fillMaxWidth() .fillMaxWidth()
.background(color = Color(0, 0, 0, 20))
.padding(start = 10.dp), .padding(start = 10.dp),
contentAlignment = Alignment.CenterStart contentAlignment = Alignment.CenterStart
) { ) {
Text(text = text) Text(text = text)
} }
}
} }

6
examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/widgets/TextInputs.kt

@ -16,6 +16,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@Composable @Composable
@ -26,21 +28,21 @@ fun TextInputs() {
var name by remember { mutableStateOf(TextFieldValue("")) } var name by remember { mutableStateOf(TextFieldValue("")) }
var password by remember { mutableStateOf(TextFieldValue("")) } var password by remember { mutableStateOf(TextFieldValue("")) }
// TextInputs() // TODO: causes exceptions on Windows OS
TextField( TextField(
value = name, value = name,
onValueChange = { newValue -> name = newValue }, onValueChange = { newValue -> name = newValue },
modifier = Modifier.padding(8.dp).fillMaxWidth(), modifier = Modifier.padding(8.dp).fillMaxWidth(),
textStyle = TextStyle(fontFamily = FontFamily.SansSerif),
label = { Text("Account:") }, label = { Text("Account:") },
placeholder = { Text("account name") } placeholder = { Text("account name") }
) )
// TextInputs() // TODO: causes exceptions on Windows OS
OutlinedTextField( OutlinedTextField(
value = password, value = password,
modifier = Modifier.padding(8.dp).fillMaxWidth(), modifier = Modifier.padding(8.dp).fillMaxWidth(),
label = { Text(text = "Password:") }, label = { Text(text = "Password:") },
placeholder = { Text(text = "your password") }, placeholder = { Text(text = "your password") },
textStyle = TextStyle(fontFamily = FontFamily.SansSerif),
visualTransformation = PasswordVisualTransformation(), visualTransformation = PasswordVisualTransformation(),
onValueChange = { onValueChange = {
password = it password = it

Loading…
Cancel
Save