Skip to content

Commit

Permalink
Cleanup code and styling
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed May 24, 2022
1 parent b3afaa4 commit 66919d6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontSynthesis
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.platform.Typeface
import androidx.compose.ui.unit.TextUnit
Expand Down Expand Up @@ -130,7 +131,8 @@ suspend fun retrieveFont(
fontWeight = FontWeight.Normal,
fontFamily = FontFamily(Typeface(typeface)),
// todo textDecoration might be defined in the awt theme
lineHeight = lineHeight
lineHeight = lineHeight,
fontSynthesis = FontSynthesis.None // TODO remove this, for testing only
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import com.intellij.openapi.wm.ToolWindow
fun ToolWindow.addComposePanel(
displayName: String,
isLockable: Boolean = true,
isCloseable: Boolean = true,
content: @Composable ComposePanel.() -> Unit
) = ComposePanel(content = content)
.also { contentManager.addContent(contentManager.factory.createContent(it, displayName, isLockable)) }
): ComposePanel {
val composePanel = ComposePanel(content = content)
val panel = contentManager.factory.createContent(composePanel, displayName, isLockable)
panel.isCloseable = isCloseable
contentManager.addContent(panel)
return composePanel
}

internal fun ComposePanel(
height: Int = 800,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.intellij.icons.AllIcons
Expand Down Expand Up @@ -159,21 +160,21 @@ suspend fun CurrentIntelliJThemeDefinition(): IntelliJThemeDefinition {
)
)

val baseTextStyle = retrieveFont("Label.font", palette.text)
val baseTextStyle = retrieveFont(key = "Label.font", color = palette.text)

fun TextStyle.scaleFont(amount: Float): TextStyle {
val size = this.fontSize.value
return this.copy(
fontSize = (size + amount).sp
)
val size = fontSize.value
return copy(fontSize = (size + amount).sp)
}

fun TextStyle.withWeight(weight: FontWeight) = copy(fontWeight = weight)

val typography = IntelliJTypography(
h0 = baseTextStyle.scaleFont(12f),
h1 = baseTextStyle.scaleFont(9f),
h0 = baseTextStyle.scaleFont(12f).withWeight(FontWeight.Bold),
h1 = baseTextStyle.scaleFont(9f).withWeight(FontWeight.Bold),
h2 = baseTextStyle.scaleFont(5f),
h3 = baseTextStyle.scaleFont(3f),
h4 = baseTextStyle,
h4 = baseTextStyle.withWeight(FontWeight.Bold),
default = baseTextStyle,
medium = baseTextStyle.scaleFont(-1f),
small = baseTextStyle.scaleFont(-2f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.SwingPanel
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -52,9 +51,8 @@ internal class JewelDemoToolWindow : ToolWindowFactory, DumbAware {
Enabled, Disabled, Automatic, Unavailable
}

@OptIn(ExperimentalComposeUiApi::class)
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
toolWindow.addComposePanel("Compose Demo") {
toolWindow.addComposePanel("Compose Demo", isCloseable = false) {
IntelliJTheme(this) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -134,7 +132,7 @@ internal class JewelDemoToolWindow : ToolWindowFactory, DumbAware {
}
}
}
toolWindow.addComposePanel("Compose Demo 2") {
toolWindow.addComposePanel("Compose Demo 2", isCloseable = false) {
IntelliJTheme(this) {
Box(
modifier = Modifier
Expand All @@ -157,7 +155,7 @@ internal class JewelDemoToolWindow : ToolWindowFactory, DumbAware {
}
}

toolWindow.addComposePanel("Text rendering comparison") {
toolWindow.addComposePanel("Text rendering comparison", isCloseable = false) {
val sampleText = "Lorem ipsum 1234567890"
IntelliJTheme(this) {
Row(
Expand Down Expand Up @@ -214,13 +212,13 @@ internal class JewelDemoToolWindow : ToolWindowFactory, DumbAware {
modifier = colModifiers,
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
TypeRow("H0", IntelliJTheme.typography.h0.copy(fontWeight = FontWeight.Bold))
TypeRow("H1", IntelliJTheme.typography.h1.copy(fontWeight = FontWeight.Bold))
TypeRow("H0", IntelliJTheme.typography.h0)
TypeRow("H1", IntelliJTheme.typography.h1)
TypeRow("H2", IntelliJTheme.typography.h2)
TypeRow("H2 Bold", IntelliJTheme.typography.h2.copy(fontWeight = FontWeight.Bold))
TypeRow("H3", IntelliJTheme.typography.h3)
TypeRow("H3 Bold", IntelliJTheme.typography.h3.copy(fontWeight = FontWeight.Bold))
TypeRow("H4", IntelliJTheme.typography.h4.copy(fontWeight = FontWeight.Bold))
TypeRow("H4", IntelliJTheme.typography.h4)
TypeRow("Default", IntelliJTheme.typography.default)
TypeRow("Default Bold", IntelliJTheme.typography.default.copy(fontWeight = FontWeight.Bold))
TypeRow("Medium", IntelliJTheme.typography.medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TableState(
mapOf(
"initialFirstVisibleRowIndex" to it.firstVisibleRowIndex,
"initialFirstVisibleRowScrollOffset" to it.firstVisibleRowScrollOffset,
*it.dividerOffsets.map { (k, v) -> it.toString() to v }.toTypedArray()
*it.dividerOffsets.map { (_, v) -> it.toString() to v }.toTypedArray()
)
},
restore = {
Expand Down

0 comments on commit 66919d6

Please sign in to comment.