Created
October 13, 2021 21:05
-
-
Save typemytype/f62bb814e76fe67b384fbcc155d7c72b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vanilla | |
import merz | |
class Demo: | |
def __init__(self): | |
# setup window | |
self.w = vanilla.Window((400, 400), minSize=(150, 150)) | |
# add a merz view | |
self.w.view = merz.MerzView((0, 0, 0, 0), delegate=self, backgroundColor=(0, 1, 0, 1)) | |
# get container and add some sublayers | |
container = self.w.view.getMerzContainer() | |
container.appendOvalSublayer( | |
size=(50, 50), | |
fillColor=(1, 0, 1, 1), | |
position=("center", "center") | |
) | |
container.appendRectangleSublayer( | |
size=(50, 50), | |
fillColor=(0, 0, 1, 1), | |
position=(10, 10) | |
) | |
self.w.open() | |
# merzview delegate stuff | |
def acceptsFirstResponder(self, view): | |
# respond with True to accepts user events | |
return True | |
def scrollWheel(self, view, event): | |
# get the delta of the scroll | |
delta = event.scrollingDeltaY() | |
if delta < 0: | |
factor = 0.9 | |
else: | |
factor = 1.1 | |
# get the container of the view | |
merzContainer = view.getMerzContainer() | |
# get the scale of the container | |
scale = merzContainer.getContainerScale() | |
# reset with a new scale | |
merzContainer.setContainerScale(scale * factor) | |
Demo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment