# Copyright 2023 (c) Anna Schumaker. """Our adaptable layout that can rearrange widgets as the window is resized.""" from gi.repository import GObject from gi.repository import Gtk from gi.repository import Adw class Layout(Adw.Bin): """A widget that can rearrange based on window dimensions.""" show_sidebar = GObject.Property(type=bool, default=False) wide_view = GObject.Property(type=bool, default=False) def __init__(self, *, content: Gtk.Widget = None, sidebar: Gtk.Widget = None): """Initialize our Layout widget.""" super().__init__() self._split_view = Adw.OverlaySplitView(content=content, sidebar=sidebar, collapsed=not self.wide_view) self.props.child = self._split_view self.bind_property("show-sidebar", self._split_view, "show-sidebar", GObject.BindingFlags.BIDIRECTIONAL) self.bind_property("wide-view", self._split_view, "collapsed", GObject.BindingFlags.INVERT_BOOLEAN) @GObject.Property(type=Gtk.Widget) def content(self) -> Gtk.Widget: """Get the content widget for the Layout.""" return self._split_view.props.content @content.setter def content(self, widget: Gtk.Widget) -> None: self._split_view.props.content = widget @GObject.Property(type=Gtk.Widget) def sidebar(self) -> Gtk.Widget: """Get the sidebar widget for the Layout.""" return self._split_view.props.sidebar @sidebar.setter def sidebar(self, widget: Gtk.Widget) -> None: self._split_view.props.sidebar = widget