Skip to content

Layer

Stacks overlay on top of base. Clicking outside the overlay sends on_dismiss, and backdrop dims the view behind it. With overlay=None it returns base unchanged, so it can always wrap your view. align_x, align_y and offset place the overlay (by default centered at the top, like a command palette).

ui.layer · Category: Overlays · Full reference →

LayerLayer
  • To show palettes, pickers, modals and menus above everything else.
  • For dialogs, Dialog layer already centers them over a dimmed backdrop.
import pyzed as pz
from pyzed import ui
class App(pz.App):
def __init__(self):
self.finder_open = False
def view(self):
overlay = self.finder() if self.finder_open else None
return ui.layer(self.main_view(), overlay,
on_dismiss=lambda: setattr(self, "finder_open", False))
Layer: Top (default)Layer: Top (default)
Top (default)
Code
ui.layer(main_view(), ui.card(ui.label("Overlay"), width=200), on_dismiss=on_close)
Layer: align_y="center"Layer: align_y="center"
align_y="center"
Code
ui.layer(main_view(), ui.card(ui.label("Overlay"), width=200), align_y="center",
on_dismiss=on_close)
Layer: align_x="end", align_y="end"Layer: align_x="end", align_y="end"
align_x="end", align_y="end"
Code
ui.layer(main_view(), ui.card(ui.label("Overlay"), width=200), align_x="end", align_y="end",
offset=16, on_dismiss=on_close)

With overlay=None the layer returns your view unchanged.

Layer: backdrop="#00000088"Layer: backdrop="#00000088"
backdrop="#00000088"
Code
ui.layer(main_view(), ui.card(ui.label("Overlay"), width=200), backdrop="#00000088",
align_y="center", on_dismiss=on_close)
Layer: overlay=NoneLayer: overlay=None
overlay=None
Code
ui.layer(main_view(), None)

Layer has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

Event Handler gets When
on_dismiss () Message or callable sent on close.

Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().

The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.

class App(pz.App):
def __init__(self):
self.finder_open = True
def view(self):
finder = ui.card(ui.muted("Search files…"), width=320)
return ui.layer(main_view(), finder if self.finder_open else None,
on_dismiss=lambda: setattr(self, "finder_open", False)) # click outside
layer(
base,
overlay=None,
*,
on_dismiss=None,
backdrop=None,
align_x='center',
align_y='start',
offset=72,
)

Stacks overlay on top of base. Clicking outside sends on_dismiss. With overlay=None it returns base unchanged.

Property Default Description
base required The UI underneath.
overlay None What floats on top (modal, palette, menu).
backdrop None Color of the backdrop that dims the UI.
align_x "center" Horizontal alignment: "start"/"left", "center", "end"/"right".
align_y "start" Vertical alignment: "start"/"top", "center", "end"/"bottom".
offset 72 Distance from the top when align_y is "start".

Events: on_dismiss (events).

Full reference →