def layout(self): content = self.content if not content: return spacing = .25 height = 1 + spacing if isinstance(content, dict): content = content.values() for c in content: # print('........', c) if isinstance(c, Space): height += c.height if isinstance(c, Entity): c.world_parent = self c.position = (0, -height, 0) if isinstance(c, InputField): if self._prev_input_field: self._prev_input_field.next_field = c self._prev_input_field = c if isinstance(c, Text): c.origin = (-.5, .5) c.x = -.48 height += len(c.lines) elif isinstance(c, Button): c.world_parent = self c.scale = (.9, 1) if hasattr(c, 'height'): c.scale_y = height c.model = Quad(aspect=c.world_scale_x/c.world_scale_y) height += c.scale_y # c.y -= c.scale_y/2 elif isinstance(c, Slider): c.world_parent = self c.x = -.5 * .9 c.scale = (.9*2, 20) # print('-------------', c.scale_y * c.height) height += 1 elif hasattr(c, 'scale_y'): height += c.scale_y if hasattr(c, 'text_entity') and c.text_entity is not None: c.text_entity.world_scale = (1,1,1) height += spacing self.panel.scale_y = height self.panel.model = Quad(aspect=self.panel.world_scale_x/self.panel.world_scale_y, radius=.025) self.panel.origin = (0, .5)
def create_background(self, padding=size*2, radius=size, color=ursina.color.black66): from ursina import Quad, destroy if self._background: destroy(self._background) self._background = Entity(parent=self, z=.01) if isinstance(padding, (int, float, complex)): padding = (padding, padding) w, h = self.width + padding[0], self.height + padding[1] self._background.x -= self.origin_x * self.width self._background.y -= self.origin_y * self.height self._background.model = Quad(radius=radius, scale=(w/self.scale_x, h/self.scale_y)) self._background.color = color