def set_position(self, axis, pos=None): delta = max(0, self.scroll_size[axis] - self.frame.size[axis]) if pos is None: pos = self._position[axis] elif isinstance(pos, float): pos = int(delta * pos) self._position = axis.point(clamp(pos, 0, delta), self._position[axis.cross])
def constrain(self, available, value=None, clamped=True): final = list(value or available) for a in Axis: v = self.size[a] if v: final[a] = v if isinstance(v, int) else int(v * available[a]) if clamped: final[a] = clamp(final[a], 0, available[a]) return Size(*final)
def load(self, class_name): for key, value in self.theme.env(class_name.lower()).items(): if key in ("padding", "border"): value = Insets(*value).scaled(self.scale) elif key in ("color", "background", "border_color", "text_shadow"): value = sdl2.SDL_Color(*value) elif key == "priority": value = Priority[value.upper()] elif key == "position": value = Position[value.upper()] elif key == "alignment": value = Alignment[value.upper()] elif key == "spacing": value = self.scaled(value) elif key == "size": value = Size(self.scaled(value[0]), self.scaled(value[1])) elif key == "opacity": value = clamp(float(value), 0.0, 1.0) setattr(self, key, value)
def opacity(self, value): self.env.opacity = clamp(float(value), 0.0, 1.0) return self
async def mousemotion(self, pt): inner = self.frame - self.env.padding - self.env.border pos = pt.x - inner.left pct = clamp(pos / inner.width, 0.0, 1.0) self._set(self.minimum + (pct * self.span))
def _set(self, value): clamped = clamp(int(value), self.minimum, self.maximum) if self.current.value != clamped: self.current.value = clamped