Exemplo n.º 1
0
 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])
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 def opacity(self, value):
     self.env.opacity = clamp(float(value), 0.0, 1.0)
     return self
Exemplo n.º 5
0
 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))
Exemplo n.º 6
0
 def _set(self, value):
     clamped = clamp(int(value), self.minimum, self.maximum)
     if self.current.value != clamped:
         self.current.value = clamped