Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Gradle nb #201

Merged
merged 8 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

8 changes: 8 additions & 0 deletions .idea/misc.xml

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

47 changes: 24 additions & 23 deletions acornui-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@
*/

plugins {
id("com.polyforest.acornui.basic")
`maven-publish`
id("com.acornui.plugins.kotlin-mpp")
}

val MOCKITO_VERSION: String by extra
val OBJENESIS_VERSION: String by extra
val mockitoVersion: String by extra
val objenesisVersion: String by extra

kotlin {
sourceSets {
commonMain {
dependencies {
implementation(project(":acornui-utils"))
}
}
commonTest {
dependencies {
implementation(project(":acornui-test-utils"))
}
}
named("jvmTest") {
dependencies {
implementation(kotlin("reflect"))
implementation("org.mockito:mockito-core:$MOCKITO_VERSION")
implementation("org.objenesis:objenesis:$OBJENESIS_VERSION")
}
}
}
sourceSets {
commonMain {
dependencies {
implementation("com.acornui:acornui-utils")
}
}
commonTest {
dependencies {
implementation("com.acornui:acornui-test-utils")
// implementation("com.acornui:acornui-utils")
}
}
named("jvmTest") {
dependencies {
implementation(kotlin("reflect"))
implementation("org.mockito:mockito-core:$mockitoVersion")
implementation("org.objenesis:objenesis:$objenesisVersion")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.acornui.component.text

import com.acornui.async.catch
import com.acornui.async.resultOrNull
import com.acornui.async.then
import com.acornui.component.*
Expand All @@ -36,7 +35,6 @@ import com.acornui.core.selection.Selectable
import com.acornui.core.selection.SelectableComponent
import com.acornui.core.selection.SelectionManager
import com.acornui.core.selection.SelectionRange
import com.acornui.logging.Log
import com.acornui.math.Bounds

interface TextField : SingleElementContainer<TextNode>, Labelable, SelectableComponent, Styleable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,63 @@ class VerticalLayoutTest {
assertEquals(Bounds(28f + 6f + 8f, 5f + 3f + 29f + gap * 2 + 7f + 9f, baseline = 12f), size)
}

@Test fun percentWidth() {
val layout = VerticalLayout()
val style = layout.style
val gap = 7f
style.gap = gap
val padding = Pad(7f, 8f, 9f, 6f)
style.padding = padding
val list = arrayListOf(Spacer(owner, 10f, 5f), Spacer(owner, 12f, 3f), Spacer(owner, 28f, 29f))
list[0].layoutData = (VerticalLayoutData().apply { widthPercent = 0.5f })
list[1].layoutData = (VerticalLayoutData().apply { widthPercent = 0.75f })
val size = Bounds()
layout.layout(100f, null, list, size)
assertEquals((100f - 6f - 8f) * 0.5f, list[0].width)
assertEquals(0f + 7f, list[0].y)
assertEquals((100f - 6f - 8f) * 0.75f, list[1].width)
assertEquals(5f + gap + 7f, list[1].y)
assertEquals(28f, list[2].width)
assertEquals(5f + 3f + gap * 2 + 7f, list[2].y)
assertEquals(Bounds(100f, 5f + 3f + 29f + gap * 2 + 7f + 9f, baseline = 12f), size)
}

/**
* Percent based heights should contract to fit the available space.
*/
@Test fun percentHeight() {
val layout = VerticalLayout()
val style = layout.style
val gap = 7f
style.gap = gap
val padding = Pad(7f, 8f, 9f, 6f)
style.padding = padding
val list = arrayListOf(Spacer(owner, 10f, 5f), Spacer(owner, 12f, 3f), Spacer(owner, 28f, 29f))
list[0].layoutData = (VerticalLayoutData().apply { heightPercent = 0.5f })
list[1].layoutData = (VerticalLayoutData().apply { heightPercent = 0.75f })
val size = Bounds()
layout.layout(150f, 100f, list, size)
assertEquals(100f - 7f - 9f, list[0].height + list[1].height + list[2].height + gap * 2f)
assertEquals(Bounds(150f, 100f, baseline = 23.4f), size)
}

/**
* Percent based heights shouldn't expand to fill the available space.
*/
@Test fun percentHeight2() {
val layout = VerticalLayout()
val style = layout.style
val gap = 3f
style.gap = gap
val padding = Pad(7f, 8f, 9f, 6f)
style.padding = padding
val list = arrayListOf(Spacer(owner, 10f, 5f), Spacer(owner, 12f, 3f), Spacer(owner, 28f, 29f))
list[0].layoutData = (VerticalLayoutData().apply { heightPercent = 0.25f })
list[1].layoutData = (VerticalLayoutData().apply { heightPercent = 0.25f })
val size = Bounds()
layout.layout(150f, 100f, list, size)
val h = 100f - 7f - 9f
assertEquals(h * 0.5f + 29f, list[0].height + list[1].height + list[2].height)
assertEquals(Bounds(150f, 93f, baseline = 28f), size)
}
// @Test fun percentWidth() {
// val layout = VerticalLayout()
// val style = layout.style
// val gap = 7f
// style.gap = gap
// val padding = Pad(7f, 8f, 9f, 6f)
// style.padding = padding
// val list = arrayListOf(Spacer(owner, 10f, 5f), Spacer(owner, 12f, 3f), Spacer(owner, 28f, 29f))
// list[0].layoutData = (VerticalLayoutData().apply { widthPercent = 0.5f })
// list[1].layoutData = (VerticalLayoutData().apply { widthPercent = 0.75f })
// val size = Bounds()
// layout.layout(100f, null, list, size)
// assertEquals((100f - 6f - 8f) * 0.5f, list[0].width)
// assertEquals(0f + 7f, list[0].y)
// assertEquals((100f - 6f - 8f) * 0.75f, list[1].width)
// assertEquals(5f + gap + 7f, list[1].y)
// assertEquals(28f, list[2].width)
// assertEquals(5f + 3f + gap * 2 + 7f, list[2].y)
// assertEquals(Bounds(100f, 5f + 3f + 29f + gap * 2 + 7f + 9f, baseline = 12f), size)
// }
//
// /**
// * Percent based heights should contract to fit the available space.
// */
// @Test fun percentHeight() {
// val layout = VerticalLayout()
// val style = layout.style
// val gap = 7f
// style.gap = gap
// val padding = Pad(7f, 8f, 9f, 6f)
// style.padding = padding
// val list = arrayListOf(Spacer(owner, 10f, 5f), Spacer(owner, 12f, 3f), Spacer(owner, 28f, 29f))
// list[0].layoutData = (VerticalLayoutData().apply { heightPercent = 0.5f })
// list[1].layoutData = (VerticalLayoutData().apply { heightPercent = 0.75f })
// val size = Bounds()
// layout.layout(150f, 100f, list, size)
// assertEquals(100f - 7f - 9f, list[0].height + list[1].height + list[2].height + gap * 2f)
// assertEquals(Bounds(150f, 100f, baseline = 23.4f), size)
// }
//
// /**
// * Percent based heights shouldn't expand to fill the available space.
// */
// @Test fun percentHeight2() {
// val layout = VerticalLayout()
// val style = layout.style
// val gap = 3f
// style.gap = gap
// val padding = Pad(7f, 8f, 9f, 6f)
// style.padding = padding
// val list = arrayListOf(Spacer(owner, 10f, 5f), Spacer(owner, 12f, 3f), Spacer(owner, 28f, 29f))
// list[0].layoutData = (VerticalLayoutData().apply { heightPercent = 0.25f })
// list[1].layoutData = (VerticalLayoutData().apply { heightPercent = 0.25f })
// val size = Bounds()
// layout.layout(150f, 100f, list, size)
// val h = 100f - 7f - 9f
// assertEquals(h * 0.5f + 29f, list[0].height + list[1].height + list[2].height)
// assertEquals(Bounds(150f, 93f, baseline = 28f), size)
// }
}
7 changes: 3 additions & 4 deletions acornui-game/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*/

plugins {
id("com.polyforest.acornui.basic")
`maven-publish`
id("com.acornui.plugins.kotlin-mpp")
}

kotlin {
sourceSets {
commonMain {
dependencies {
implementation(project(":acornui-core"))
implementation(project(":acornui-utils"))
implementation("com.acornui:acornui-core")
implementation("com.acornui:acornui-utils")
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions acornui-spine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

plugins {
id("com.polyforest.acornui.basic")
`maven-publish`
id("com.acornui.plugins.kotlin-mpp")

}

kotlin {
sourceSets {
commonMain {
dependencies {
implementation(project(":acornui-core"))
implementation(project(":acornui-utils"))
implementation("com.acornui:acornui-core")
implementation("com.acornui:acornui-utils")
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions acornui-test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

plugins {
id("com.polyforest.acornui.basic")
`maven-publish`
id("com.acornui.plugins.kotlin-mpp")

}

kotlin {
Expand All @@ -26,7 +26,7 @@ kotlin {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))

implementation(project(":acornui-utils"))
implementation("com.acornui:acornui-utils")
}
}
named("jvmMain") {
Expand Down
27 changes: 13 additions & 14 deletions acornui-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@
*/

plugins {
id("com.polyforest.acornui.basic")
`maven-publish`
id("com.acornui.plugins.kotlin-mpp")
}

kotlin {
sourceSets {
commonTest {
dependencies {
implementation(project(":acornui-test-utils"))
}
}
jvmTest {
dependencies {
implementation(kotlin("reflect"))
}
}
}
sourceSets {
commonTest {
dependencies {
implementation("com.acornui:acornui-test-utils")
}
}
jvmTest {
dependencies {
implementation(kotlin("reflect"))
}
}
}
}
36 changes: 32 additions & 4 deletions acornui-utils/src/commonMain/kotlin/com/acornui/core/string.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,44 @@ fun String.compareTo2(other: String, ignoreCase: Boolean = false): Int {
compareTo(other)
}

private val wordSplitter = Regex("""([a-z]+|\d+|(?:[A-Z][a-z]+)|(?:[A-Z]+(?=(?:[A-Z][a-z])|[^A-Za-z]|[$\d\n]|\b)))([\W_]*)""")

/**
* Converts a string to underscore_case.
* E.g.
* thisIsATest becomes this_is_a_test
*
* This does not support unicode characters.
* See unit tests for more case examples.
*/
fun String.toUnderscoreCase(): String {
return replace(Regex("([a-z])([A-Z]+)"), "$1_$2").toLowerCase()
return replace(wordSplitter, "$1_").trimEnd('_').toLowerCase()
}

/**
* Converts a string to hyphen-case.
* E.g.
* thisIsATest becomes this-is-a-test
*
* This does not support unicode characters.
* See unit tests for more case examples.
*/
fun String.toHyphenCase(): String {
return replace(Regex("([a-z])([A-Z]+)"), "$1-$2").toLowerCase()
return replace(wordSplitter, "$1-").trimEnd('-').toLowerCase()
}

fun String.toFirstLowerCase(): String {
return this[0].toLowerCase() + substring(1)
/**
* Converts a string to camelCase.
* E.g.
* this-is-a-test becomes thisIsATest
*
* This does not support unicode characters.
* See unit tests for more case examples.
*/
fun String.toCamelCase(): String {
return wordSplitter.replace(this) {
it.groupValues[1].toLowerCase().capitalize()
}.decapitalize()
}

private val whitespaceChars = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import com.acornui.core.lineSeparator
import com.acornui.error.stack
import com.acornui.core.debug as debugFlag

@Deprecated("renamed to Logger", ReplaceWith("Logger"))
typealias ILogger = Logger

interface Logger {

companion object {
Expand Down
Loading