def scroll(self, z): if self.isSubMenuNeedScroll(): self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z, len(self.children)) sw, sh = self.subMenuSize dw, dh = self.window.size h = 0 idx = 0 for c in self.children[: self.subMenuOffsetIdx]: h += c.height if sh - h < dh: h = sh - dh self.subMenuOffsetIdx = idx break idx += 1 rh = 0 # remain height for c in self.children[self.subMenuOffsetIdx :]: rh += c.height c.dirty = True if rh > dh: break self.subMenuOffset.Reset(0.3, -h) self.dirty = True return True return hasattr(self, "subMenuExpand") and self.subMenuExpand
def scroll(self, z): if self.fullSize > self.height: self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z, len(self.children)) sw, sh = self.width, self.fullSize dw, dh = self.window.size h = 0 idx = 0 for c in self.children[: self.subMenuOffsetIdx]: h += c.height if sh - h < dh: h = sh - dh self.subMenuOffsetIdx = idx break idx += 1 rh = 0 # remain height for c in self.children[self.subMenuOffsetIdx :]: rh += c.height c.dirty = True if rh > dh: break self.onScroll(float(h) / self.fullSize) self.dirty = True return True return True
def __getSubMenuPos(self): mw, mh = self.subMenuSize # calc the expect position if self.sysMenuItem: pos = 0, self.height else: # default sub menu is on the right side pm = self.popupMenu pos = self.width - (pm.subMenuIndent if pm else 0), -(mh - self.height) / 2 # return (pm.subMenuIndent if pm else 0) - self.subMenuSize[0], 0 # fix position to prevent outside the window dw, dh = self.window.size l, t = self.local2global(*pos) if l + mw > dw: # display sub menu on left side _l, _t = (pm.subMenuIndent if pm else 0) - mw, pos[1] l, t = self.local2global(_l, _t) l = max(0, l) if mh > dh: t = 0 else: t = clamp(0, t, dh - mh) pos = self.global2local(l, t) return pos
def __getSubMenuPos(self): mw, mh = self.subMenuSize # calc the expect position if self.sysMenuItem: pos = 0, self.height else: # default sub menu is on the right side pm = self.popupMenu pos = self.width - (pm.subMenuIndent if pm else 0), -(mh - self.height) / 2 #return (pm.subMenuIndent if pm else 0) - self.subMenuSize[0], 0 # fix position to prevent outside the window dw, dh = self.window.size l, t = self.local2global(*pos) if l + mw > dw: # display sub menu on left side _l, _t = (pm.subMenuIndent if pm else 0) - mw, pos[1] l, t = self.local2global(_l, _t) l = max(0, l) if mh > dh: t = 0 else: t = clamp(0, t, dh - mh) pos = self.global2local(l, t) return pos
def scroll(self, z): if self.fullSize > self.height: self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z, len(self.children)) sw, sh = self.width, self.fullSize dw, dh = self.window.size h = 0 idx = 0 for c in self.children[:self.subMenuOffsetIdx]: h += c.height if sh - h < dh: h = sh - dh self.subMenuOffsetIdx = idx break idx += 1 rh = 0 # remain height for c in self.children[self.subMenuOffsetIdx:]: rh += c.height c.dirty = True if rh > dh: break self.onScroll(float(h) / self.fullSize) self.dirty = True return True return True
def scroll(self, z): if self.isSubMenuNeedScroll(): self.subMenuOffsetIdx = clamp(0, self.subMenuOffsetIdx + z, len(self.children)) sw, sh = self.subMenuSize dw, dh = self.window.size h = 0 idx = 0 for c in self.children[:self.subMenuOffsetIdx]: h += c.height if sh - h < dh: h = sh - dh self.subMenuOffsetIdx = idx break idx += 1 rh = 0 # remain height for c in self.children[self.subMenuOffsetIdx:]: rh += c.height c.dirty = True if rh > dh: break self.subMenuOffset.Reset(0.3, -h) self.dirty = True return True return hasattr(self, 'subMenuExpand') and self.subMenuExpand
def moveToFocus(self, anim=True): ''' move focus item to center ''' #prevent invalid offset when list item is less than view old_o1 = -self.o1.QueryValue() o1 = 0 if self.cellSize * len(self._items) <= self.viewSize: o1 = 0 if anim: self.o1.Reset(self.animTime, 0) else: self.o1.Assign(0) else: o1 = (self.cellSize + self.cellMargin) * self.focusIdx - ( self.viewSize - self.cellSize - self.cellMargin) / 2 o1 = clamp(0, o1, self._full - self.viewSize) if anim: self.o1.Reset(self.animTime, -o1) else: self.o1.Assign(-o1) #self.o1 = -o1 self.__resetDisplayRange(old_o1, o1) if self._full: self.invoke('Fix Scroll', -self.o1 / self._full)
def onSlideMove(self, x, y): self.thumbStart = clamp(self.__start, self.__capPos + (y if self.vertical else x), self.__end) self._thumbStartAnim.ForceAssign(int(self.thumbStart)) if self.snap == 0: self.__updateValue()
def __onScroll(self, x, y): if self.vertical: offset = float(y) / self.height else: offset = float(x) / self.width self.__offset = clamp(0, self.__capOffset + offset, self.maxOffset) self.__onChangeOffset() self.__animScroll(self.thumbStart)
def onKey(self, key): if self.vertical and (key == 'UP' or key == 'DOWN') or not self.vertical and (key == 'LEFT' or key == 'RIGHT'): interval = float(self.valueRange[1] - self.valueRange[0]) / 10 if key == 'UP' or key == 'LEFT': interval = -interval self.value = clamp(self.valueRange[0], self.value + interval, self.valueRange[1]) return True return super(Slider, self).onKey(key)
def __onMouseWheel(self, delta): old_o1 = -self.o1.QueryValue() #o1 = -self.o1 new_o1 = old_o1 - delta * (self.cellSize + self.cellMargin) new_o1 = clamp(0, new_o1, max(0, self._full - self.viewSize)) self.o1.Reset(self.animTime, -new_o1) self.__resetDisplayRange(old_o1, new_o1) if self._full: self.invoke('Fix Scroll', -self.o1 / self._full)
def onSlideTo(self, x, y, flag): self.thumbStart = clamp(self.__start, (y - self.thumb.height / 2) if self.vertical else (x - self.thumb.width / 2), self.__end) if self.snap > 0: self.__updateValue() self.__updateThumbPos() else: self._thumbStartAnim.ForceAssign(int(self.thumbStart)) self.__updateValue() self.invoke('Slide To', self.__value)
def __onMouseWheel(self, delta): old_o1 = -self.o1.QueryValue() #o1 = -self.o1 new_o1 = old_o1 - delta * (self.cellSize + self.cellMargin) new_o1 = clamp( 0, new_o1, max(0, self._full - self.viewSize) ) self.o1.Reset( self.animTime, -new_o1 ) self.__resetDisplayRange(old_o1, new_o1) if self._full: self.invoke('Fix Scroll', -self.o1 / self._full)
def onSlideTo(self, x, y, flag): self.thumbStart = clamp( self.__start, (y - self.thumb.height / 2) if self.vertical else (x - self.thumb.width / 2), self.__end) if self.snap > 0: self.__updateValue() self.__updateThumbPos() else: self._thumbStartAnim.ForceAssign(int(self.thumbStart)) self.__updateValue() self.invoke('Slide To', self.__value)
def onKey(self, key): if self.vertical and (key == 'UP' or key == 'DOWN') or not self.vertical and ( key == 'LEFT' or key == 'RIGHT'): interval = float(self.valueRange[1] - self.valueRange[0]) / 10 if key == 'UP' or key == 'LEFT': interval = -interval self.value = clamp(self.valueRange[0], self.value + interval, self.valueRange[1]) return True return super(Slider, self).onKey(key)
def onSize(self): self.onCellSize() # full size (self._full) and view size (self.width) self._full = (self.cellSize + self.cellMargin) * len(self._items) + self.cellMargin # old_o1 = -self.o1.QueryValue() if self._full > self.viewSize: new_o1 = clamp( 0, old_o1, max(self._full - self.viewSize, self.viewSize) ) else: new_o1 = 0 self.o1.Reset( self.animTime, -new_o1 ) self.__resetDisplayRange(old_o1, new_o1) if self._full: self.invoke('Fix Scroll', -self.o1 / self._full)
def onSize(self): self.onCellSize() # full size (self._full) and view size (self.width) self._full = (self.cellSize + self.cellMargin) * len( self._items) + self.cellMargin # old_o1 = -self.o1.QueryValue() if self._full > self.viewSize: new_o1 = clamp(0, old_o1, max(self._full - self.viewSize, self.viewSize)) else: new_o1 = 0 self.o1.Reset(self.animTime, -new_o1) self.__resetDisplayRange(old_o1, new_o1) if self._full: self.invoke('Fix Scroll', -self.o1 / self._full)
def moveToFocus(self, anim = True): ''' move focus item to center ''' #prevent invalid offset when list item is less than view old_o1 = -self.o1.QueryValue() o1 = 0 if self.cellSize * len(self._items) <= self.viewSize: o1 = 0 if anim: self.o1.Reset( self.animTime, 0 ) else: self.o1.Assign( 0 ) else: o1 = (self.cellSize + self.cellMargin) * self.focusIdx - (self.viewSize-self.cellSize-self.cellMargin) / 2 o1 = clamp(0, o1, self._full - self.viewSize) if anim: self.o1.Reset( self.animTime, -o1 ) else: self.o1.Assign( -o1 ) #self.o1 = -o1 self.__resetDisplayRange(old_o1, o1) if self._full: self.invoke('Fix Scroll', -self.o1 / self._full)
def __getThumbSize(self): if self.vertical: size = self.height else: size = self.width return clamp(self.thumbMinSize, self.pageSize * size, size)
def fixScroll(self, value): self.__offset = clamp(0, value, self.maxOffset) self.__animScroll(self.thumbStart)
def onScroll(self, offset): view = self.height if self.orientation == 'Vertical' else self.width full = self.fullSize if full > view: offset = clamp(0, offset, float(full - view) / full) self.scrollOffset.Reset(0.3, full * offset)
def __fixScroll(self): offset = clamp(0, self.__offset, self.maxOffset) if offset != self.__offset: self.__offset = offset self.__onChangeOffset() self.__animScroll(self.thumbStart)
def onSizeMove(self, x, y): self.width = clamp(self.minSize[0], self.__capWidth + x, self.parent.width) self.height = clamp(self.minSize[1], self.__capHeight + y, self.parent.height)
def onPageDown(self): self.__offset = clamp(0, self.__offset + self.pageSize, self.maxOffset) self.__onChangeOffset() self.__animScroll(self.thumbStart)
def relayout(self, *argv): super(PopupMenu, self).relayout(*argv) window = self.window if window: self.xy = clamp(0, self.left, window.width - self.width), clamp( 0, self.top, window.height - self.height)
def relayout(self, *argv): super(PopupMenu, self).relayout(*argv) window = self.window if window: self.xy = clamp(0, self.left, window.width - self.width), clamp(0, self.top, window.height - self.height)
def setScroll(self, value): self.__offset = clamp(0, value, self.maxOffset) self.__onChangeOffset() self.__animScroll(self.thumbStart)
def __focus(self, idx): self.focusIdx = clamp(0, idx, len(self._items)-1 ) self.moveToFocus()
def __focus(self, idx): self.focusIdx = clamp(0, idx, len(self._items) - 1) self.moveToFocus()