def layout_constraints(self): """ The constraints generation for a HGroup. This method supplies horizontal group constraints for the children of the container in addition to any user-supplied constraints. """ widgets = self.visible_widgets() items = [self.leading_spacer] + widgets + [self.trailing_spacer] cns = self.constraints[:] cns.append(hbox(*items, spacing=self.spacing)) cns.append(align('v_center', *widgets)) if self.align_widths: cns.append(align('width', *widgets)) return cns
def layout_constraints(self): """ The constraints generation for a HGroup. This method supplies horizontal group constraints for the children of the container in addition to any user-supplied constraints. This method cannot be overridden from Enaml syntax. """ widgets = self.visible_widgets() items = [self.leading_spacer] + widgets + [self.trailing_spacer] cns = self.constraints[:] cns.append(hbox(*items, spacing=self.spacing)) cns.append(align('v_center', *widgets)) if self.align_widths: cns.append(align('width', *widgets)) return cns
def layout_constraints(self): """ The constraints generation for a VGroup. This method supplies left-aligned vertical group constraints for the children of the container in addition to any user-supplied constraints. """ widgets = self.visible_widgets() items = [self.leading_spacer] + widgets + [self.trailing_spacer] cns = self.constraints[:] cns.append(vbox(*items, spacing=self.spacing)) cns.append(align('left', *widgets)) return cns
def layout_constraints(self): """ The constraints generation for a VGroup. This method supplies left-aligned vertical group constraints for the children of the container in addition to any user-supplied constraints. This method cannot be overridden from Enaml syntax. """ widgets = self.visible_widgets() items = [self.leading_spacer] + widgets + [self.trailing_spacer] cns = self.constraints[:] cns.append(vbox(*items, spacing=self.spacing)) cns.append(align('left', *widgets)) return cns
def _component_constraints(self): """ Supplies the constraints which layout the children in a two column form. """ # FIXME: do something sensible when children are not visible. children = list(self.widgets) labels = children[::2] widgets = children[1::2] n_labels = len(labels) n_widgets = len(widgets) if n_labels != n_widgets: if n_labels > n_widgets: odd_child = labels.pop() else: odd_child = widgets.pop() else: odd_child = None layout_strength = self.layout_strength constraints = [] # Align the left side of each widget with the midline constraint # variable of the form. midline = self.midline for widget in widgets: cn = (widget.left == midline) | layout_strength constraints.append(cn) # Arrange each label/widget pair horizontally in the form # XXX this is a highly inefficient way to generate these # constraints. It starts to be noticeably slow when the # form has around 20 rows. This can be done better. labels_widgets = zip(labels, widgets) vbox_args = [hbox(label, widget) for label, widget in labels_widgets] if odd_child is not None: vbox_args.append(odd_child) constraints.append(vbox(*vbox_args)) for label, widget in labels_widgets: # FIXME: baselines would be much better. constraints.append( align('v_center', label, widget) | layout_strength) return constraints
def _component_constraints(self): """ Supplies the constraints which layout the children in a two column form. """ # FIXME: do something sensible when children are not visible. children = list(self.widgets) labels = children[::2] widgets = children[1::2] n_labels = len(labels) n_widgets = len(widgets) if n_labels != n_widgets: if n_labels > n_widgets: odd_child = labels.pop() else: odd_child = widgets.pop() else: odd_child = None layout_strength = self.layout_strength constraints = [] # Align the left side of each widget with the midline constraint # variable of the form. midline = self.midline for widget in widgets: cn = (widget.left == midline) | layout_strength constraints.append(cn) # Arrange each label/widget pair horizontally in the form # XXX this is a highly inefficient way to generate these # constraints. It starts to be noticeably slow when the # form has around 20 rows. This can be done better. labels_widgets = zip(labels, widgets) vbox_args = [hbox(label, widget) for label, widget in labels_widgets] if odd_child is not None: vbox_args.append(odd_child) constraints.append(vbox(*vbox_args)) for label, widget in labels_widgets: # FIXME: baselines would be much better. constraints.append(align('v_center', label, widget) | layout_strength) return constraints
def layout_constraints(self): """ Get the layout constraints for a Form. A Form supplies default constraints which will arrange the children in a two column layout. User defined 'constraints' will be added on top of the generated form constraints. This method cannot be overridden from Enaml syntax. """ children = self.visible_widgets() labels = children[::2] widgets = children[1::2] n_labels = len(labels) n_widgets = len(widgets) if n_labels != n_widgets: if n_labels > n_widgets: odd_child = labels.pop() else: odd_child = widgets.pop() else: odd_child = None # Boundary flex spacer b_flx = spacer(0).flex() # Inter-column flex spacer c_flx = spacer(max(0, self.column_spacing)).flex() # Inter-row flex spacer r_flx = spacer(max(0, self.row_spacing)).flex() # Generate the row constraints and make the column stacks midline = self.midline top = self.contents_top left = self.contents_left right = self.contents_right constraints = self.constraints[:] column1 = [top, b_flx] column2 = [top, b_flx] push = constraints.append push_col1 = column1.append push_col2 = column2.append for label, widget in zip(labels, widgets): push((widget.left == midline) | 'strong') push(align('v_center', label, widget) | 'strong') push(horizontal(left, b_flx, label, c_flx, widget, b_flx, right)) push_col1(label) push_col1(r_flx) push_col2(widget) push_col2(r_flx) # Handle the odd child and create the column constraints if odd_child is not None: push_col1(odd_child) push_col2(odd_child) push(horizontal(left, b_flx, odd_child, b_flx, right)) else: column1.pop() column2.pop() bottom = self.contents_bottom push_col1(b_flx) push_col1(bottom) push_col2(b_flx) push_col2(bottom) push(vertical(*column1)) push(vertical(*column2)) return constraints
def layout_constraints(self): """ Get the layout constraints for a Form. A Form supplies default constraints which will arrange the children in a two column layout. User defined 'constraints' will be added on top of the generated form constraints. """ # FIXME: do something sensible when children are not visible. children = self.widgets() labels = children[::2] widgets = children[1::2] n_labels = len(labels) n_widgets = len(widgets) if n_labels != n_widgets: if n_labels > n_widgets: odd_child = labels.pop() else: odd_child = widgets.pop() else: odd_child = None # Boundary flex spacer b_flx = spacer(0).flex() # Inter-widget flex spacer w_flx = spacer(10).flex() # Generate the row constraints and make the column stacks midline = self.midline top = self.contents_top left = self.contents_left right = self.contents_right constraints = self.constraints[:] column1 = [top, b_flx] column2 = [top, b_flx] push = constraints.append push_col1 = column1.append push_col2 = column2.append for label, widget in zip(labels, widgets): push((widget.left == midline) | 'strong') push(align('v_center', label, widget) | 'strong') push(horizontal(left, b_flx, label, w_flx, widget, b_flx, right)) push_col1(label) push_col1(w_flx) push_col2(widget) push_col2(w_flx) # Handle the odd child and create the column constraints if odd_child is not None: push_col1(odd_child) push_col2(odd_child) push(horizontal(left, b_flx, odd_child, b_flx, right)) else: column1.pop() column2.pop() bottom = self.contents_bottom push_col1(b_flx) push_col1(bottom) push_col2(b_flx) push_col2(bottom) push(vertical(*column1)) push(vertical(*column2)) return constraints