nicegui icon indicating copy to clipboard operation
nicegui copied to clipboard

Layout builder

Open rodja opened this issue 2 years ago • 0 comments

One idea from #117 was to create a subset of layout commands which are easier to understand and discover than the classic css/quasar/tailwind techniques. The "Layout Builder" is one such attempt.

Features

This branch currently sketches out the following features (meaning it's not a full implementation but rather a proof of concept):

  • auto completion + documentation for simple to understand layout and styling aspects
  • using the builder pattern in combination with string literals for auto completion
  • logical grouping of layout aspects (e.g. align.center and align.children are fundamentally different in css but presented together)
  • the Layout of an existing element can be modify by accessing its layout property
  • Layouts can also be created independently because they are self contained classes
  • element.props and element.classes take precedence over element.layout definitions to allow customizations
  • Layouts can be used as contexts to create generic groups, rows, columns: with ui.layout('horizontal')
  • specialized Layouts provide additional styling (e.g. ButtonLayout to configure shape etc.)
  • a Layout can be applied to (multiple) other Layouts via add
  • a Layout can be duplicated by calling .copy()
  • invalid layout aspects can raise error reports (e.g. margin.top.auto() is not possible with css)
  • binding to Layout values like opacity

A demo of this features is implemented in the layout_demo.py.

ToDos / Ideas

  • Layout.row() and Layout.column() should use a GroupLayout which provides arrangement of children (e.g. gap, align.children, ...)
  • Some mechanism to allow Grid and Masonry Layouts

Questions

  • How does the name "Layout" affect header/footer/drawer and tabs? Should we rename the latter? Or incorporate it?
  • How to provide smart colors which change automatically for dark mode?
  • Can we return the specialized Layout type in base class methods? (e.g. ui.button().layout.align.center() should return ButtonLayout)
  • Should we use tailwind classes for color to support dark: selector or use Quasar colors to support Theming with ui.colors?

rodja avatar Feb 11 '23 14:02 rodja