Skip to content

Commit

Permalink
Run ktlint -f (lotsa changes)
Browse files Browse the repository at this point in the history
Looks like we've been on a pretty old ktlint version; new ones are much
stricter/more powerful and so a lot of changes ensued.

This also:
1. Downgrades sarif4k to 0.5.0 (see
   jeremymailen/kotlinter-gradle#382)
2. Updates the IDE code style to match ktlint's
  • Loading branch information
rock3r committed Jun 10, 2024
1 parent 9db7237 commit dfc9701
Show file tree
Hide file tree
Showing 222 changed files with 4,545 additions and 4,328 deletions.
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,44 @@ public fun DecoratedWindow(
var decoratedWindowState by remember { mutableStateOf(DecoratedWindowState.of(window)) }

DisposableEffect(window) {
val adapter = object : WindowAdapter(), ComponentListener {
override fun windowActivated(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}
val adapter =
object : WindowAdapter(), ComponentListener {
override fun windowActivated(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}

override fun windowDeactivated(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}
override fun windowDeactivated(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}

override fun windowIconified(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}
override fun windowIconified(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}

override fun windowDeiconified(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}
override fun windowDeiconified(e: WindowEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}

override fun windowStateChanged(e: WindowEvent) {
decoratedWindowState = DecoratedWindowState.of(window)
}
override fun windowStateChanged(e: WindowEvent) {
decoratedWindowState = DecoratedWindowState.of(window)
}

override fun componentResized(e: ComponentEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}
override fun componentResized(e: ComponentEvent?) {
decoratedWindowState = DecoratedWindowState.of(window)
}

override fun componentMoved(e: ComponentEvent?) {
// Empty
}
override fun componentMoved(e: ComponentEvent?) {
// Empty
}

override fun componentShown(e: ComponentEvent?) {
// Empty
}
override fun componentShown(e: ComponentEvent?) {
// Empty
}

override fun componentHidden(e: ComponentEvent?) {
// Empty
override fun componentHidden(e: ComponentEvent?) {
// Empty
}
}
}

window.addWindowListener(adapter)
window.addWindowStateListener(adapter)
Expand Down Expand Up @@ -155,13 +156,14 @@ public fun DecoratedWindow(
) {
Layout(
content = {
val scope = object : DecoratedWindowScope {
override val state: DecoratedWindowState
get() = decoratedWindowState

override val window: ComposeWindow
get() = this@Window.window
}
val scope =
object : DecoratedWindowScope {
override val state: DecoratedWindowState
get() = decoratedWindowState

override val window: ComposeWindow
get() = this@Window.window
}
scope.content()
},
modifier = undecoratedWindowBorder.trackWindowActivation(window),
Expand All @@ -173,15 +175,16 @@ public fun DecoratedWindow(

@Stable
public interface DecoratedWindowScope : FrameWindowScope {

override val window: ComposeWindow

public val state: DecoratedWindowState
}

private object DecoratedWindowMeasurePolicy : MeasurePolicy {

override fun MeasureScope.measure(measurables: List<Measurable>, constraints: Constraints): MeasureResult {
override fun MeasureScope.measure(
measurables: List<Measurable>,
constraints: Constraints,
): MeasureResult {
if (measurables.isEmpty()) {
return layout(width = constraints.minWidth, height = constraints.minHeight) {}
}
Expand Down Expand Up @@ -222,7 +225,6 @@ private object DecoratedWindowMeasurePolicy : MeasurePolicy {
@Immutable
@JvmInline
public value class DecoratedWindowState(public val state: ULong) {

public val isActive: Boolean
get() = state and Active != 0UL

Expand All @@ -248,11 +250,9 @@ public value class DecoratedWindowState(public val state: ULong) {
active = active,
)

override fun toString(): String =
"${javaClass.simpleName}(isFullscreen=$isFullscreen, isActive=$isActive)"
override fun toString(): String = "${javaClass.simpleName}(isFullscreen=$isFullscreen, isActive=$isActive)"

public companion object {

public val Active: ULong = 1UL shl 0
public val Fullscreen: ULong = 1UL shl 1
public val Minimize: ULong = 1UL shl 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ private fun TitleBarScope.ControlButton(
}

private object Inactive : PainterSuffixHint() {

override fun PainterProviderScope.suffix(): String = "Inactive"

override fun toString(): String = "Inactive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ import org.jetbrains.jewel.window.styling.TitleBarStyle
import org.jetbrains.jewel.window.utils.macos.MacUtil

public fun Modifier.newFullscreenControls(newControls: Boolean = true): Modifier =
this then NewFullscreenControlsElement(
newControls,
debugInspectorInfo {
name = "newFullscreenControls"
value = newControls
},
)
this then
NewFullscreenControlsElement(
newControls,
debugInspectorInfo {
name = "newFullscreenControls"
value = newControls
},
)

private class NewFullscreenControlsElement(
val newControls: Boolean,
val inspectorInfo: InspectorInfo.() -> Unit,
) : ModifierNodeElement<NewFullscreenControlsNode>() {

override fun create(): NewFullscreenControlsNode =
NewFullscreenControlsNode(newControls)
override fun create(): NewFullscreenControlsNode = NewFullscreenControlsNode(newControls)

override fun equals(other: Any?): Boolean {
if (this === other) return true
val otherModifier = other as? NewFullscreenControlsElement
?: return false
val otherModifier =
other as? NewFullscreenControlsElement
?: return false
return newControls == otherModifier.newControls
}

Expand All @@ -59,13 +59,14 @@ internal fun DecoratedWindowScope.TitleBarOnMacOs(
style: TitleBarStyle = JewelTheme.defaultTitleBarStyle,
content: @Composable TitleBarScope.(DecoratedWindowState) -> Unit,
) {
val newFullscreenControls = modifier.foldOut(false) { e, r ->
if (e is NewFullscreenControlsElement) {
e.newControls
} else {
r
val newFullscreenControls =
modifier.foldOut(false) { e, r ->
if (e is NewFullscreenControlsElement) {
e.newControls
} else {
r
}
}
}

if (newFullscreenControls) {
System.setProperty("apple.awt.newFullScreeControls", true.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,22 @@ internal fun DecoratedWindowScope.TitleBarImpl(

val density = LocalDensity.current

val backgroundBrush = remember(background, gradientStartColor) {
if (gradientStartColor.isUnspecified) {
SolidColor(background)
} else {
with(density) {
Brush.horizontalGradient(
0.0f to background,
0.5f to gradientStartColor,
1.0f to background,
startX = style.metrics.gradientStartX.toPx(),
endX = style.metrics.gradientEndX.toPx(),
)
val backgroundBrush =
remember(background, gradientStartColor) {
if (gradientStartColor.isUnspecified) {
SolidColor(background)
} else {
with(density) {
Brush.horizontalGradient(
0.0f to background,
0.5f to gradientStartColor,
1.0f to background,
startX = style.metrics.gradientStartX.toPx(),
endX = style.metrics.gradientEndX.toPx(),
)
}
}
}
}

Layout(
content = {
Expand All @@ -114,17 +115,19 @@ internal fun DecoratedWindowScope.TitleBarImpl(
}
}
},
modifier = modifier.background(backgroundBrush)
.focusProperties { canFocus = false }
.layoutId(TITLE_BAR_LAYOUT_ID)
.height(style.metrics.height)
.onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } }
.fillMaxWidth(),
measurePolicy = rememberTitleBarMeasurePolicy(
window,
state,
applyTitleBar,
),
modifier =
modifier.background(backgroundBrush)
.focusProperties { canFocus = false }
.layoutId(TITLE_BAR_LAYOUT_ID)
.height(style.metrics.height)
.onSizeChanged { with(density) { applyTitleBar(it.height.toDp(), state) } }
.fillMaxWidth(),
measurePolicy =
rememberTitleBarMeasurePolicy(
window,
state,
applyTitleBar,
),
)

Spacer(
Expand All @@ -140,8 +143,10 @@ internal class TitleBarMeasurePolicy(
private val state: DecoratedWindowState,
private val applyTitleBar: (Dp, DecoratedWindowState) -> PaddingValues,
) : MeasurePolicy {

override fun MeasureScope.measure(measurables: List<Measurable>, constraints: Constraints): MeasureResult {
override fun MeasureScope.measure(
measurables: List<Measurable>,
constraints: Constraints,
): MeasureResult {
if (measurables.isEmpty()) {
return layout(width = constraints.minWidth, height = constraints.minHeight) {}
}
Expand Down Expand Up @@ -237,7 +242,6 @@ internal fun rememberTitleBarMeasurePolicy(
}

public interface TitleBarScope {

public val title: String

public val icon: Painter?
Expand All @@ -250,22 +254,21 @@ private class TitleBarScopeImpl(
override val title: String,
override val icon: Painter?,
) : TitleBarScope {

override fun Modifier.align(alignment: Alignment.Horizontal): Modifier =
this then TitleBarChildDataElement(
alignment,
debugInspectorInfo {
name = "align"
value = alignment
},
)
this then
TitleBarChildDataElement(
alignment,
debugInspectorInfo {
name = "align"
value = alignment
},
)
}

private class TitleBarChildDataElement(
val horizontalAlignment: Alignment.Horizontal,
val inspectorInfo: InspectorInfo.() -> Unit = NoInspectorInfo,
) : ModifierNodeElement<TitleBarChildDataNode>(), InspectableValue {

override fun create(): TitleBarChildDataNode = TitleBarChildDataNode(horizontalAlignment)

override fun equals(other: Any?): Boolean {
Expand All @@ -288,7 +291,5 @@ private class TitleBarChildDataElement(
private class TitleBarChildDataNode(
var horizontalAlignment: Alignment.Horizontal,
) : ParentDataModifierNode, Modifier.Node() {

override fun Density.modifyParentData(parentData: Any?) =
this@TitleBarChildDataNode
override fun Density.modifyParentData(parentData: Any?) = this@TitleBarChildDataNode
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class DecoratedWindowStyle(
public val colors: DecoratedWindowColors,
public val metrics: DecoratedWindowMetrics,
) {

public companion object
}

Expand All @@ -27,7 +26,6 @@ public class DecoratedWindowColors(
public val border: Color,
public val borderInactive: Color,
) {

@Composable
public fun borderFor(state: DecoratedWindowState): State<Color> =
rememberUpdatedState(
Expand All @@ -43,7 +41,6 @@ public class DecoratedWindowColors(
@Immutable
@GenerateDataFunctions
public class DecoratedWindowMetrics(public val borderWidth: Dp) {

public companion object
}

Expand Down
Loading

0 comments on commit dfc9701

Please sign in to comment.