UI: auto-scrolling

This commit is contained in:
2026-09-01 16:57:21 +02:00
parent 9e010c7873
commit ef5ccb9274
4 changed files with 27 additions and 6 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ plugins {
} }
group = "com.jaytux.phoebench" group = "com.jaytux.phoebench"
version = rootProject.version as PhoebenchVersion version = PhoebenchVersion(1, 2, 1, "patch0")
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion)) if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
throw GradleException("CLI Client version must be at least as high as protocol/common version") throw GradleException("CLI Client version must be at least as high as protocol/common version")
+1 -1
View File
@@ -13,7 +13,7 @@ plugins {
alias(libs.plugins.buildconfig) alias(libs.plugins.buildconfig)
} }
version = rootProject.version as PhoebenchVersion version = PhoebenchVersion(1, 2, 1, "autoscroll")
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion)) if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
throw GradleException("UI Clients version must be at least as high as protocol/common version") throw GradleException("UI Clients version must be at least as high as protocol/common version")
@@ -6,6 +6,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -161,6 +162,15 @@ fun MonitorMessage(msg: ServerMonitorEvent.ITextEvent) = when(msg) {
@Composable @Composable
fun MonitorDialog(name: String, logs: List<ServerMonitorEvent.ITextEvent>, onClose: () -> Unit, onClear: () -> Unit) { 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)) { 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) { Surface(Modifier.padding(15.dp).fillMaxHeight(0.8f).widthIn(min = 300.dp, max = 2000.dp), shape = MaterialTheme.shapes.medium) {
Column(Modifier.padding(8.dp)) { Column(Modifier.padding(8.dp)) {
@@ -175,9 +185,20 @@ fun MonitorDialog(name: String, logs: List<ServerMonitorEvent.ITextEvent>, onClo
} }
else { else {
CompositionLocalProvider(LocalTextStyle provides LocalTextStyle.current.makeMonospaced()) { CompositionLocalProvider(LocalTextStyle provides LocalTextStyle.current.makeMonospaced()) {
LazyColumn(Modifier.weight(1f).padding(10.dp).background(MaterialTheme.colorScheme.surfaceDim)) { Box(Modifier.weight(1f)) {
items(logs) { LazyColumn(Modifier.fillMaxHeight().fillMaxWidth().padding(10.dp).background(MaterialTheme.colorScheme.surfaceDim), state) {
MonitorMessage(it) 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")
}
} }
} }
} }
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
} }
group = "com.jaytux.phoebench" group = "com.jaytux.phoebench"
version = rootProject.version as PhoebenchVersion version = PhoebenchVersion(1, 2, 1, "patch0")
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion)) if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
throw GradleException("Server version must be at least as high as protocol/common version") throw GradleException("Server version must be at least as high as protocol/common version")