Skip to content

Commit

Permalink
Added more fixes to UIComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
smilefx committed Feb 1, 2025
1 parent a3a4f32 commit 4daaa3c
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 76 deletions.
2 changes: 2 additions & 0 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/elements/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ internal val App =
".bgw-root *:has(*[aria-roledescription='draggable'][aria-pressed='true'])" {
zIndex = important(integer(1000000))
}

"bgw_scroll::-webkit-scrollbar" { display = None.none }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal val ListView =
className = ClassName("components")
id = props.data.id + "--components"
css {
width = fit()
width = 100.pct
display = Display.flex
flexDirection = FlexDirection.column
alignItems = AlignItems.start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ internal class JCEFApplication : Application {
if (component is ComboBox<*>) component.select(eventData.selectedItem)
}
is StructuredDataSelectEventData -> {
if (component is StructuredDataView<*>) component.select(eventData.index)
if (component is StructuredDataView<*>) component.selectIndex(eventData.index)
}
is TextInputChangedEventData -> {
if (component is TextInputUIComponent) component.text = eventData.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import tools.aqua.bgw.visual.Visual
* @param width Width for this [ComboBox]. Default: [DEFAULT_COMBOBOX_WIDTH].
* @param height Height for this [ComboBox]. Default: [DEFAULT_COMBOBOX_HEIGHT].
* @param font [Font] to be used for the options. Default: default [Font] constructor.
* @param visual [Visual] that is used to represent this [ComboBox]. Default: empty [Visual].
* @property prompt Prompt for this [ComboBox]. This gets displayed as a prompt to the user whenever
* the [selectedItem] value is `null`. Default: empty string.
* @param items The initial selection of items. Default: empty list.
Expand All @@ -56,18 +57,14 @@ open class ComboBox<T>(
width: Number = DEFAULT_COMBOBOX_WIDTH,
height: Number = DEFAULT_COMBOBOX_HEIGHT,
font: Font = Font(),
visual: Visual = Visual.EMPTY,
/** Prompt for this [ComboBox]. */
val prompt: String = "",
items: List<T> = emptyList(),
formatFunction: ((T) -> String)? = null,
) :
UIComponent(
posX = posX,
posY = posY,
width = width,
height = height,
font = font,
visual = Visual.EMPTY) {
posX = posX, posY = posY, width = width, height = height, font = font, visual = visual) {

internal fun select(selectedItem: Int) {
if (selectedItem < 0 || selectedItem >= observableItemsList.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import tools.aqua.bgw.visual.Visual
* @param posY Vertical coordinate for this [ProgressBar]. Default: 0.
* @param width Width for this [ProgressBar]. Default: [DEFAULT_PROGRESSBAR_WIDTH].
* @param height Height for this [ProgressBar]. Default: [DEFAULT_PROGRESSBAR_HEIGHT].
* @param visual [Visual] that is used to represent this [ProgressBar]. Default: empty [Visual].
* @param progress The initial progress of this [ProgressBar]. Default 0.
* @param barColor The initial bar color of this [ProgressBar]. Default [Color.CYAN].
*/
Expand All @@ -44,16 +45,12 @@ open class ProgressBar(
posY: Number = 0,
width: Number = DEFAULT_PROGRESSBAR_WIDTH,
height: Number = DEFAULT_PROGRESSBAR_HEIGHT,
visual: Visual = Visual.EMPTY,
progress: Double = 0.0,
barColor: Color = Color.CYAN
) :
UIComponent(
posX = posX,
posY = posY,
width = width,
height = height,
font = Font(),
visual = Visual.EMPTY) {
posX = posX, posY = posY, width = width, height = height, font = Font(), visual = visual) {
/**
* [Property] for the progress state of this [ProgressBar].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sealed class StructuredDataView<T>(
selectedItemsList.clear()
selectedIndicesList.clear()

if(it) onSelectionChanged?.invoke(selectedItemsList.toList())
if (it) onSelectionChanged?.invoke(selectedItemsList.toList())
}

/**
Expand All @@ -205,7 +205,7 @@ sealed class StructuredDataView<T>(
* @throws IllegalStateException If selection mode is [SelectionMode.NONE].
* @throws IllegalArgumentException If [index] is out of bounds.
*/
fun select(index: Int) {
fun selectIndex(index: Int) {
checkSelectionEnabled()
require(index in items.indices) { "Index is out of bounds." }

Expand All @@ -227,7 +227,7 @@ sealed class StructuredDataView<T>(
"Cannot select element because it is not contained in this UIComponent."
}

select(items.indexOf(element))
selectIndex(items.indexOf(element))
}

/**
Expand All @@ -237,7 +237,7 @@ sealed class StructuredDataView<T>(
* @throws IllegalArgumentException If [UIComponent] is empty.
*/
fun selectFirst() {
select(0)
selectIndex(0)
}

/**
Expand All @@ -247,7 +247,7 @@ sealed class StructuredDataView<T>(
* @throws IllegalArgumentException If [UIComponent] is empty.
*/
fun selectLast() {
select(items.size - 1)
selectIndex(items.size - 1)
}

/**
Expand All @@ -264,8 +264,8 @@ sealed class StructuredDataView<T>(
"Cannot select next item in selection mode '$selectionMode'."
}

if (selectedIndices.isEmpty()) select(0)
else if (selectedIndices[0] < items.size - 1) select(selectedIndices[0] + 1)
if (selectedIndices.isEmpty()) selectIndex(0)
else if (selectedIndices[0] < items.size - 1) selectIndex(selectedIndices[0] + 1)
}

/**
Expand All @@ -281,8 +281,8 @@ sealed class StructuredDataView<T>(
"Cannot select previous item in selection mode '$selectionMode'."
}

if (selectedIndices.isEmpty()) select(items.size - 1)
else if (selectedIndices[0] > 0) select(selectedIndices[0] - 1)
if (selectedIndices.isEmpty()) selectIndex(items.size - 1)
else if (selectedIndices[0] > 0) selectIndex(selectedIndices[0] - 1)
}

/**
Expand Down Expand Up @@ -324,7 +324,6 @@ sealed class StructuredDataView<T>(
private fun checkSelectionEnabled(): Unit =
check(selectionMode != SelectionMode.NONE) { "Cannot select items in selection mode 'NONE'." }


/**
* Gets invoked whenever items are selected or deselected.
*
Expand Down
Loading

0 comments on commit 4daaa3c

Please sign in to comment.