UI: auto-scrolling
This commit is contained in:
@@ -9,7 +9,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.jaytux.phoebench"
|
||||
version = rootProject.version as PhoebenchVersion
|
||||
version = PhoebenchVersion(1, 2, 1, "patch0")
|
||||
|
||||
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
|
||||
throw GradleException("CLI Client version must be at least as high as protocol/common version")
|
||||
|
||||
@@ -13,7 +13,7 @@ plugins {
|
||||
alias(libs.plugins.buildconfig)
|
||||
}
|
||||
|
||||
version = rootProject.version as PhoebenchVersion
|
||||
version = PhoebenchVersion(1, 2, 1, "autoscroll")
|
||||
|
||||
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
|
||||
throw GradleException("UI Clients version must be at least as high as protocol/common version")
|
||||
|
||||
+24
-3
@@ -6,6 +6,7 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -161,6 +162,15 @@ fun MonitorMessage(msg: ServerMonitorEvent.ITextEvent) = when(msg) {
|
||||
|
||||
@Composable
|
||||
fun MonitorDialog(name: String, logs: List<ServerMonitorEvent.ITextEvent>, onClose: () -> Unit, onClear: () -> Unit) {
|
||||
var autoFollow by remember { mutableStateOf(true) }
|
||||
val state = rememberLazyListState()
|
||||
|
||||
LaunchedEffect(autoFollow, logs) {
|
||||
if(autoFollow) {
|
||||
state.animateScrollToItem(logs.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
Dialog(onDismissRequest = onClose, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
Surface(Modifier.padding(15.dp).fillMaxHeight(0.8f).widthIn(min = 300.dp, max = 2000.dp), shape = MaterialTheme.shapes.medium) {
|
||||
Column(Modifier.padding(8.dp)) {
|
||||
@@ -175,9 +185,20 @@ fun MonitorDialog(name: String, logs: List<ServerMonitorEvent.ITextEvent>, onClo
|
||||
}
|
||||
else {
|
||||
CompositionLocalProvider(LocalTextStyle provides LocalTextStyle.current.makeMonospaced()) {
|
||||
LazyColumn(Modifier.weight(1f).padding(10.dp).background(MaterialTheme.colorScheme.surfaceDim)) {
|
||||
items(logs) {
|
||||
MonitorMessage(it)
|
||||
Box(Modifier.weight(1f)) {
|
||||
LazyColumn(Modifier.fillMaxHeight().fillMaxWidth().padding(10.dp).background(MaterialTheme.colorScheme.surfaceDim), state) {
|
||||
items(logs) {
|
||||
MonitorMessage(it)
|
||||
}
|
||||
}
|
||||
|
||||
Box(Modifier.align(Alignment.TopEnd).padding(25.dp)) {
|
||||
val colors = if(autoFollow)
|
||||
IconButtonDefaults.iconButtonColors(containerColor = LocalContentColor.current, contentColor = MaterialTheme.colorScheme.surface)
|
||||
else IconButtonDefaults.iconButtonColors(containerColor = MaterialTheme.colorScheme.surface, contentColor = LocalContentColor.current)
|
||||
IconButton({ autoFollow = !autoFollow }, colors = colors) {
|
||||
Icon(Lucide.ArrowDownToLine, "Follow")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user