bottom-align value bar for settings
s-ol
3 months ago
69 | 69 | class SliderSetting(Setting): |
70 | 70 | name: str |
71 | 71 | max: int |
72 | fmt: str | None | |
73 | ||
72 | 74 | _value: int |
73 | fmt: str | None | |
75 | ||
76 | offset: int | |
77 | width: int | |
74 | 78 | |
75 | 79 | def __init__( |
76 | 80 | self, |
86 | 90 | self.max = max |
87 | 91 | self.fmt = fmt |
88 | 92 | self.width = min(23, max) |
93 | self.offset = 12 if self.width <= 12 else 0 | |
89 | 94 | |
90 | 95 | self.thresh = thresh |
91 | 96 | self.color = color |
97 | 102 | self._value = (self._value + 1) % (self.max + 1) |
98 | 103 | |
99 | 104 | def press_key(self, i): |
100 | if i > self.width: | |
105 | i = i - self.offset | |
106 | if i < 0: | |
101 | 107 | return |
108 | # if i > self.width: | |
109 | # return | |
102 | 110 | |
103 | 111 | self._value = int(self.max * i / self.width) |
104 | 112 | |
105 | 113 | def get_colors(self) -> list[int]: |
106 | colors = [] | |
114 | colors = [0] * self.offset | |
107 | 115 | for i in range(self.width + 1): |
108 | 116 | thresh = int(self.max * i / self.width) |
109 | 117 | active = self.thresh(self.value, thresh) |
183 | 191 | self._value = self.values.index(val) |
184 | 192 | |
185 | 193 | def get_colors(self) -> list[int]: |
186 | colors = [] | |
194 | colors = [0] * self.offset | |
187 | 195 | value = self.value |
188 | 196 | for i in range(self.width + 1): |
189 | 197 | thresh = self.values[int(self.max * i / self.width)] |