def three(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('root', vertical=true), List( ViewTree.pane( SimplePane.cons(StrIdent('one'), geometry=ViewGeometry.cons(max_size=10))), ViewTree.pane( SimplePane.cons(StrIdent('two'), geometry=ViewGeometry.cons(max_size=10))), ViewTree.pane( SimplePane.cons(StrIdent('three'), geometry=ViewGeometry.cons(max_size=10))), )) data = SpecData.cons(layout) @do(TS[SpecData, List[PaneData]]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) panes = yield all_panes().state positions = panes / _.position yield TS.from_maybe(positions.lift_all(0, 1, 2), 'invalid number of panes') s, (p1, p2, p3) = self.run(go(), data) return k(p3 - p2) == (p2 - p1)
def four(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('root'), List( ViewTree.pane( SimplePane.cons('one', geometry=ViewGeometry.cons(min_size=30))), ViewTree.layout( SimpleLayout.cons('main', vertical=false), List( ViewTree.pane(SimplePane.cons('two')), ViewTree.layout( SimpleLayout.cons('sub1'), List( ViewTree.pane(SimplePane.cons('three')), ViewTree.layout( SimpleLayout.cons('sub2', vertical=false), List( ViewTree.pane(SimplePane.cons('four')), ViewTree.pane(SimplePane.cons('five')), )))))), )) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane('one') yield ui_open_simple_pane('two') yield ui_open_simple_pane('three') yield ui_open_simple_pane('four') yield open_simple_pane('five') yield all_panes().state s, panes = self.run(go(), data) return k(panes).must(have_length(5))
def focus(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('main', vertical=true), List( ViewTree.pane(SimplePane.cons('one')), ViewTree.pane(SimplePane.cons('two')), ), ) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield open_simple_pane(StrIdent('two')) yield all_panes().state yield TS.lift(pdata()) (s, r) = self.run(go(), data) return k(r) == List(FData(0, True), FData(1, False))
def one_sub(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('main', vertical=true), List( ViewTree.pane(SimplePane.cons('one')), ViewTree.layout( SimpleLayout.cons('sub', vertical=false), List( ViewTree.pane(SimplePane.cons('two')), ViewTree.pane(SimplePane.cons('three')), )), )) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) yield all_panes().state s, panes = self.run(go(), data) return k(panes).must(have_length(3))
def layout_node(self, node: LayoutNode[A, P]) -> MeasureTree: vertical = node.data.vertical total = self.height if vertical else self.width views = open_views(self.bindings)(node) def recurse(next_node: ViewTree[A, P], size: float) -> MeasureTree: new_width, new_height = (self.width, size) if vertical else (size, self.height) next_measures = Measures(size) return measure_layout(self.bindings)(next_measures, new_width, new_height)(next_node) def measure_views() -> List[MeasureTree]: sizes = measure_layout_views( views / _.data / measure_data(V=self.bindings.bindings['P']), total) return views.zip(sizes).map2(recurse) sub = (measure_views() if views.length > 0 else Nil) return ViewTree.layout(MeasuredView(node.data, self.measures), sub)
def pane_node(self, node: PaneNode[A, P]) -> MeasureTree: return ViewTree.pane(MeasuredView(node.data, self.measures))
def sub_ui_node(self, node: SubUiNode[L, P]) -> Either[str, P]: return ViewTree.pane(MeasuredView(node.data, self.measures))
from chiasma.data.view_tree import ViewTree, map_panes from chiasma.ui.simple import SimpleLayout, SimplePane from amino import List from amino.func import const from amino.lenses.lens import lens from amino.boolean import true three = ViewTree.layout( SimpleLayout.cons('main', vertical=False), List( ViewTree.pane(SimplePane.cons('one')), ViewTree.layout( SimpleLayout.cons('sub', vertical=True), List( ViewTree.pane(SimplePane.cons('two', pin=True)), ViewTree.pane(SimplePane.cons('three')), )), )) two_vertical = ViewTree.layout( SimpleLayout.cons('root', vertical=False), List( ViewTree.layout( SimpleLayout.cons('left', vertical=True), List(ViewTree.pane(SimplePane.cons('one', open=True)), ), ), ViewTree.layout( SimpleLayout.cons('right', vertical=True), List(ViewTree.pane(SimplePane.cons('two')), ), ))) open_all_panes = map_panes(const(True), lens.open.set(true))