Skip to content

Commit

Permalink
feat:提取公共UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Yricky committed Jun 22, 2024
1 parent ac1b018 commit 516c3a1
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ModuleLiteralArray(
} else null

override fun toString(): String {
return "$moduleRequest.$importName as $localName"
return "import $moduleRequest.$importName as $localName"
}
companion object{
fun parseFrom(mla: ModuleLiteralArray,offset: Int):RegularImport{
Expand Down Expand Up @@ -131,7 +131,7 @@ class ModuleLiteralArray(
mla.abc.stringItem(exportNameOffset).value
} else null
override fun toString(): String {
return "LocalExport(l:$localName, ex:$exportName)"
return "export $localName.$exportName"
}
companion object{
fun parseFrom(mla: ModuleLiteralArray,offset: Int):LocalExport{
Expand Down
4 changes: 2 additions & 2 deletions abcde/src/jvmMain/kotlin/me/yricky/oh/abcd/isa/Asm.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import me.yricky.oh.abcd.isa.bean.Isa

actual fun loadInnerAsmMap(): AsmMap {
val yaml = Yaml(configuration = YamlConfiguration(strictMode = false))

return AsmMap(yaml.decodeFromString(Isa.serializer(),Asm::class.java.classLoader.getResourceAsStream("abcde/isa.yaml").reader().readText()))
return AsmMap(yaml.decodeFromString(Isa.serializer(),
Asm::class.java.classLoader.getResourceAsStream("abcde/isa.yaml")!!.reader().readText()))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package me.yricky.abcde.content

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import me.yricky.abcde.ui.LazyColumnWithScrollBar
import me.yricky.abcde.ui.icon
import me.yricky.oh.abcd.cfm.AbcClass

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ModuleInfoContent(
modifier: Modifier,
clazz: AbcClass
){
Column(modifier) {
Row(verticalAlignment = Alignment.CenterVertically) {
Image(clazz.icon(), null, modifier = Modifier.padding(8.dp).size(24.dp))
Text(clazz.name, style = MaterialTheme.typography.titleLarge)
}
LazyColumnWithScrollBar {
clazz.moduleInfo?.let { m ->
stickyHeader {
Text("ModuleRequests(${m.moduleRequestNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.moduleRequests){
Text("- $it")
}
stickyHeader {
Text("RegularImports(${m.regularImportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.regularImports){
Column(Modifier.padding(4.dp)) {
Text("- ${it}")
}
}
stickyHeader {
Text("NamespaceImports(${m.namespaceImportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.namespaceImports){
Column(Modifier.padding(4.dp)) {
Text("- localName:${it.localName}")
Text("- moduleRequest:${it.moduleRequest}")
}
}
stickyHeader {
Text("LocalExports(${m.localExportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.localExports){
Column(Modifier.padding(4.dp)) {
Text("- ${it}")
}
}
stickyHeader {
Text("IndirectExports(${m.indirectExportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.indirectExports){
Column(Modifier.padding(4.dp)) {
Text("- importName:${it.importName}")
Text("- exportName:${it.exportName}")
Text("- moduleRequest:${it.moduleRequest}")
}
}
stickyHeader {
Text("StarExports(${m.starExportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.starExports){
Column {
Text("- moduleRequest:${it.moduleRequest}")
}
}
}
}
}
}
64 changes: 2 additions & 62 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/ClassView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import me.yricky.abcde.AppState
import me.yricky.abcde.content.ModuleInfoContent
import me.yricky.abcde.ui.*
import me.yricky.oh.abcd.cfm.AbcField
import me.yricky.oh.abcd.cfm.AbcMethod
Expand Down Expand Up @@ -138,68 +139,7 @@ fun ClassViewPage(
}, composeSelectContent{ _:Boolean ->
Image(Icons.pkg(), null, Modifier.fillMaxSize().alpha(0.5f), colorFilter = grayColorFilter)
} to composeContent{
Column(Modifier.fillMaxSize()) {
Row(verticalAlignment = Alignment.CenterVertically) {
Image(clazz.icon(), null, modifier = Modifier.padding(8.dp).size(24.dp))
Text(clazz.name, style = MaterialTheme.typography.titleLarge)
}
LazyColumnWithScrollBar {
clazz.moduleInfo?.let { m ->
stickyHeader {
Text("ModuleRequests(${m.moduleRequestNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.moduleRequests){
Text("- $it")
}
stickyHeader {
Text("RegularImports(${m.regularImportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.regularImports){
Column(Modifier.padding(4.dp)) {
Text("- localName:${it.localName}")
Text("- importName:${it.importName}")
Text("- moduleRequest:${it.moduleRequest}")
}
}
stickyHeader {
Text("NamespaceImports(${m.namespaceImportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.namespaceImports){
Column(Modifier.padding(4.dp)) {
Text("- localName:${it.localName}")
Text("- moduleRequest:${it.moduleRequest}")
}
}
stickyHeader {
Text("LocalExports(${m.localExportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.localExports){
Column(Modifier.padding(4.dp)) {
Text("- localName:${it.localName}")
Text("- exportName:${it.exportName}")
}
}
stickyHeader {
Text("IndirectExports(${m.indirectExportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.indirectExports){
Column(Modifier.padding(4.dp)) {
Text("- importName:${it.importName}")
Text("- exportName:${it.exportName}")
Text("- moduleRequest:${it.moduleRequest}")
}
}
stickyHeader {
Text("StarExports(${m.starExportNum})",Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface))
}
items(m.starExports){
Column {
Text("- moduleRequest:${it.moduleRequest}")
}
}
}
}
}
ModuleInfoContent(Modifier.fillMaxSize(),clazz)
}
))
}
11 changes: 10 additions & 1 deletion abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/CodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.platform.Font
import androidx.compose.ui.unit.dp
import me.yricky.abcde.AppState
import me.yricky.abcde.content.ModuleInfoContent
import me.yricky.abcde.ui.*
import me.yricky.oh.abcd.cfm.AbcClass
import me.yricky.oh.abcd.cfm.AbcMethod
import me.yricky.oh.abcd.cfm.FieldType
import me.yricky.oh.abcd.code.Code
import me.yricky.oh.abcd.code.TryBlock
import me.yricky.oh.abcd.isa.calledMethods
Expand Down Expand Up @@ -201,7 +204,7 @@ fun CodeViewPage(modifier: Modifier, appState: AppState, method: AbcMethod, code
}
}
}, composeSelectContent { _: Boolean ->
Image(Icons.pkg(), null, Modifier.fillMaxSize().alpha(0.5f), colorFilter = grayColorFilter)
Image(Icons.listFiles(), null, Modifier.fillMaxSize().alpha(0.5f), colorFilter = grayColorFilter)
} to composeContent {
Column(Modifier.fillMaxSize()) {
LazyColumnWithScrollBar {
Expand All @@ -210,6 +213,12 @@ fun CodeViewPage(modifier: Modifier, appState: AppState, method: AbcMethod, code
}
}
}
}, (method.clazz as? FieldType.ClassType)?.let { it.clazz as? AbcClass }?.let { clazz ->
composeSelectContent{ _:Boolean ->
Image(Icons.pkg(), null, Modifier.fillMaxSize().alpha(0.5f), colorFilter = grayColorFilter)
} to composeContent{
ModuleInfoContent(Modifier.fillMaxSize(),clazz)
}
}
))
}

0 comments on commit 516c3a1

Please sign in to comment.