Colour client rows in the channel tree: for everyone, while talking, while muted or away

Design settings on desktop and Android offer a few see-through presets
that suit light and dark themes alike, or a custom colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 21:47:51 +00:00
co-authored by Claude Opus 5.5
parent 4cdbdea9a2
commit 59176ea017
11 changed files with 408 additions and 15 deletions
@@ -378,7 +378,7 @@ class ServerController internal constructor(
treePending.set(false)
if (structureChanged.getAndSet(false)) roots = conn.model.buildTree()
_tree.value = ServerTree.of(roots, conn.model, conn.contacts, app.settings.colorContacts,
app.settings.countryFlags)
app.settings.countryFlags, app.settings.clientRowColors)
val serverName = if (session.isConnected) conn.model.serverName.orEmpty() else ""
val channelName = session.currentChannel()?.name.orEmpty()
_chats.update {
@@ -1,6 +1,7 @@
package com.ts3client.android
import androidx.compose.runtime.Immutable
import com.ts3client.config.ClientRowColors
import com.ts3client.contacts.ContactStore
import com.ts3client.contacts.ContactType
import com.ts3client.net.ChannelNode
@@ -91,14 +92,15 @@ data class ServerTree(
companion object {
fun of(roots: List<ChannelNode>, model: ServerModel, contacts: ContactStore, colorContacts: Boolean,
countryFlags: Boolean): ServerTree =
countryFlags: Boolean, rowColors: ClientRowColors): ServerTree =
ServerTree(
roots.map { channel(it, model, contacts, colorContacts) },
roots.map { channel(it, model, contacts, colorContacts, rowColors) },
model.serverIconId(),
countryFlags,
)
private fun channel(c: ChannelNode, model: ServerModel, contacts: ContactStore, colorContacts: Boolean): ChannelItem {
private fun channel(c: ChannelNode, model: ServerModel, contacts: ContactStore, colorContacts: Boolean,
rowColors: ClientRowColors): ChannelItem {
val clients = c.clients
val spacer = Spacers.parse(c.name)
return ChannelItem(
@@ -109,21 +111,24 @@ data class ServerTree(
locked = c.hasPassword,
full = c.maxClients >= 0 && clients.size >= c.maxClients,
subscribed = c.subscribed,
clients = clients.map { client(it, model, contacts, colorContacts) },
children = c.children.map { channel(it, model, contacts, colorContacts) },
clients = clients.map { client(it, model, contacts, colorContacts, rowColors) },
children = c.children.map { channel(it, model, contacts, colorContacts, rowColors) },
)
}
private fun client(c: ClientEntry, model: ServerModel, contacts: ContactStore, colorContacts: Boolean): ClientItem {
private fun client(c: ClientEntry, model: ServerModel, contacts: ContactStore, colorContacts: Boolean,
rowColors: ClientRowColors): ClientItem {
val contact = contacts.find(c.uniqueId)
val away = c.away && c.awayMessage.isNotEmpty() && contact?.ignoreAwayMessage != true
val status = ClientStatus.of(c)
return ClientItem(
id = c.id,
uniqueId = c.uniqueId,
nickname = c.nickname ?: "",
name = contact?.displayName(c.nickname) ?: c.nickname ?: "",
awayMessage = if (away) c.awayMessage else "",
status = ClientStatus.of(c),
status = status,
background = rowColors.of(status),
self = c.self,
contactType = contact?.type,
highlight = if (colorContacts) contact?.type ?: ContactType.NEUTRAL else ContactType.NEUTRAL,
@@ -169,6 +174,8 @@ data class ClientItem(
val name: String,
val awayMessage: String,
val status: ClientStatus,
/** The row's background colour, ARGB; 0 for none. */
val background: Int,
val self: Boolean,
/** How the client is filed in the contacts; null when it is not one. */
val contactType: ContactType?,
@@ -354,6 +354,12 @@ class SessionController(private val context: Context) {
servers.value.forEach { it.scheduleTree(structure = false) }
}
/** Puts new client row colours, already set in [settings], into effect. */
fun clientRowColorsChanged() {
settings.save()
servers.value.forEach { it.scheduleTree(structure = false) }
}
fun setDescriptionPictures(shown: Boolean) {
settings.descriptionPictures = shown
settings.save()
@@ -236,12 +236,15 @@ private fun RowLayout(
depth: Int,
onClick: (() -> Unit)?,
background: Color = Color.Transparent,
/** The colour under [background], which a flash or find match goes over. */
tint: Color = Color.Transparent,
onDoubleClick: (() -> Unit)? = null,
content: @Composable RowScope.() -> Unit,
) {
Row(
Modifier
.fillMaxWidth()
.background(tint)
.background(background)
.height(ROW)
.then(if (onClick != null) Modifier.combinedClickable(onDoubleClick = onDoubleClick, onClick = onClick) else Modifier)
@@ -314,7 +317,7 @@ private fun SpacerLabel(align: Char, caption: String, modifier: Modifier) {
@Composable
private fun ClientRow(row: TreeRow.Client, countryFlags: Boolean, background: Color, onClient: (ClientItem) -> Unit) {
val client = row.client
RowLayout(row.depth, onClick = { onClient(client) }, background = background) {
RowLayout(row.depth, onClick = { onClient(client) }, background = background, tint = Color(client.background)) {
Spacer(Modifier.width(ICON + 4.dp))
StatusIcon(client.status)
Row(Modifier.weight(1f), horizontalArrangement = Arrangement.spacedBy(4.dp)) {
@@ -0,0 +1,120 @@
package com.ts3client.android.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.ts3client.config.ClientRowColors
/** A row background: none, a preset, or a custom colour. [argb] is 0 for none. */
@Composable
internal fun RowColorPicker(label: String, argb: Int, onChange: (Int) -> Unit) {
var open by remember { mutableStateOf(false) }
var custom by remember { mutableStateOf(false) }
Box {
Row(Modifier.fillMaxWidth().clickable { open = true }.padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically) {
Column(Modifier.weight(1f)) {
Text(label)
Text(nameOf(argb), style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant)
}
Swatch(argb, 28.dp)
}
DropdownMenu(open, { open = false }) {
DropdownMenuItem({ Text("None") }, leadingIcon = { Swatch(0) }, onClick = {
open = false
onChange(0)
})
for (p in ClientRowColors.PRESETS) {
DropdownMenuItem({ Text(p.name()) }, leadingIcon = { Swatch(p.argb()) }, onClick = {
open = false
onChange(p.argb())
})
}
DropdownMenuItem({ Text("Custom…") }, onClick = {
open = false
custom = true
})
}
}
if (custom) {
CustomColorDialog(if (argb != 0) argb else 0x59808080, onDismiss = { custom = false }) {
custom = false
onChange(it)
}
}
}
private fun nameOf(argb: Int): String =
if (argb == 0) "None" else ClientRowColors.presetOf(argb)?.name() ?: "Custom"
@Composable
private fun CustomColorDialog(initial: Int, onDismiss: () -> Unit, onPick: (Int) -> Unit) {
var alpha by remember { mutableIntStateOf(initial ushr 24) }
var red by remember { mutableIntStateOf(initial shr 16 and 0xFF) }
var green by remember { mutableIntStateOf(initial shr 8 and 0xFF) }
var blue by remember { mutableIntStateOf(initial and 0xFF) }
val argb = (alpha shl 24) or (red shl 16) or (green shl 8) or blue
AlertDialog(
onDismissRequest = onDismiss,
title = { Text("Custom colour") },
text = {
Column {
Box(Modifier.fillMaxWidth().height(40.dp).clip(RoundedCornerShape(6.dp))
.background(MaterialTheme.colorScheme.surface)) {
Box(Modifier.fillMaxWidth().height(40.dp).background(Color(argb)))
}
Channel("Red", red) { red = it }
Channel("Green", green) { green = it }
Channel("Blue", blue) { blue = it }
Channel("Opacity", alpha) { alpha = it }
}
},
confirmButton = { TextButton({ onPick(argb) }, enabled = argb != 0) { Text("OK") } },
dismissButton = { TextButton(onDismiss) { Text("Cancel") } },
)
}
@Composable
private fun Channel(label: String, value: Int, onChange: (Int) -> Unit) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(label, Modifier.width(64.dp), style = MaterialTheme.typography.bodySmall)
Slider(value.toFloat(), { onChange(it.toInt()) }, Modifier.weight(1f), valueRange = 0f..255f)
}
}
/** The colour over the screen's background, as a row would show it; outlined so "none" shows too. */
@Composable
private fun Swatch(argb: Int, size: Dp = 20.dp) {
val shape = RoundedCornerShape(4.dp)
Box(Modifier.size(size).clip(shape).background(MaterialTheme.colorScheme.surface).background(Color(argb))
.border(1.dp, MaterialTheme.colorScheme.outline, shape))
}
@@ -8,6 +8,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@@ -52,7 +53,7 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
LinkRow("Giant PTT", "A push-to-talk button filling the screen", "CAPTURE") {
page = SettingsPage.GIANT_PTT
}
LinkRow("Design", "Icon pack, country flags, description pictures", "GUISETUP") {
LinkRow("Design", "Icon pack, country flags, client colours, description pictures", "GUISETUP") {
page = SettingsPage.DESIGN
}
LinkRow("Identities", "Create, import, export, security level",
@@ -70,15 +71,35 @@ private fun DesignScreen(vm: SessionController, onBack: () -> Unit) {
SubScreen("Design", onBack) { padding ->
Column(Modifier.padding(padding).verticalScroll(rememberScrollState())) {
IconPackPicker(vm.icons)
var pictures by remember { mutableStateOf(vm.settings.descriptionPictures) }
Toggle("Show pictures in descriptions", pictures) {
pictures = it
vm.setDescriptionPictures(it)
}
Section("Channel tree")
var flags by remember { mutableStateOf(vm.settings.countryFlags) }
Toggle("Show country flags in the channel tree", flags) {
flags = it
vm.setCountryFlags(it)
}
var pictures by remember { mutableStateOf(vm.settings.descriptionPictures) }
Toggle("Show pictures in descriptions", pictures) {
pictures = it
vm.setDescriptionPictures(it)
val colors = vm.settings.clientRowColors
var any by remember { mutableIntStateOf(colors.any) }
var talking by remember { mutableIntStateOf(colors.talking) }
var mutedAway by remember { mutableIntStateOf(colors.mutedAway) }
RowColorPicker("Client background", any) {
any = it
colors.any = it
vm.clientRowColorsChanged()
}
RowColorPicker("While talking", talking) {
talking = it
colors.talking = it
vm.clientRowColorsChanged()
}
RowColorPicker("Muted / away", mutedAway) {
mutedAway = it
colors.mutedAway = it
vm.clientRowColorsChanged()
}
}
}
@@ -0,0 +1,77 @@
package com.ts3client.config;
import com.ts3client.net.ClientStatus;
import java.util.List;
import java.util.Properties;
/**
* Background colours of client rows in the channel tree: one for every client, overridden
* by one while they talk and one while they are muted or away. Colours are ARGB; 0 is none.
*/
public final class ClientRowColors {
public record Preset(String name, int argb) {
}
/** See-through, so they tint the light and dark themes alike and the names stay readable. */
public static final List<Preset> PRESETS = List.of(
new Preset("Green", 0x594CAF50),
new Preset("Teal", 0x5926A69A),
new Preset("Blue", 0x5942A5F5),
new Preset("Purple", 0x59AB47BC),
new Preset("Pink", 0x59EC407A),
new Preset("Red", 0x59EF5350),
new Preset("Orange", 0x59FFA726),
new Preset("Yellow", 0x59FFEE58),
new Preset("Grey", 0x599E9E9E));
private static final String PREFIX = "clientRowColor.";
public int any;
public int talking;
public int mutedAway;
/** The colour of a row showing {@code status}; 0 for none. */
public int of(ClientStatus status) {
int own = switch (status) {
case TALKING, COMMANDER_TALKING -> talking;
case SPEAKERS_DISABLED, SPEAKERS_MUTED, MIC_DISABLED, MIC_MUTED, AWAY -> mutedAway;
default -> 0;
};
return own != 0 ? own : any;
}
/** The preset named for {@code argb}, or {@code null} for a custom colour or none. */
public static Preset presetOf(int argb) {
for (Preset p : PRESETS) {
if (p.argb() == argb) return p;
}
return null;
}
void load(Properties p) {
any = parse(p.getProperty(PREFIX + "any"));
talking = parse(p.getProperty(PREFIX + "talking"));
mutedAway = parse(p.getProperty(PREFIX + "mutedAway"));
}
void store(Properties p) {
p.setProperty(PREFIX + "any", format(any));
p.setProperty(PREFIX + "talking", format(talking));
p.setProperty(PREFIX + "mutedAway", format(mutedAway));
}
private static int parse(String v) {
if (v == null || v.isBlank()) return 0;
try {
return (int) Long.parseLong(v.trim().replace("#", ""), 16);
} catch (NumberFormatException e) {
return 0;
}
}
private static String format(int argb) {
return argb == 0 ? "" : String.format("#%08X", argb);
}
}
@@ -181,6 +181,8 @@ public final class Settings {
* their details show it beside their name either way.
*/
public boolean countryFlags = false;
/** Background colours of client rows in the channel tree. */
public final ClientRowColors clientRowColors = new ClientRowColors();
/** Extra folder to look for icon packs in, on top of the well-known locations. */
public String iconPackDir = "";
@@ -314,6 +316,7 @@ public final class Settings {
desktopNotifications = parseB(props.getProperty("desktopNotifications"), desktopNotifications);
iconPack = props.getProperty("iconPack", iconPack);
countryFlags = parseB(props.getProperty("countryFlags"), countryFlags);
clientRowColors.load(props);
iconPackDir = props.getProperty("iconPackDir", iconPackDir);
appearance = parseEnum(Appearance.class, props.getProperty("appearance"), appearance);
uiScale = parseD(props.getProperty("uiScale"), uiScale);
@@ -375,6 +378,7 @@ public final class Settings {
props.setProperty("desktopNotifications", Boolean.toString(desktopNotifications));
props.setProperty("iconPack", iconPack);
props.setProperty("countryFlags", Boolean.toString(countryFlags));
clientRowColors.store(props);
props.setProperty("iconPackDir", iconPackDir);
props.setProperty("appearance", appearance.name());
props.setProperty("uiScale", Double.toString(uiScale));
@@ -30,7 +30,7 @@ import java.util.Arrays;
/**
* Options page for how the client looks: the light or dark look-and-feel, the interface
* scale, and the icon pack the user interface is drawn with — where to look for more of
* scale, the channel tree's flags and row colours, and the icon pack the user interface is drawn with — where to look for more of
* them, and a viewer showing everything the active pack contains.
*
* <p>Theme and pack apply right away so the change can be seen in the window behind the
@@ -61,6 +61,9 @@ final class DesignPanel extends JPanel {
private final JLabel packInfo = new JLabel();
private final JTextField packDirField;
private final JCheckBox countryFlags = new JCheckBox("Show country flags in the channel tree");
private final RowColorCombo anyColor;
private final RowColorCombo talkingColor;
private final RowColorCombo mutedAwayColor;
private final DefaultListModel<String> previewModel = new DefaultListModel<>();
private final JList<String> preview = new JList<>(previewModel);
@@ -71,6 +74,9 @@ final class DesignPanel extends JPanel {
this.originalPackDir = settings.iconPackDir;
this.originalAppearance = settings.appearance;
this.packDirField = new JTextField(settings.iconPackDir, 18);
this.anyColor = new RowColorCombo(settings.clientRowColors.any);
this.talkingColor = new RowColorCombo(settings.clientRowColors.talking);
this.mutedAwayColor = new RowColorCombo(settings.clientRowColors.mutedAway);
setBorder(new ScaledEmptyBorder(12, 12, 12, 12));
add(buildHeader(), BorderLayout.NORTH);
@@ -87,6 +93,9 @@ final class DesignPanel extends JPanel {
Object selected = packCombo.getSelectedItem();
settings.iconPack = selected instanceof IconPack pack ? pack.id() : "";
settings.countryFlags = countryFlags.isSelected();
settings.clientRowColors.any = anyColor.value();
settings.clientRowColors.talking = talkingColor.value();
settings.clientRowColors.mutedAway = mutedAwayColor.value();
originalPackId = settings.iconPack;
originalPackDir = settings.iconPackDir;
originalAppearance = settings.appearance;
@@ -155,6 +164,9 @@ final class DesignPanel extends JPanel {
}
FormPanel.addSection(p, c, row++, "Channel Tree");
FormPanel.addWide(p, c, row++, countryFlags);
FormPanel.addRow(p, c, row++, new JLabel("Client background:"), anyColor);
FormPanel.addRow(p, c, row++, new JLabel("While talking:"), talkingColor);
FormPanel.addRow(p, c, row++, new JLabel("Muted / away:"), mutedAwayColor);
FormPanel.addSection(p, c, row++, "Icon Pack");
FormPanel.addRow(p, c, row++, new JLabel("Icon pack:"), packCombo);
c.gridx = 1;
@@ -5,6 +5,7 @@ import com.ts3client.config.Settings;
import com.ts3client.net.ChannelNode;
import com.ts3client.net.Spacers;
import com.ts3client.net.ClientEntry;
import com.ts3client.net.ClientStatus;
import com.ts3client.net.ServerModel;
import javax.swing.Icon;
@@ -13,6 +14,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -161,6 +163,7 @@ final class DropIndicatorTree extends JTree {
Rectangle clip = g.getClipBounds();
g.setColor(getBackground());
g.fillRect(clip.x, clip.y, clip.width, clip.height);
paintClientColors(g);
paintSearchHits(g);
paintSelection(g);
paintHover(g);
@@ -206,6 +209,23 @@ final class DropIndicatorTree extends JTree {
}
}
/** Fills client rows across the full width in the colour chosen for what they are doing. */
private void paintClientColors(Graphics g) {
Rectangle visible = getVisibleRect();
int first = Math.max(0, getClosestRowForLocation(visible.x, visible.y));
for (int row = first; row < getRowCount(); row++) {
Rectangle bounds = getRowBounds(row);
if (bounds == null) continue;
if (bounds.y > visible.y + visible.height) break;
Object obj = ((DefaultMutableTreeNode) getPathForRow(row).getLastPathComponent()).getUserObject();
if (!(obj instanceof ClientEntry cl)) continue;
int argb = settings.clientRowColors.of(ClientStatus.of(cl));
if (argb == 0) continue;
g.setColor(new Color(argb, true));
g.fillRect(visible.x, bounds.y, visible.width, bounds.height);
}
}
private void paintSearchHits(Graphics g) {
if (searchHits.isEmpty()) return;
Rectangle visible = getVisibleRect();
@@ -0,0 +1,123 @@
package com.ts3client.ui;
import com.formdev.flatlaf.util.UIScale;
import com.ts3client.config.ClientRowColors;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
/**
* Picks a row background: none, one of {@link ClientRowColors#PRESETS}, or a custom
* colour from a colour chooser. The value is ARGB, 0 for none.
*/
final class RowColorCombo extends JComboBox<RowColorCombo.Option> {
record Option(String name, int argb, boolean custom) {
}
private static final Option NONE = new Option("None", 0, false);
/** The last item, holding whichever custom colour was chosen. */
private Option custom;
private Option previous;
private boolean choosing;
RowColorCombo(int argb) {
addItem(NONE);
for (ClientRowColors.Preset p : ClientRowColors.PRESETS) addItem(new Option(p.name(), p.argb(), false));
boolean isCustom = argb != 0 && ClientRowColors.presetOf(argb) == null;
custom = new Option("Custom…", isCustom ? argb : 0, true);
addItem(custom);
setValue(argb);
previous = (Option) getSelectedItem();
setMaximumRowCount(getItemCount());
setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean selected, boolean focus) {
super.getListCellRendererComponent(list, value, index, selected, focus);
Option o = (Option) value;
setText(o == null ? "" : o.name());
setIcon(o == null ? null : new Swatch(o.argb()));
return this;
}
});
addActionListener(e -> onSelected());
}
int value() {
Option o = (Option) getSelectedItem();
return o == null ? 0 : o.argb();
}
private void setValue(int argb) {
for (int i = 0; i < getItemCount(); i++) {
Option o = getItemAt(i);
if (o.argb() == argb && (argb != 0 || o == NONE)) {
setSelectedIndex(i);
return;
}
}
setSelectedItem(NONE);
}
private void onSelected() {
Option o = (Option) getSelectedItem();
if (o == null || choosing) return;
if (!o.custom()) {
previous = o;
return;
}
choosing = true;
try {
int start = custom.argb() != 0 ? custom.argb() : previous.argb() != 0 ? previous.argb() : 0x59808080;
Color picked = JColorChooser.showDialog(this, "Row Colour", new Color(start, true), true);
if (picked == null || picked.getRGB() == 0) {
setSelectedItem(previous);
return;
}
Option chosen = new Option("Custom…", picked.getRGB(), true);
removeItem(custom);
custom = chosen;
addItem(custom);
setSelectedItem(custom);
previous = custom;
} finally {
choosing = false;
}
}
/** A small square of the colour over the tree's background, as a row shows it. */
private record Swatch(int argb) implements Icon {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
int size = getIconWidth();
g.setColor(UIManager.getColor("Tree.background"));
g.fillRect(x, y, size, size);
if (argb != 0) {
g.setColor(new Color(argb, true));
g.fillRect(x, y, size, size);
}
g.setColor(UIManager.getColor("Component.borderColor"));
g.drawRect(x, y, size - 1, size - 1);
}
@Override
public int getIconWidth() {
return UIScale.scale(14);
}
@Override
public int getIconHeight() {
return getIconWidth();
}
}
}