Skip to content

Commit

Permalink
Get rid of dark blue highlight for cells with colored text
Browse files Browse the repository at this point in the history
Closes #68.
  • Loading branch information
torhus committed Dec 1, 2022
1 parent a369b27 commit 063ea0d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down
12 changes: 6 additions & 6 deletions src/playertable.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
});
Expand Down
46 changes: 19 additions & 27 deletions src/servertable.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class ServerTable
table_.addListener(SWT.PaintItem, new PaintItemListener);
}


sortListener_ = new SortListener;

for (int i = 0; i < table_.getColumnCount(); i++) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 063ea0d

Please sign in to comment.