git.s-ol.nu hw/0x33.board/firmware / 9655ae6
bottom-align value bar for settings s-ol 3 months ago
1 changed file(s) with 12 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
6969 class SliderSetting(Setting):
7070 name: str
7171 max: int
72 fmt: str | None
73
7274 _value: int
73 fmt: str | None
75
76 offset: int
77 width: int
7478
7579 def __init__(
7680 self,
8690 self.max = max
8791 self.fmt = fmt
8892 self.width = min(23, max)
93 self.offset = 12 if self.width <= 12 else 0
8994
9095 self.thresh = thresh
9196 self.color = color
97102 self._value = (self._value + 1) % (self.max + 1)
98103
99104 def press_key(self, i):
100 if i > self.width:
105 i = i - self.offset
106 if i < 0:
101107 return
108 # if i > self.width:
109 # return
102110
103111 self._value = int(self.max * i / self.width)
104112
105113 def get_colors(self) -> list[int]:
106 colors = []
114 colors = [0] * self.offset
107115 for i in range(self.width + 1):
108116 thresh = int(self.max * i / self.width)
109117 active = self.thresh(self.value, thresh)
183191 self._value = self.values.index(val)
184192
185193 def get_colors(self) -> list[int]:
186 colors = []
194 colors = [0] * self.offset
187195 value = self.value
188196 for i in range(self.width + 1):
189197 thresh = self.values[int(self.max * i / self.width)]