Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioButtons does not consider the right pallet when item is selected without focus #387

Open
jbfro opened this issue May 4, 2024 · 2 comments

Comments

@jbfro
Copy link

jbfro commented May 4, 2024

Describe the bug
When a radio button is selected but not focused the wrong pallet color is chosen.

To Reproduce

  1. Override the selected_control and selected_field pallet definition with Screen.COLOUR_YELLOW color for better observation.
  2. When the radiobuttons widget is focused and selected, the color is okay.
  3. When the radiobuttons widget losses the focus, then the selected item does not get colored in accordance with selected_control and selected_field.

wrong

Expected behavior

  1. Override the selected_control and selected_field pallet definition with Screen.COLOUR_YELLOW color for better observation.
  2. When the radiobuttons widget is focused and selected, the color is okay.
  3. When the radiobuttons widget losses the focus, then the selected item gets colored in accordance with selected_control and selected_field.

okay

Potential fix to this issue

The bellow patch is based on the master branch.

From c89160b2cb8c2503a745da6f937021bf14f121cd Mon Sep 17 00:00:00 2001
From: Jean-Baptiste FROMENTEAU <jb.fromenteau@gmail.com>
Date: Sat, 4 May 2024 17:11:53 +0200
Subject: [PATCH] Fix radiobuttons pallet selection when item is selected

Signed-off-by: Jean-Baptiste FROMENTEAU <jb.fromenteau@gmail.com>
---
 asciimatics/widgets/radiobuttons.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/asciimatics/widgets/radiobuttons.py b/asciimatics/widgets/radiobuttons.py
index 999e8bf..9d6e6e3 100644
--- a/asciimatics/widgets/radiobuttons.py
+++ b/asciimatics/widgets/radiobuttons.py
@@ -37,8 +37,8 @@ class RadioButtons(Widget):
 
         # 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}) ",
-- 
2.25.1
@jbfro jbfro changed the title Radiobutton does not consider the right pallet when item is selected RadioButtons does not consider the right pallet when item is selected May 4, 2024
@jbfro jbfro changed the title RadioButtons does not consider the right pallet when item is selected RadioButtons does not consider the right pallet when item is selected without focus May 4, 2024
@peterbrittain
Copy link
Owner

Good spot! I need to think about how this should affect other widgets too.

@jbfro
Copy link
Author

jbfro commented May 4, 2024

As per my investigations it only affects the RadioButtons widget. Other widgets call the _pick_colours function with the proper test i == current_entry and it works fine since the focus state is checked by _pick_palette_key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants