Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Oct 13, 2023
1 parent 7a228de commit 3a5beb4
Show file tree
Hide file tree
Showing 19 changed files with 468 additions and 145 deletions.
11 changes: 9 additions & 2 deletions core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ internal val LocalIsDarkTheme = staticCompositionLocalOf<Boolean> {
}

internal val LocalOnDarkBackground = staticCompositionLocalOf<Boolean> {
error("No InDarkTheme provided")
error("No OnDarkBackground provided")
}

internal val LocalSwingCompatMode = staticCompositionLocalOf {
Expand All @@ -253,9 +253,16 @@ val LocalIconData = staticCompositionLocalOf<IntelliJThemeIconData> {
EmptyThemeIconData
}

/**
* Sets the background color of the current area,
* which affects the style(light or dark) of the icon rendered above it,
* by calculating the luminance.
* If the color is not specified, the style will follow the current theme style.
* Transparent color will be ignored.
*/
@Composable
fun onBackground(color: Color, content: @Composable () -> Unit) {
val locals = if (color.isSpecified && color.alpha == 1f) {
val locals = if (color.isSpecified) {
arrayOf(LocalOnDarkBackground provides color.isDark())
} else {
emptyArray()
Expand Down
10 changes: 2 additions & 8 deletions core/src/main/kotlin/org/jetbrains/jewel/util/ColorExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.jewel.util

import androidx.compose.ui.graphics.Color
import kotlin.math.pow
import androidx.compose.ui.graphics.luminance
import kotlin.math.roundToInt

fun Color.toHexString(): String {
Expand All @@ -22,10 +22,4 @@ fun Color.toHexString(): String {
}
}

fun Color.isDark(): Boolean = (luminance + 0.05) / 0.05 < 4.5

val Color.luminance: Double
get() = linearRGBComponentValue(red) * 0.2126 + linearRGBComponentValue(green) * 0.7152 + linearRGBComponentValue(blue) * 0.0722

private fun linearRGBComponentValue(colorValue: Float): Double =
if (colorValue <= 0.03928) colorValue / 12.92 else ((colorValue + 0.055) / 1.055).pow(2.4)
fun Color.isDark(): Boolean = (luminance() + 0.05) / 0.05 < 4.5
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
import com.jetbrains.JBR
Expand Down Expand Up @@ -41,12 +42,20 @@ import org.jetbrains.jewel.window.styling.TitleBarStyle
internal fun Modifier.customTitleBarMouseEventHandler(titleBar: CustomTitleBar): Modifier = this.pointerInput(Unit) {
val currentContext = currentCoroutineContext()
awaitPointerEventScope {
var inUserControl = false
while (currentContext.isActive) {
val event = awaitPointerEvent(PointerEventPass.Main)
event.changes.forEach {
if (!it.isConsumed) {
if (!it.isConsumed && !inUserControl) {
titleBar.forceHitTest(false)
it.consume()
} else {
if (event.type == PointerEventType.Press) {
inUserControl = true
}
if (event.type == PointerEventType.Release) {
inUserControl = false
}
titleBar.forceHitTest(true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.offset
import org.jetbrains.jewel.IntelliJTheme
Expand Down Expand Up @@ -159,8 +158,8 @@ internal class TitleBarMeasurePolicy(

val contentPadding = applyTitleBar(boxHeight.toDp(), state)

val leftInset = contentPadding.calculateLeftPadding(LayoutDirection.Ltr).roundToPx()
val rightInset = contentPadding.calculateRightPadding(LayoutDirection.Ltr).roundToPx()
val leftInset = contentPadding.calculateLeftPadding(layoutDirection).roundToPx()
val rightInset = contentPadding.calculateRightPadding(layoutDirection).roundToPx()

occupiedSpaceHorizontally += leftInset
occupiedSpaceHorizontally += rightInset
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.jewel.intui.window.styling

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
Expand All @@ -9,39 +10,74 @@ import org.jetbrains.jewel.window.styling.DecoratedWindowColors
import org.jetbrains.jewel.window.styling.DecoratedWindowMetrics
import org.jetbrains.jewel.window.styling.DecoratedWindowStyle

@Stable data class IntUiDecoratedWindowStyle(
@Stable
@Immutable
class IntUiDecoratedWindowStyle(
override val colors: IntUiDecoratedWindowColors,
override val metrics: IntUiDecoratedWindowMetrics,
) : DecoratedWindowStyle {

override fun hashCode(): Int {
var result = colors.hashCode()
result = 31 * result + metrics.hashCode()
return result
}

override fun toString(): String = "IntUiDecoratedWindowStyle(colors=$colors, metrics=$metrics)"

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is IntUiDecoratedWindowStyle) return false

if (colors != other.colors) return false
if (metrics != other.metrics) return false

return true
}

companion object {

@Composable fun light(
intUiDecoratedWindowColors: IntUiDecoratedWindowColors = IntUiDecoratedWindowColors.light(),
intUiDecoratedWindowMetrics: IntUiDecoratedWindowMetrics = IntUiDecoratedWindowMetrics(1.dp),
): IntUiDecoratedWindowStyle = IntUiDecoratedWindowStyle(
colors = intUiDecoratedWindowColors,
metrics = intUiDecoratedWindowMetrics,
)
colors: IntUiDecoratedWindowColors = IntUiDecoratedWindowColors.light(),
metrics: IntUiDecoratedWindowMetrics = IntUiDecoratedWindowMetrics(1.dp),
): IntUiDecoratedWindowStyle = IntUiDecoratedWindowStyle(colors, metrics)

@Composable fun dark(
intUiDecoratedWindowColors: IntUiDecoratedWindowColors = IntUiDecoratedWindowColors.dark(),
intUiDecoratedWindowMetrics: IntUiDecoratedWindowMetrics = IntUiDecoratedWindowMetrics(1.dp),
): IntUiDecoratedWindowStyle = IntUiDecoratedWindowStyle(
colors = intUiDecoratedWindowColors,
metrics = intUiDecoratedWindowMetrics,
)
colors: IntUiDecoratedWindowColors = IntUiDecoratedWindowColors.dark(),
metrics: IntUiDecoratedWindowMetrics = IntUiDecoratedWindowMetrics(1.dp),
): IntUiDecoratedWindowStyle = IntUiDecoratedWindowStyle(colors, metrics)
}
}

@Stable data class IntUiDecoratedWindowColors(
@Stable
@Immutable
class IntUiDecoratedWindowColors(
override val border: Color,
override val borderInactive: Color,
) : DecoratedWindowColors {

override fun hashCode(): Int {
var result = border.hashCode()
result = 31 * result + borderInactive.hashCode()
return result
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is IntUiDecoratedWindowColors) return false

if (border != other.border) return false
if (borderInactive != other.borderInactive) return false

return true
}

override fun toString(): String = "IntUiDecoratedWindowColors(border=$border, borderInactive=$borderInactive)"

companion object {

@Composable fun light(
@Composable
fun light(
// from Window.undecorated.border
borderColor: Color = Color(0xFF5A5D6B),
inactiveBorderColor: Color = borderColor,
Expand All @@ -50,7 +86,8 @@ import org.jetbrains.jewel.window.styling.DecoratedWindowStyle
inactiveBorderColor,
)

@Composable fun dark(
@Composable
fun dark(
// from Window.undecorated.border
borderColor: Color = Color(0xFF5A5D63),
inactiveBorderColor: Color = borderColor,
Expand All @@ -61,6 +98,21 @@ import org.jetbrains.jewel.window.styling.DecoratedWindowStyle
}
}

@Stable data class IntUiDecoratedWindowMetrics(
@Stable
class IntUiDecoratedWindowMetrics(
override val borderWidth: Dp,
) : DecoratedWindowMetrics
) : DecoratedWindowMetrics {

override fun toString(): String = "IntUiDecoratedWindowMetrics(borderWidth=$borderWidth)"

override fun hashCode(): Int = borderWidth.hashCode()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is IntUiDecoratedWindowMetrics) return false

if (borderWidth != other.borderWidth) return false

return true
}
}
Loading

0 comments on commit 3a5beb4

Please sign in to comment.