Skip to content

Commit

Permalink
Fix #387 - consistent selection highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbrittain committed Jun 22, 2024
1 parent 17cdc87 commit 55b927a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LATEST
- Added border option to PopupMenu
- Fixed double-width alignment issues on DropdownList
- Improved TextBox line wrapping to break on word boundaries.
- Fixed logic for highlighting selected widget controls without focus.

1.15.0
------
Expand Down
4 changes: 2 additions & 2 deletions asciimatics/widgets/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def update(self, frame_no):

# Render this checkbox.
check_char = "✓" if self._frame.canvas.unicode_aware else "X"
(colour, attr, bg) = self._pick_colours("control", self._has_focus)
(colour, attr, bg) = self._pick_colours("control", self._has_focus or self._value)
self._frame.canvas.print_at(
f"[{check_char if self._value else ' '}] ",
self._x + self._offset,
self._y,
colour, attr, bg)
(colour, attr, bg) = self._pick_colours("field", self._has_focus)
(colour, attr, bg) = self._pick_colours("field", self._has_focus or self._value)
self._frame.canvas.print_at(
self._text,
self._x + self._offset + 4,
Expand Down
4 changes: 2 additions & 2 deletions asciimatics/widgets/radiobuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def update(self, frame_no):

# Render the list of radio buttons.
for i, (text, _) in enumerate(self._options):
fg, attr, bg = self._pick_colours("control", self._has_focus and i == self._selection)
fg2, attr2, bg2 = self._pick_colours("field", self._has_focus and i == self._selection)
fg, attr, bg = self._pick_colours("control", i == self._selection)
fg2, attr2, bg2 = self._pick_colours("field", i == self._selection)
check = check_char if i == self._selection else " "
self._frame.canvas.print_at(
f"({check}) ",
Expand Down
5 changes: 3 additions & 2 deletions asciimatics/widgets/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"button": (Screen.COLOUR_WHITE, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"focus_button": (Screen.COLOUR_WHITE, Screen.A_BOLD, Screen.COLOUR_CYAN),
"control": (Screen.COLOUR_YELLOW, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"selected_control": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLUE),
"selected_control": (Screen.COLOUR_YELLOW, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"focus_control": (Screen.COLOUR_YELLOW, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"selected_focus_control": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_CYAN),
"field": (Screen.COLOUR_WHITE, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"selected_field": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLUE),
"selected_field": (Screen.COLOUR_YELLOW, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"focus_field": (Screen.COLOUR_WHITE, Screen.A_NORMAL, Screen.COLOUR_BLUE),
"selected_focus_field": (Screen.COLOUR_WHITE, Screen.A_BOLD, Screen.COLOUR_CYAN),
},
Expand Down Expand Up @@ -71,6 +71,7 @@
"invalid": (Screen.COLOUR_BLACK, Screen.A_NORMAL, Screen.COLOUR_RED),
"label": (Screen.COLOUR_GREEN, Screen.A_BOLD, Screen.COLOUR_BLACK),
"control": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLACK),
"selected_control": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLACK),
"focus_control": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLACK),
"selected_focus_control": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLACK),
"selected_focus_field": (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_BLACK),
Expand Down

0 comments on commit 55b927a

Please sign in to comment.