[docs]classUIDraggableMixin(UILayout):""" UIDraggableMixin can be used to make any :class:`UIWidget` draggable. Example, create a draggable Frame, with a background, useful for window like constructs: class DraggablePane(UITexturePane, UIDraggableMixin): ... This does overwrite :class:`UILayout` behaviour which position themselves, like :class:`UIAnchorWidget` """
[docs]defdo_layout(self):# Preserve top left alignment, this overwrites self placing behaviour like from :class:`UIAnchorWidget`rect=self.rectsuper().do_layout()self.rect=self.rect.align_top(rect.top).align_left(rect.left)
[docs]classUIMouseFilterMixin(UIWidget):""" :class:`UIMouseFilterMixin` can be used to catch all mouse events which occur inside this widget. Useful for window like widgets, :class:`UIMouseEvents` should not trigger effects which are under the widget. """
[docs]defon_event(self,event)->Optional[bool]:ifsuper().on_event(event):returnEVENT_HANDLEDifisinstance(event,UIMouseEvent):# Catch all mouse events, that are inside this widget, to act like a windowifself.rect.collide_with_point(*event.pos):returnEVENT_HANDLEDreturnEVENT_UNHANDLED
[docs]classUIWindowLikeMixin(UIMouseFilterMixin,UIDraggableMixin,UIWidget):""" Makes a widget window like: - handles all mouse events that occur within the widgets boundaries - can be dragged """