Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-arold committed Feb 14, 2024
1 parent 00223b8 commit 10e9621
Show file tree
Hide file tree
Showing 53 changed files with 1,771 additions and 877 deletions.
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

## Must have

- [ ] Implement Rexpaint loading
- [x] Implement Rexpaint loading
- [ ] Implement animation loading
- [ ] Add remaining tilesets to app config and test them
- [ ] Retrofit code examples
- [ ] Implement texture transform modifiers (crossed-out, underline, border)
- [ ] Refactor the Markov modifier
- [ ] Fix the buggy components
- [ ] radio box won't do the `o` when selected without focus (first click)
- [ ] `TextBox` will do an interaction recoloring when `<Space>` is pressed
- [ ] `TextBox` cursor is drawn outside the box
- [x] `TextBox` will do an interaction recoloring when `<Space>` is pressed
- [x] `TextBox` cursor is drawn outside the box
- [ ] if `CheckBox` is clicked quickly it won't check
- [ ] Use all code examples to check for bugs

## Nice to have

- [x] Refactor java-sytle builders to kotlin builder dsls
- [ ] Refactor the Markov modifier
- [ ] Check the rest of the code for Javaesque patterns and refactor them
- [ ] Make life easier for Java users

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object Versions {
const val KOTLINX_COROUTINES_VERSION = "1.5.0"
const val KOTLINX_COLLECTIONS_IMMUTABLE_VERSION = "0.3.5"

const val COBALT_VERSION = "2024.0.0-RELEASE"
const val COBALT_VERSION = "2024.1.0-RELEASE"
const val KOR_VERSION = "5.3.0"

const val SNAKEYAML_VERSION = "1.29"
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
group=org.hexworks.zircon
version=2024.0.0-RELEASE
version=2024.1.0-RELEASE

kotlin.mpp.stability.nowarn=true
kotlin.js.compiler=ir
kotlin.daemon.jvmargs=-Xmx4096m

POM_PACKAGING=jar
POM_URL=https://github.com/Hexworks/zircon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package org.hexworks.zircon.api.behavior

import org.hexworks.cobalt.databinding.api.property.Property
import org.hexworks.zircon.api.data.Position
import org.hexworks.zircon.api.data.Size
import org.hexworks.zircon.internal.behavior.impl.DefaultScrollable

/**
* A [Scrollable] object has a visible 2D space which might be smaller than its actual size.
* A scrollable maintains a visible "window" over its content which can be bigger
* either vertically or horizontally than its actual part.
* A [Scrollable] object maintains a scrollable "window" of `visibleSize` over
* an area of (possibly) larger (`actualSize`) size. `visibleOffset` can be modified
* to move the window around.
*/
interface Scrollable {

/**
* the [Size] of the virtual space this [Scrollable] can scroll through
*/
var actualSize: Size
val actualSizeProperty: Property<Size>

/**
* the size of the visible part of this [Scrollable3D].
Expand All @@ -23,67 +26,83 @@ interface Scrollable {
/**
* The offset where the visible part of this [Scrollable] starts.
*/
val visibleOffset: Position
var visibleOffset: Position
val visibleOffsetProperty: Property<Position>

/**
* Scrolls this [Scrollable] with one width to the right.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Scrolls this [Scrollable] right.
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollOneRight(): Position

/**
* Scrolls this [Scrollable] with one width to the left.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Scrolls this [Scrollable] left.
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollOneLeft(): Position

/**
* Scrolls this [Scrollable] with one depth up.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Scrolls this [Scrollable] up.
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollOneUp(): Position

/**
* Scrolls this [Scrollable] with one depth down.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Scrolls this [Scrollable] down.
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollOneDown(): Position

/**
* Scrolls this [Scrollable] by `width` width to the right.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollRightBy(columns: Int): Position

/**
* Scrolls this [Scrollable] with `width` width to the left.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollLeftBy(columns: Int): Position

/**
* Scrolls this [Scrollable] by `depth` depth up.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollUpBy(rows: Int): Position

/**
* Scrolls this [Scrollable] with `rows` rows down.
* If the bounds of the virtual space are already reached this method has no effect.
* @return the new visible offset
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollDownBy(rows: Int): Position

/**
* Scrolls this [Scrollable] to the provided position
* Scrolls this [Scrollable] to the provided position.
* Has no effect if the bounds are already reached.
* @return the current `visibleOffset`
*/
fun scrollTo(position: Position)
fun scrollTo(position: Position): Position

companion object {

fun create(
visibleSize: Size,
actualSize: Size
): Scrollable {
require(actualSize.toRect().containsBoundable(visibleSize.toRect())) {
"Visible size cannot be bigger than actual size"
}
return DefaultScrollable(visibleSize, actualSize)
}
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
package org.hexworks.zircon.api.builder.component

import org.hexworks.zircon.api.behavior.Scrollable
import org.hexworks.zircon.api.builder.data.size
import org.hexworks.zircon.api.component.ScrollBar
import org.hexworks.zircon.api.component.builder.base.BaseComponentBuilder
import org.hexworks.zircon.api.component.builder.base.BaseContainerBuilder
import org.hexworks.zircon.api.dsl.buildChildFor
import org.hexworks.zircon.internal.component.impl.DefaultVerticalScrollBar
import org.hexworks.zircon.internal.component.renderer.VerticalScrollBarRenderer
import org.hexworks.zircon.internal.component.renderer.DefaultVerticalScrollBarRenderer
import org.hexworks.zircon.internal.dsl.ZirconDsl

/**
* Builder for a vertical [ScrollBar]. By default, it creates a [ScrollBar] with
* - [itemsShownAtOnce]: `1`
* - [numberOfScrollableItems]: `100`
*/
@ZirconDsl
class VerticalScrollBarBuilder :
ScrollBarBuilder<ScrollBar>(VerticalScrollBarRenderer()) {
class VerticalScrollBarBuilder(
initialScrollable: Scrollable
) : BaseComponentBuilder<ScrollBar>(
initialRenderer = DefaultVerticalScrollBarRenderer()
) {

var scrollable: Scrollable = initialScrollable

override fun build(): ScrollBar = DefaultVerticalScrollBar(
componentMetadata = createMetadata(),
renderingStrategy = createRenderingStrategy(),
minValue = 0,
maxValue = numberOfScrollableItems,
itemsShownAtOnce = itemsShownAtOnce,
numberOfSteps = size.height,
).attachListeners()
override fun build(): ScrollBar {
val visibleSize = scrollable.visibleSize
preferredSize = size {
width = 1
height = visibleSize.height
}
return DefaultVerticalScrollBar(
componentMetadata = createMetadata(),
renderingStrategy = createRenderingStrategy(),
scrollable = scrollable
).attachListeners()
}
}

/**
* Creates a new [ScrollBar] using the component builder DSL and returns it.
* Creates a new vertical [ScrollBar] using the component builder DSL and returns it.
*/
fun buildVerticalScrollBar(init: VerticalScrollBarBuilder.() -> Unit): ScrollBar =
VerticalScrollBarBuilder().apply(init).build()
fun buildVerticalScrollBar(scrollable: Scrollable, init: VerticalScrollBarBuilder.() -> Unit): ScrollBar =
VerticalScrollBarBuilder(scrollable).apply(init).build()

/**
* Creates a new [ScrollBar] using the component builder DSL, adds it to the
* Creates a new vertical [ScrollBar] using the component builder DSL, adds it to the
* receiver [BaseContainerBuilder] it and returns the [ScrollBar].
*/
fun <T : BaseContainerBuilder<*>> T.verticalScrollBar(
scrollable: Scrollable,
init: VerticalScrollBarBuilder.() -> Unit
): ScrollBar = buildChildFor(this, VerticalScrollBarBuilder(), init)
): ScrollBar = buildChildFor(this, VerticalScrollBarBuilder(scrollable), init)
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,8 @@ class TileImageBuilder : Builder<TileImage> {
var filler: Tile = Tile.empty()

var size: Size = Size.one()
set(value) {
if (this.size.width > size.width || this.size.height > size.height) {
removeOutOfBoundsTiles(size)
}
field = value
}

var tiles: Map<Position, Tile> = mapOf()
set(value) {
field = value
removeOutOfBoundsTiles()
}


private fun removeOutOfBoundsTiles(size: Size = this.size) {
this.tiles = tiles
.filterKeys { size.containsPosition(it) }
.toMap()
}

override fun build(): TileImage {
return DefaultTileImage(
Expand Down
Loading

0 comments on commit 10e9621

Please sign in to comment.