Show a dialog to edit an integer setting with UP/DOWN to change value.
(self, key, label, min_val, max_val, step)
| 804 | self._edit_choice_dialog(key, label, setting['choices']) |
| 805 | |
| 806 | def _edit_int_dialog(self, key, label, min_val, max_val, step): |
| 807 | """Show a dialog to edit an integer setting with UP/DOWN to change value.""" |
| 808 | self.dialog_showing = True |
| 809 | try: |
| 810 | current = int(self.shared_data.config.get(key, min_val)) |
| 811 | current = max(min_val, min(max_val, current)) |
| 812 | |
| 813 | # Dialog box: 400w x 148h, centred on 480x222 |
| 814 | DW, DH = 400, 148 |
| 815 | DX = (self.width - DW) // 2 # 40 |
| 816 | DY = (self.height - DH) // 2 # 37 |
| 817 | |
| 818 | def draw(): |
| 819 | # Box |
| 820 | self.pager.fill_rect(DX, DY, DW, DH, self.CARD_BG) |
| 821 | self.pager.rect(DX, DY, DW, DH, self.CYAN) |
| 822 | self.pager.rect(DX + 2, DY + 2, DW - 4, DH - 4, self.DARK_GRAY) |
| 823 | |
| 824 | # Label — 16px (TTF_MEDIUM), readable |
| 825 | lw = self.pager.ttf_width(label[:28], self.font_arial, 16) |
| 826 | self.pager.draw_ttf((self.width - lw) // 2, DY + 10, label[:28], |
| 827 | self.WHITE, self.font_arial, 16) |
| 828 | |
| 829 | # Value — 36px, very prominent |
| 830 | val_str = str(current) |
| 831 | vw = self.pager.ttf_width(val_str, self.font_arial, 36) |
| 832 | self.pager.draw_ttf((self.width - vw) // 2, DY + 38, val_str, |
| 833 | self.CYAN, self.font_arial, 36) |
| 834 | |
| 835 | # Range hint — 13px (TTF_SMALL) |
| 836 | hint = f"{min_val} - {max_val} step {step}" |
| 837 | hw = self.pager.ttf_width(hint, self.font_arial, 13) |
| 838 | self.pager.draw_ttf((self.width - hw) // 2, DY + 94, hint, |
| 839 | self.GRAY, self.font_arial, 13) |
| 840 | |
| 841 | # Button hints — 13px |
| 842 | self.pager.draw_ttf_centered(DY + 118, "UP: increase DOWN: decrease A: save B: cancel", |
| 843 | self.GRAY, self.font_arial, 13) |
| 844 | self.pager.flip() |
| 845 | |
| 846 | draw() |
| 847 | |
| 848 | while True: |
| 849 | button = self.pager.wait_button() |
| 850 | if button & Pager.BTN_UP: |
| 851 | current = min(max_val, current + step) |
| 852 | draw() |
| 853 | elif button & Pager.BTN_DOWN: |
| 854 | current = max(min_val, current - step) |
| 855 | draw() |
| 856 | elif button & Pager.BTN_A: |
| 857 | self._save_setting(key, current) |
| 858 | break |
| 859 | elif button & Pager.BTN_B: |
| 860 | break |
| 861 | except Exception as e: |
| 862 | logger.error(f"Error in int dialog for {key}: {e}") |
| 863 | finally: |
no test coverage detected