Hey everyone,
awkward title of the topic, I know. I struggled with fitting nodes in resizing sceneViews. I have a sceneView, which is resized via animation by pushing a button. The question was how to stick the scene at the top of the view. I have found a solution, but because of the fact I am new to that stuff I‘d like to post the code here with the silent question if there is a better way or if it is a common way.
```
from scene import *
import ui
class MyScene(Scene):
def init(self):
Scene.init(self)
self.background_color= '#eee'
self.frm = ShapeNode(parent=self, fill_color='red', stroke_color='clear')
def setup(self):
self.viewSizeHasChanged()
def viewSizeHasChanged(self):
self.frm.position = (150,self.view.height/2-(500-self.view.height)/2)
self.frm.path = ui.Path.rect(0,0,250,450)
class GUI(ui.View):
def init(self):
self.background_color = '#ddd'
self.scales = (100, 500)
self.state = True
self.separator_H = 10
self.mainView = ui.View(frame=(50,50,300,500), background_color='#fff')
self.add_subview(self.mainView)
self.sn = SceneView()
self.sn.frame = self.mainView.bounds
self.mainView.add_subview(self.sn)
self.sn.scene = MyScene()
self.btn_Do = ui.Button(name='Do', title='Do', background_color= '#ddd', corner_radius = 12, action = self.btn_tapped)
self.btn_Do.frame = (175, 275, 50, 50)
self.add_subview(self.btn_Do)
def btn_tapped(self, sender):
if sender.name == 'Do':
self.state = (self.state+1)%2
self.sn.scene.viewSizeHasChanged()
self.animate(self.scales[self.state])
def animate(self, H):
def animation(): self.mainView.frame = (50,(600-H)/2,300,H)
ui.animate(animation, duration=1.0)
if name == 'main':
GUI().present('fullscreen')
```
Thx for every hint guys
rownn