Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created October 13, 2021 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typemytype/f62bb814e76fe67b384fbcc155d7c72b to your computer and use it in GitHub Desktop.
Save typemytype/f62bb814e76fe67b384fbcc155d7c72b to your computer and use it in GitHub Desktop.
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