Skip to content

Commit

Permalink
Yet another round of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Nov 1, 2023
1 parent d9d1bb0 commit c834e83
Show file tree
Hide file tree
Showing 59 changed files with 714 additions and 936 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ internal fun DecoratedWindowScope.TitleBarOnLinux(
val viewConfig = LocalViewConfiguration.current
TitleBarImpl(
modifier.onPointerEvent(PointerEventType.Press, PointerEventPass.Main) {
if (
this.currentEvent.button == PointerButton.Primary &&
if (this.currentEvent.button == PointerButton.Primary &&
this.currentEvent.changes.any { changed -> !changed.isConsumed }
) {
JBR.getWindowMove()?.startMovingTogetherWithMouse(window, MouseEvent.BUTTON1)
if (
System.currentTimeMillis() - lastPress in
if (System.currentTimeMillis() - lastPress in
viewConfig.doubleTapMinTimeMillis..viewConfig.doubleTapTimeoutMillis
) {
if (state.isMaximized) {
Expand Down Expand Up @@ -97,7 +95,14 @@ private fun TitleBarScope.CloseButton(
state: DecoratedWindowState,
style: TitleBarStyle = JewelTheme.defaultTitleBarStyle,
) {
ControlButton(onClick, state, style.icons.closeButton, "Close", style, style.paneCloseButtonStyle)
ControlButton(
onClick,
state,
style.icons.closeButton,
"Close",
style,
style.paneCloseButtonStyle,
)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ public class DecoratedWindowMetrics(public val borderWidth: Dp) {
}

public val LocalDecoratedWindowStyle: ProvidableCompositionLocal<DecoratedWindowStyle> =
staticCompositionLocalOf<DecoratedWindowStyle> { error("No DecoratedWindowStyle provided. Have you forgotten the theme?") }
staticCompositionLocalOf {
error("No DecoratedWindowStyle provided. Have you forgotten the theme?")
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ public class TitleBarIcons(
}

public val LocalTitleBarStyle: ProvidableCompositionLocal<TitleBarStyle> =
staticCompositionLocalOf<TitleBarStyle> { error("No TitleBarStyle provided. Have you forgotten the theme?") }
staticCompositionLocalOf {
error("No TitleBarStyle provided. Have you forgotten the theme?")
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ internal object Foundation {
ID(myObjcMsgSend?.invokeLong(prepInvoke(id, selector, args)) ?: 0)

/**
* Invokes the given vararg selector. Expects `NSArray arrayWithObjects:(id), ...` like signature,
* i.e. exactly one fixed argument, followed by varargs.
* Invokes the given vararg selector. Expects `NSArray arrayWithObjects:(id), ...` like signature, i.e.,
* exactly one fixed argument, followed by varargs.
*/
public fun invokeVarArg(id: ID?, selector: Pointer?, vararg args: Any?): ID {
// c functions and objc methods have at least 1 fixed argument, we therefore need to separate
// c functions and objc methods have at least 1 fixed argument, we therefore need to
// separate
// out the first argument
return myFoundationLibrary?.objc_msgSend(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ internal object MacUtil {
SwingUtilities.invokeLater {
val window = getWindowFromJavaWindow(w)
val delegate = Foundation.invoke(window, "delegate")
if (
Foundation.invoke(
if (Foundation.invoke(
delegate,
"respondsToSelector:",
Foundation.createSelector("updateColors"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ public class OutlineColors(
}

public val LocalGlobalColors: ProvidableCompositionLocal<GlobalColors> =
staticCompositionLocalOf<GlobalColors> { error("No GlobalColors provided. Have you forgotten the theme?") }
staticCompositionLocalOf {
error("No GlobalColors provided. Have you forgotten the theme?")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class GlobalMetrics(
}

public val LocalGlobalMetrics: ProvidableCompositionLocal<GlobalMetrics> =
staticCompositionLocalOf<GlobalMetrics> { error("No GlobalMetrics provided. Have you forgotten the theme?") }
staticCompositionLocalOf {
error("No GlobalMetrics provided. Have you forgotten the theme?")
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public interface SelectableColumnOnKeyEvent {
}
if (list.isNotEmpty()) {
state.selectedKeys =
state.selectedKeys.toMutableList().also { selectionList -> selectionList.addAll(list) }
state.selectedKeys.toMutableList()
.also { selectionList -> selectionList.addAll(list) }
}
}
}
Expand Down Expand Up @@ -192,9 +193,9 @@ public interface SelectableColumnOnKeyEvent {
val visibleSize = state.layoutInfo.visibleItemsInfo.size
val targetIndex = min((state.lastActiveItemIndex ?: 0) + visibleSize, keys.lastIndex)
val newSelectionList =
keys.subList(state.lastActiveItemIndex ?: 0, targetIndex).filterIsInstance<Selectable>().let {
state.selectedKeys + it.map { selectableKey -> selectableKey.key }
}
keys.subList(state.lastActiveItemIndex ?: 0, targetIndex)
.filterIsInstance<Selectable>()
.let { state.selectedKeys + it.map { selectableKey -> selectableKey.key } }
state.selectedKeys = newSelectionList
state.lastActiveItemIndex = targetIndex
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public fun SelectableLazyColumn(
.onPreviewKeyEvent { event ->
if (state.lastActiveItemIndex != null) {
val actionHandled =
keyActions.handleOnKeyEvent(event, keys, state, selectionMode).invoke(event)
keyActions.handleOnKeyEvent(event, keys, state, selectionMode)
.invoke(event)
if (actionHandled) {
scope.launch { state.lastActiveItemIndex?.let { state.scrollToItem(it) } }
}
Expand Down Expand Up @@ -120,6 +121,7 @@ public fun SelectableLazyColumn(
) { index ->
val itemScope =
SelectableLazyItemScope(entry.key(index) in state.selectedKeys, isFocused)

if (keys.any { it.key == entry.key(index) && it is SelectableLazyListKey.Selectable }) {
Box(
modifier =
Expand All @@ -142,6 +144,7 @@ public fun SelectableLazyColumn(
is Entry.StickyHeader ->
stickyHeader(entry.key, entry.contentType) {
val itemScope = SelectableLazyItemScope(entry.key in state.selectedKeys, isFocused)

if (keys.any { it.key == entry.key && it is SelectableLazyListKey.Selectable }) {
Box(
modifier =
Expand All @@ -157,9 +160,8 @@ public fun SelectableLazyColumn(
entry.content.invoke(itemScope)
}
} else {
SelectableLazyItemScope(entry.key in state.selectedKeys, isFocused).apply {
entry.content.invoke(itemScope)
}
SelectableLazyItemScope(entry.key in state.selectedKeys, isFocused)
.apply { entry.content.invoke(itemScope) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public interface SelectableLazyListScope {
* Represents a list of items based on the provided parameters.
*
* @param count The number of items in the list.
* @param key A function that generates a unique key for each item based on its index.
* @param contentType A function that returns the content type of an item based on its index.
* Defaults to `null`.
* @param selectable A function that determines if an item is selectable based on its index.
* Defaults to `true`.
* @param itemContent The content of each individual item, specified as a composable function that
* takes the item's index as a parameter.
* @param key A function that generates a unique key for each item based on
* its index.
* @param contentType A function that returns the content type of an item
* based on its index. Defaults to `null`.
* @param selectable A function that determines if an item is selectable
* based on its index. Defaults to `true`.
* @param itemContent The content of each individual item, specified as a
* composable function that takes the item's index as a parameter.
*/
public fun items(
count: Int,
Expand Down
Loading

0 comments on commit c834e83

Please sign in to comment.