Skip to content

Commit

Permalink
feat:为实现自定义选择文本做准备
Browse files Browse the repository at this point in the history
  • Loading branch information
Yricky committed Jul 22, 2024
1 parent c39869e commit 2b094d8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import me.yricky.oh.abcd.cfm.ClassItem
import me.yricky.oh.abcd.cfm.AbcClass
import me.yricky.oh.utils.Adler32

class AbcView(val abc: AbcBuf,override var hap:HapView? = null):AttachHapPage() {
class AbcView(val abc: AbcBuf,override val hap:HapView? = null):AttachHapPage() {

override val navString: String = "${hap?.navString ?: ""}${asNavString("ABC", abc.tag)}"
override val name: String = if(hap == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import me.yricky.oh.abcd.cfm.AbcMethod
import me.yricky.oh.abcd.cfm.AbcClass
import me.yricky.oh.abcd.cfm.isModuleRecordIdx

class ClassView(val classItem: AbcClass,override var hap:HapView? = null):AttachHapPage() {
class ClassView(val classItem: AbcClass,override val hap:HapView? = null):AttachHapPage() {
override val navString: String = "${hap?.navString ?: ""}${asNavString("CLZ", classItem.name)}"
override val name: String = "${hap?.name?:""}/${classItem.abc.tag}/${classItem.name}"
@OptIn(ExperimentalFoundationApi::class)
Expand Down
26 changes: 20 additions & 6 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/CodeView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.yricky.abcde.page

import androidx.compose.foundation.*
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
Expand All @@ -15,11 +16,12 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.*
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.HapSession
Expand All @@ -33,7 +35,7 @@ import me.yricky.oh.abcd.code.TryBlock
import me.yricky.oh.abcd.isa.Asm
import me.yricky.oh.abcd.isa.calledMethods

class CodeView(val code: Code,override var hap:HapView? = null):AttachHapPage() {
class CodeView(val code: Code,override val hap:HapView? = null):AttachHapPage() {
override val navString: String = "${hap?.navString ?: ""}${asNavString("ASM", code.method.defineStr(true))}"
override val name: String = "${hap?.name ?: ""}/${code.method.abc.tag}/${code.method.name}"
@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -95,7 +97,6 @@ class CodeView(val code: Code,override var hap:HapView? = null):AttachHapPage()
}
itemsIndexed(code.asm.list) { index, item ->
Row {
item.asm
DisableSelection {
val line = remember {
"$index ".let {
Expand All @@ -114,7 +115,6 @@ class CodeView(val code: Code,override var hap:HapView? = null):AttachHapPage()
tryBlock = null
})
}
item.asm
code.tryBlocks.forEach {
add(
ContextMenuItem(
Expand Down Expand Up @@ -187,8 +187,22 @@ class CodeView(val code: Code,override var hap:HapView? = null):AttachHapPage()
}
}
}, modifier = Modifier.fillMaxSize()) {
val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }
val pressIndicator = Modifier.pointerInput(item,layoutResult) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent(PointerEventPass.Main)
if (event.type == PointerEventType.Move) {
layoutResult.value?.let { layoutResult ->
// println(layoutResult.getOffsetForPosition(event.changes.first().position))
}
}
}
}
}
Text(
text = asmString[item]!!, style = codeStyle, modifier = Modifier.fillMaxWidth()
text = asmString[item]!!, style = codeStyle, modifier = Modifier.fillMaxWidth().then(pressIndicator),
onTextLayout = { layoutResult.value = it },
)
Text("\n", maxLines = 1, style = codeStyle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ class HapView(private val hap:ZipFile):Page() {
?.firstOrNull()?.data ?: hapConfig.app.label.indexStr
}
Text("名称:${name}")
Text("模块名:${hapConfig.module.name}")
Text("bundleName:${hapConfig.app.bundleName}")
Text("moduleName:${hapConfig.module.name}")
Text("版本:${hapConfig.app.versionName}(${hapConfig.app.versionCode})")
}
}
Expand Down
9 changes: 1 addition & 8 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/Page.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ sealed class Page{
}

sealed class AttachHapPage:Page(){
abstract var hap:HapView?
protected set

fun attachHap(hap:HapView){
if(this.hap == null){
this.hap = hap
}
}
abstract val hap:HapView?
}

val Page.shortName get() = name.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import me.yricky.oh.resde.ResIndexBuf
import me.yricky.oh.resde.ResType
import me.yricky.oh.resde.ResourceItem

class ResIndexView(val res:ResIndexBuf, name: String,override var hap:HapView? = null):AttachHapPage() {
class ResIndexView(val res:ResIndexBuf, name: String,override val hap:HapView? = null):AttachHapPage() {
companion object{
val emptyTable = ResTable()
}
Expand Down

0 comments on commit 2b094d8

Please sign in to comment.