Skip to content

Commit

Permalink
just a few somethings, working on uninit.ui
Browse files Browse the repository at this point in the history
  • Loading branch information
aenriii committed Jun 1, 2024
1 parent ab9e8ce commit 1a94a36
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 25 deletions.
2 changes: 1 addition & 1 deletion genesis/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ kotlin {

implementation(project(":uninit:common"))
implementation(project(":uninit:common-compose"))
implementation(project(":uninit:ui"))
implementation(project(":genesis:discord:api"))
implementation(project(":genesis:discord:client"))
implementation(project(":genesis:genesisApi"))

}

Expand Down
10 changes: 0 additions & 10 deletions uninit/common/src/commonMain/kotlin/uninit/common/Quad.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package uninit.common.collections

import kotlin.jvm.JvmInline

//open class Four<T, U, V, W>(
// val first: T,
// val second: U,
// val third: V,
// val fourth: W,
//) {
// override fun toString(): String = "Four($first, $second, $third, $fourth)"
//}


@JvmInline value class Four<T> ( internal val it: Array<T> ) : Collection<T> {
override val size: Int
get() = 4
init {
require(it.size == 4)
}
val first: T get() = it[0]
val second: T get() = it[1]
val third: T get() = it[2]
val fourth: T get() = it[3]

override fun toString(): String = "Four($first, $second, $third, $fourth)"
operator fun component1(): T = first
operator fun component2(): T = second
operator fun component3(): T = third
operator fun component4(): T = fourth
operator fun get(index: Int): T = it[index]
override fun contains(element: T): Boolean {
return first == element || second == element || third == element || fourth == element
}
override fun containsAll(elements: Collection<T>): Boolean {
return elements.all { contains(it) }
}
override fun isEmpty(): Boolean = false
override fun iterator(): Iterator<T> = it.iterator()
}

val <T> Array<T>.four: Four<T>
get() = Four(this)
19 changes: 11 additions & 8 deletions uninit/common/src/commonMain/kotlin/uninit/common/color/RGBA.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package uninit.common.color

import uninit.common.Quad
import uninit.common.collections.Four
import uninit.common.collections.four

class RGBA(
val r: Int,
val g: Int,
val b: Int,
val a: Int = 255,
) : Quad<Int, Int, Int, Int>(r, g, b, a){
){
init {
require(r in 0..255)
require(g in 0..255)
require(b in 0..255)
require(a in 0..255)
}

override fun toString(): String = "RGBA($r, $g, $b, $a)"
fun toFloat(): Quad<Float, Float, Float, Float> = Quad(
r / 255f,
g / 255f,
b / 255f,
a / 255f,
)
fun toFloat(): Four<Float> =
arrayOf(
r / 255f,
g / 255f,
b / 255f,
a / 255f
).four
companion object {
fun hex(it: String): RGBA {
require(it.length in 6..9)
Expand Down
2 changes: 1 addition & 1 deletion uninit/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ kotlin {

android {
compileSdk = (findProperty("android.compileSdk") as String).toInt()
namespace = "uninit.common"
namespace = "uninit.ui"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
Expand Down
5 changes: 0 additions & 5 deletions uninit/ui/src/commonMain/kotlin/uninit/ui/UIKit.kt

This file was deleted.

24 changes: 24 additions & 0 deletions uninit/ui/src/commonMain/kotlin/uninit/ui/application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uninit.ui

import androidx.compose.runtime.Composable
import uninit.ui.application.ApplicationConfigurationScope
import uninit.ui.application.ApplicationScope

@Composable
fun application(
config: ApplicationConfigurationScope.() -> Unit = {},
content: @Composable ApplicationScope.() -> Unit)
{

}

@Composable
@Deprecated(level = DeprecationLevel.ERROR, message = "Not intended for use")
private fun example() = application({
applicationName = "My New Application"
useWebview = true
}) {
ui.ElevatedBox {
ui.Text("Hello, World!")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package uninit.ui.application

import uninit.ui.theme.ThemeRegistry

class ApplicationConfigurationScope {
/**
* List of modules to be loaded by Koin.
*/
var koinModules = mutableListOf<Any>() // FIXME

/**
* Whether to download the webview modules on
* desktop platforms. Requires
*/
var useWebview = false

/**
* The theme to use for the application.
*
* Will default to the theme with the ID that
* matches the preference [themePreferenceName] in
* the PreferencesManager.
*/
var themeId: String? = null

/**
* The name of the preference to use for the theme ID.
* Defaults to "currentThemeId".
*/
var themePreferenceName = "currentThemeId"

/**
* The theme registry to use for the application.
*
* Defaults to the singleton instance of ThemeRegistry.
*/
var themeRegistry: ThemeRegistry = ThemeRegistry

/**
* The default theme ID to use if no theme ID is set
* and no theme ID is found in the preferences.
*
* This will also set the theme ID in the preferences
* if no theme ID is set.
*
* Defaults to "Catppuccin/Mocha/Pink".
*/
var defaultThemeId: String = "Catppuccin/Mocha/Pink"


/**
* The UI kit to use for the application.
*
* Will default to the ui kit with the ID that
* matches the preference [uikitPreferenceName] in
* the PreferencesManager.
*/
var uikitId: String? = null

/**
* The name of the preference to use for the UI kit ID.
*
* Defaults to "currentUIKitId".
*/

var uikitPreferenceName = "currentUIKitId"

/**
* The default UI kit ID to use if no UI kit ID is set
* and no UI kit ID is found in the preferences.
*
* This will also set the UI kit ID in the preferences
* if no UI kit ID is set.
*
* Defaults to "builtin/uninit".
*/

var defaultUIKitId = "builtin/uninit"

/**
* The name of the application.
*/
var applicationName: String? = null

/**
* The version of the application.
*/
var applicationVersion: String? = null

/**
* Whether the application's name is normalized
* to lowercase dash-delimited on linux when
* creating directories and files.
*
* This setting only applies to linux, and
* only effects ASCII application names
*
* Example: "My App" -> "my-app"
*/
var normalizeApplicationName = true

/**
* Which directory to use for the application's
* cache and data storage on Windows.
*
* Use the `%APP_NAME%` placeholder to insert the
* application name into the path.
*
* Defaults to the user's Local AppData directory.
*/
var windowsDataDirectory: String? = null

/**
* Which directory to use for the application's
* cache and data storage on macOS.
*
* Use the `%APP_NAME%` placeholder to insert the
* application name into the path.
*
* Defaults to the user's Application Support directory.
*/
var macDataDirectory: String? = null

/**
* Which directory to use for the application's
* cache and data storage on Linux.
*
*
* Use the `%APP_NAME%` placeholder to insert the
* application name into the path.
*
* Defaults to "~/.%APP_NAME%".
*/
var linuxDataDirectory: String? = null

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uninit.ui.application

import uninit.ui.kit.UIKit

class ApplicationScope {
val ui: UIKit
get() = TODO()
val preferences: Any /* TODO: PreferencesManager */
get() = TODO()
}
15 changes: 15 additions & 0 deletions uninit/ui/src/commonMain/kotlin/uninit/ui/composites.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uninit.ui

import androidx.compose.runtime.compositionLocalOf
import uninit.ui.kit.UIKit
import uninit.ui.theme.ApplicationTheme

val LocalUIKit = compositionLocalOf<UIKit> {
error("No UIKit provided")
}
val LocalApplicationTheme = compositionLocalOf<ApplicationTheme> {
error("No ApplicationTheme provided")
}
val LocalMutableWindowTitle = compositionLocalOf<String> {
""
}
20 changes: 20 additions & 0 deletions uninit/ui/src/commonMain/kotlin/uninit/ui/kit/UIKit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uninit.ui.kit

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle


interface UIKit {
@Composable
fun Text(
text: String,
style: TextStyle = TextStyle.Default,
modifier: Modifier = Modifier
)
@Composable
fun ElevatedBox(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
)
}

0 comments on commit 1a94a36

Please sign in to comment.