Skip to content

Commit

Permalink
TabStyle refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Oct 20, 2023
1 parent e832ed0 commit f30d2cb
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 401 deletions.
117 changes: 64 additions & 53 deletions core/src/main/kotlin/org/jetbrains/jewel/styling/TabStyling.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,63 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import org.jetbrains.jewel.GenerateDataFunctions
import org.jetbrains.jewel.TabState
import org.jetbrains.jewel.painter.PainterProvider

@Stable
interface TabStyle {

val colors: TabColors
val metrics: TabMetrics
val icons: TabIcons
val contentAlpha: TabContentAlpha
@GenerateDataFunctions
class TabStyle(
val colors: TabColors,
val metrics: TabMetrics,
val icons: TabIcons,
val contentAlpha: TabContentAlpha,
) {

companion object
}

@Immutable
interface TabIcons {

val close: PainterProvider
@Stable
@GenerateDataFunctions
class TabMetrics(
val underlineThickness: Dp,
val tabPadding: PaddingValues,
val tabHeight: Dp,
val closeContentGap: Dp,
) {

companion object
}

@Stable
interface TabMetrics {
@Immutable
@GenerateDataFunctions
class TabIcons(val close: PainterProvider) {

val underlineThickness: Dp
val tabPadding: PaddingValues
val tabHeight: Dp
val closeContentGap: Dp
companion object
}

@Immutable
interface TabColors {

val background: Color
val backgroundDisabled: Color
val backgroundFocused: Color
val backgroundPressed: Color
val backgroundHovered: Color
val backgroundSelected: Color

val content: Color
val contentDisabled: Color
val contentFocused: Color
val contentPressed: Color
val contentHovered: Color
val contentSelected: Color

val underline: Color
val underlineDisabled: Color
val underlineFocused: Color
val underlinePressed: Color
val underlineHovered: Color
val underlineSelected: Color
@GenerateDataFunctions
class TabColors(
val background: Color,
val backgroundDisabled: Color,
val backgroundFocused: Color,
val backgroundPressed: Color,
val backgroundHovered: Color,
val backgroundSelected: Color,
val content: Color,
val contentDisabled: Color,
val contentFocused: Color,
val contentPressed: Color,
val contentHovered: Color,
val contentSelected: Color,
val underline: Color,
val underlineDisabled: Color,
val underlineFocused: Color,
val underlinePressed: Color,
val underlineHovered: Color,
val underlineSelected: Color,
) {

@Composable
fun contentFor(state: TabState) = rememberUpdatedState(
Expand Down Expand Up @@ -101,17 +108,26 @@ interface TabColors {
)
},
)

companion object
}

@Immutable
interface TabContentAlpha {

val iconNormal: Float
val iconDisabled: Float
val iconFocused: Float
val iconPressed: Float
val iconHovered: Float
val iconSelected: Float
@GenerateDataFunctions
class TabContentAlpha(
val iconNormal: Float,
val iconDisabled: Float,
val iconFocused: Float,
val iconPressed: Float,
val iconHovered: Float,
val iconSelected: Float,
val labelNormal: Float,
val labelDisabled: Float,
val labelFocused: Float,
val labelPressed: Float,
val labelHovered: Float,
val labelSelected: Float,
) {

@Composable
fun iconFor(state: TabState) = rememberUpdatedState(
Expand All @@ -128,13 +144,6 @@ interface TabContentAlpha {
},
)

val labelNormal: Float
val labelDisabled: Float
val labelFocused: Float
val labelPressed: Float
val labelHovered: Float
val labelSelected: Float

@Composable
fun labelFor(state: TabState) = rememberUpdatedState(
when {
Expand All @@ -149,6 +158,8 @@ interface TabContentAlpha {
)
},
)

companion object
}

// Tabs are the only components that handle hover states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldColors
import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldMetrics
import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldStyle
import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldTextStyles
import org.jetbrains.jewel.intui.standalone.styling.IntUiTabColors
import org.jetbrains.jewel.intui.standalone.styling.IntUiTabContentAlpha
import org.jetbrains.jewel.intui.standalone.styling.IntUiTabIcons
import org.jetbrains.jewel.intui.standalone.styling.IntUiTabMetrics
import org.jetbrains.jewel.intui.standalone.styling.IntUiTabStyle
import org.jetbrains.jewel.intui.standalone.styling.IntUiTextAreaColors
import org.jetbrains.jewel.intui.standalone.styling.IntUiTextAreaMetrics
import org.jetbrains.jewel.intui.standalone.styling.IntUiTextAreaStyle
Expand Down Expand Up @@ -92,6 +87,11 @@ import org.jetbrains.jewel.styling.ScrollbarColors
import org.jetbrains.jewel.styling.ScrollbarMetrics
import org.jetbrains.jewel.styling.ScrollbarStyle
import org.jetbrains.jewel.styling.SubmenuMetrics
import org.jetbrains.jewel.styling.TabColors
import org.jetbrains.jewel.styling.TabContentAlpha
import org.jetbrains.jewel.styling.TabIcons
import org.jetbrains.jewel.styling.TabMetrics
import org.jetbrains.jewel.styling.TabStyle
import org.jetbrains.skiko.DependsOnJBR
import javax.swing.UIManager
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -790,13 +790,13 @@ private fun readLazyTreeStyle(): LazyTreeStyle {
}

// See com.intellij.ui.tabs.impl.themes.DefaultTabTheme
private fun readDefaultTabStyle(): IntUiTabStyle {
private fun readDefaultTabStyle(): TabStyle {
val normalBackground = JBUI.CurrentTheme.DefaultTabs.background().toComposeColor()
val selectedBackground = JBUI.CurrentTheme.DefaultTabs.underlinedTabBackground().toComposeColorOrUnspecified()
val normalContent = retrieveColorOrUnspecified("TabbedPane.foreground")
val selectedUnderline = retrieveColorOrUnspecified("TabbedPane.underlineColor")

val colors = IntUiTabColors(
val colors = TabColors(
background = normalBackground,
backgroundDisabled = normalBackground,
backgroundFocused = normalBackground,
Expand All @@ -817,18 +817,18 @@ private fun readDefaultTabStyle(): IntUiTabStyle {
underlineSelected = selectedUnderline,
)

return IntUiTabStyle(
return TabStyle(
colors = colors,
metrics = IntUiTabMetrics(
metrics = TabMetrics(
underlineThickness = retrieveIntAsDpOrUnspecified("TabbedPane.tabSelectionHeight").takeOrElse { 2.dp },
tabPadding = retrieveInsetsAsPaddingValues("TabbedPane.tabInsets"),
closeContentGap = 4.dp,
tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp },
),
icons = IntUiTabIcons(
icons = TabIcons(
close = bridgePainterProvider("${iconsBasePath}expui/general/closeSmall.svg"),
),
contentAlpha = IntUiTabContentAlpha(
contentAlpha = TabContentAlpha(
iconNormal = 1f,
iconDisabled = 1f,
iconFocused = 1f,
Expand All @@ -845,13 +845,13 @@ private fun readDefaultTabStyle(): IntUiTabStyle {
)
}

private fun readEditorTabStyle(): IntUiTabStyle {
private fun readEditorTabStyle(): TabStyle {
val normalBackground = JBUI.CurrentTheme.EditorTabs.background().toComposeColor()
val selectedBackground = JBUI.CurrentTheme.EditorTabs.underlinedTabBackground().toComposeColorOrUnspecified()
val normalContent = retrieveColorOrUnspecified("TabbedPane.foreground")
val selectedUnderline = retrieveColorOrUnspecified("TabbedPane.underlineColor")

val colors = IntUiTabColors(
val colors = TabColors(
background = normalBackground,
backgroundDisabled = normalBackground,
backgroundFocused = normalBackground,
Expand All @@ -872,18 +872,18 @@ private fun readEditorTabStyle(): IntUiTabStyle {
underlineSelected = selectedUnderline,
)

return IntUiTabStyle(
return TabStyle(
colors = colors,
metrics = IntUiTabMetrics(
metrics = TabMetrics(
underlineThickness = retrieveIntAsDpOrUnspecified("TabbedPane.tabSelectionHeight").takeOrElse { 2.dp },
tabPadding = retrieveInsetsAsPaddingValues("TabbedPane.tabInsets"),
closeContentGap = 4.dp,
tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp },
),
icons = IntUiTabIcons(
icons = TabIcons(
close = bridgePainterProvider("${iconsBasePath}expui/general/closeSmall.svg"),
),
contentAlpha = IntUiTabContentAlpha(
contentAlpha = TabContentAlpha(
iconNormal = .7f,
iconDisabled = .7f,
iconFocused = .7f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme
import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme
import org.jetbrains.jewel.intui.standalone.IntUiTheme.defaultComponentStyling
import org.jetbrains.jewel.intui.standalone.styling.Default
import org.jetbrains.jewel.intui.standalone.styling.Editor
import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldStyle
import org.jetbrains.jewel.intui.standalone.styling.IntUiTabStyle
import org.jetbrains.jewel.intui.standalone.styling.IntUiTextAreaStyle
import org.jetbrains.jewel.intui.standalone.styling.IntUiTextFieldStyle
import org.jetbrains.jewel.intui.standalone.styling.IntUiTooltipStyle
Expand Down Expand Up @@ -87,10 +87,10 @@ object IntUiTheme : BaseIntUiTheme {
chipStyle: ChipStyle = ChipStyle.dark(),
circularProgressStyle: CircularProgressStyle = CircularProgressStyle.dark(),
defaultButtonStyle: ButtonStyle = ButtonStyle.Default.dark(),
defaultTabStyle: TabStyle = IntUiTabStyle.Default.dark(),
defaultTabStyle: TabStyle = TabStyle.Default.dark(),
dividerStyle: DividerStyle = DividerStyle.dark(),
dropdownStyle: DropdownStyle = DropdownStyle.Default.dark(),
editorTabStyle: TabStyle = IntUiTabStyle.Editor.dark(),
editorTabStyle: TabStyle = TabStyle.Editor.dark(),
groupHeaderStyle: GroupHeaderStyle = GroupHeaderStyle.dark(),
horizontalProgressBarStyle: HorizontalProgressBarStyle = HorizontalProgressBarStyle.dark(),
iconButtonStyle: IconButtonStyle = IconButtonStyle.dark(),
Expand Down Expand Up @@ -136,10 +136,10 @@ object IntUiTheme : BaseIntUiTheme {
chipStyle: ChipStyle = ChipStyle.light(),
circularProgressStyle: CircularProgressStyle = CircularProgressStyle.light(),
defaultButtonStyle: ButtonStyle = ButtonStyle.Default.light(),
defaultTabStyle: TabStyle = IntUiTabStyle.Default.light(),
defaultTabStyle: TabStyle = TabStyle.Default.light(),
dividerStyle: DividerStyle = DividerStyle.light(),
dropdownStyle: DropdownStyle = DropdownStyle.Default.light(),
editorTabStyle: TabStyle = IntUiTabStyle.Editor.light(),
editorTabStyle: TabStyle = TabStyle.Editor.light(),
groupHeaderStyle: GroupHeaderStyle = GroupHeaderStyle.light(),
horizontalProgressBarStyle: HorizontalProgressBarStyle = HorizontalProgressBarStyle.light(),
iconButtonStyle: IconButtonStyle = IconButtonStyle.light(),
Expand Down
Loading

0 comments on commit f30d2cb

Please sign in to comment.