From 063ea0da798945ec34a0ffced590ce1ed155951b Mon Sep 17 00:00:00 2001 From: torhus Date: Thu, 1 Dec 2022 21:03:11 +0100 Subject: [PATCH] Get rid of dark blue highlight for cells with colored text Closes #68. --- CHANGELOG.TXT | 2 ++ src/playertable.d | 12 ++++++------ src/servertable.d | 46 +++++++++++++++++++--------------------------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 037a8b8..081f07e 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -9,6 +9,8 @@ Work in progress or upgrade, instead of being included in the installer. This should work better when multiple user accounts are involved. It is still included in the ZIP package. +- Fix: The name column is no longer highlighted in dark blue for selected + servers or players. v0.9i - 2022-11-18 ------------------ diff --git a/src/playertable.d b/src/playertable.d index c0751d6..df5a626 100644 --- a/src/playertable.d +++ b/src/playertable.d @@ -69,15 +69,18 @@ class PlayerTable if (getSetting("coloredNames") == "true") { table_.addListener(SWT.EraseItem, new class Listener { void handleEvent(Event e) { - if (e.index == PlayerColumn.NAME) + if (e.index == PlayerColumn.NAME && + !(e.detail & SWT.SELECTED)) e.detail &= ~SWT.FOREGROUND; } }); table_.addListener(SWT.PaintItem, new class Listener { void handleEvent(Event e) { - if (e.index != PlayerColumn.NAME) + if (e.index != PlayerColumn.NAME || + (e.detail & SWT.SELECTED)) { return; + } TableItem item = cast(TableItem) e.item; string[] data = players_[table_.indexOf(item)].data; scope tl = new TextLayout(Display.getDefault); @@ -88,10 +91,7 @@ class PlayerTable foreach (r; parseColors(rawName, useEtColors).ranges) tl.setStyle(r.style, r.start, r.end); - if (e.detail & SWT.SELECTED) - e.gc.drawString(tl.getText, e.x+2, e.y); - else - tl.draw(e.gc, e.x+2, e.y); + tl.draw(e.gc, e.x + 2, e.y + 2); tl.dispose(); } }); diff --git a/src/servertable.d b/src/servertable.d index b76fcc1..7ff923a 100644 --- a/src/servertable.d +++ b/src/servertable.d @@ -106,7 +106,6 @@ class ServerTable table_.addListener(SWT.PaintItem, new PaintItemListener); } - sortListener_ = new SortListener; for (int i = 0; i < table_.getColumnCount(); i++) { @@ -534,44 +533,37 @@ private: class EraseItemListener : Listener { void handleEvent(Event e) { - if (e.index == ServerColumn.NAME && coloredNames_ || - e.index == ServerColumn.PASSWORDED) + if ((e.index == ServerColumn.NAME && coloredNames_ && + !(e.detail & SWT.SELECTED)) || + e.index == ServerColumn.PASSWORDED) e.detail &= ~SWT.FOREGROUND; } } class PaintItemListener : Listener { void handleEvent(Event e) { - if (!((e.index == ServerColumn.NAME && coloredNames_) || - e.index == ServerColumn.PASSWORDED)) + if (!((e.index == ServerColumn.NAME && coloredNames_ && + !(e.detail & SWT.SELECTED)) || + e.index == ServerColumn.PASSWORDED)) return; TableItem item = cast(TableItem) e.item; - auto i = table_.indexOf(item); - ServerData sd = serverList_.getFiltered(i); - - enum { leftMargin = 2 } + ServerData sd = serverList_.getFiltered(table_.indexOf(item)); switch (e.index) { - case ServerColumn.NAME: - auto textX = e.x + leftMargin; - if (!(e.detail & SWT.SELECTED)) { - TextLayout tl = new TextLayout(Display.getDefault); - tl.setText(sd.server[ServerColumn.NAME]); - - bool useEtColors = serverList_.useEtColors; - auto name = parseColors(sd.rawName, useEtColors); - foreach (r; name.ranges) - tl.setStyle(r.style, r.start, r.end); - - tl.draw(e.gc, textX, e.y); - tl.dispose(); - } - else { - auto name = sd.server[ServerColumn.NAME]; - e.gc.drawString(name, textX, e.y); - } + case ServerColumn.NAME: { + TextLayout tl = new TextLayout(Display.getDefault); + tl.setText(sd.server[ServerColumn.NAME]); + + bool useEtColors = serverList_.useEtColors; + auto name = parseColors(sd.rawName, useEtColors); + foreach (r; name.ranges) + tl.setStyle(r.style, r.start, r.end); + + tl.draw(e.gc, e.x + 5, e.y + 2); + tl.dispose(); break; + } case ServerColumn.PASSWORDED: if (sd.server[ServerColumn.PASSWORDED] == PASSWORD_YES) e.gc.drawImage(padlockImage_, e.x+4, e.y+1);