1414
1515from textual import events
1616from textual .app import ComposeResult
17+ from textual .content import Content
1718from textual .containers import Container , Horizontal , Vertical , VerticalScroll
1819from textual .screen import ModalScreen
1920from textual .widgets import Button , Checkbox , Input , Label , RadioButton , RadioSet
@@ -170,9 +171,16 @@ class CheckListModal(ModalScreen[list[str] | None]):
170171 }
171172
172173 .btns {
173- height: 3; /* give buttons row a fixed height */
174- padding-top: 1;
175- content-align: right middle;
174+ height: auto;
175+ width: 100%;
176+ margin-top: 1;
177+ padding: 0;
178+ content-align: center middle;
179+ align-horizontal: center;
180+ }
181+
182+ .btns Button {
183+ padding: 0 3;
176184 }
177185 """
178186
@@ -209,6 +217,18 @@ def on_mount(self) -> None:
209217
210218
211219class RadioListModal (ModalScreen [str | None ]):
220+ class SquareRadioButton (RadioButton ):
221+ # BUTTON_INNER = '●'
222+ @property
223+ def _button (self ) -> Content :
224+ button_style = self .get_visual_style ("toggle--button" )
225+ symbol = "☒" if self .value else "☐"
226+ return Content .assemble (
227+ (" " , button_style ),
228+ (symbol , button_style ),
229+ (" " , button_style ),
230+ )
231+
212232 CSS = """
213233 RadioListModal {
214234 align: center middle;
@@ -218,7 +238,6 @@ class RadioListModal(ModalScreen[str | None]):
218238 width: 60%;
219239 max-width: 90%;
220240 height: 40%;
221- border: round $accent;
222241 padding: 1 2;
223242 background: $panel;
224243 }
@@ -233,9 +252,16 @@ class RadioListModal(ModalScreen[str | None]):
233252 }
234253
235254 .btns {
236- height: 3;
237- padding-top: 1;
238- content-align: right middle;
255+ height: auto;
256+ width: 100%;
257+ margin-top: 1;
258+ padding: 0;
259+ content-align: center middle;
260+ align-horizontal: center;
261+ }
262+
263+ .btns Button {
264+ padding: 0 1;
239265 }
240266 """
241267
@@ -255,15 +281,15 @@ def compose(self) -> ComposeResult:
255281 with VerticalScroll (classes = "radio-list" ):
256282 with RadioSet (id = "radio-set" ):
257283 for i , line in enumerate (self .lines ):
258- yield RadioButton (line , id = f"rb{ i } " , value = (i == self .default_index ))
284+ yield self . SquareRadioButton (line , id = f"rb{ i } " , value = (i == self .default_index ))
259285
260286 # Buttons
261287 with Horizontal (classes = "btns" ):
262288 yield Button ("Cancel" , variant = "default" , id = "cancel" )
263289 yield Button ("Submit" , variant = "primary" , id = "submit" )
264290
265291 def on_mount (self ) -> None :
266- first_rb = self .query_one (RadioButton )
292+ first_rb = self .query_one (self . SquareRadioButton )
267293 self .set_focus (first_rb )
268294
269295 def on_button_pressed (self , event : Button .Pressed ) -> None :
0 commit comments