diff --git a/src/qtile_bonsai/core/tree.py b/src/qtile_bonsai/core/tree.py index 26f468a..c68dd88 100644 --- a/src/qtile_bonsai/core/tree.py +++ b/src/qtile_bonsai/core/tree.py @@ -14,6 +14,7 @@ from qtile_bonsai.core.geometry import ( Axis, AxisParam, + Box, Direction, DirectionParam, PerimieterParams, @@ -110,6 +111,15 @@ def set_config(self, key: str, value: Any, *, level: int | None = None): self._config[level][key] = value + def validate_config(self): + """Validate config across config keys. + + Raises: + `ValueError`: if there are any validation errors. + """ + for level in self._config: + self._validate_tab_bar_config(level) + def get_config( self, key: str, @@ -1136,6 +1146,29 @@ def _notify_subscribers(self, event: TreeEvent, nodes: list[Node]): for callback in self._event_subscribers[event].values(): callback(nodes) + def _validate_tab_bar_config(self, level: int): + bar_height = self.get_config( + "tab_bar.height", level=level, fall_back_to_default=True + ) + bar_margin = self.get_config( + "tab_bar.margin", level=level, fall_back_to_default=True + ) + bar_border_size = self.get_config( + "tab_bar.border_size", level=level, fall_back_to_default=True + ) + bar_padding = self.get_config( + "tab_bar.padding", level=level, fall_back_to_default=True + ) + try: + Box( + Rect(0, 0, self.width, bar_height), + margin=bar_margin, + border=bar_border_size, + padding=bar_padding, + ).validate() + except ValueError as err: + raise ValueError(f"Error in tab_bar config. {err}") from err + def tree_matches_repr(tree: Tree, test_str: str) -> bool: """Tests if the provided `Tree` instance has a str representation that matches the diff --git a/src/qtile_bonsai/layout.py b/src/qtile_bonsai/layout.py index 1a8d68b..d208729 100644 --- a/src/qtile_bonsai/layout.py +++ b/src/qtile_bonsai/layout.py @@ -793,6 +793,7 @@ def _reset(self): # We initialize the tree with arbitrary dimensions. These get reset soon as this # layout's group is assigned to a screen. self._tree = BonsaiTree(100, 100, config=config) + self._tree.validate_config() self._tree.subscribe( TreeEvent.node_added, lambda nodes: self._handle_added_tree_nodes(nodes) @@ -836,8 +837,6 @@ def parse_multi_level_config(self) -> BonsaiTree.MultiLevelConfig: multi_level_config[level][key] = value - validation.validate_across_options(multi_level_config) - return multi_level_config def _handle_added_tree_nodes(self, nodes: list[BonsaiNodeMixin]): diff --git a/src/qtile_bonsai/validation.py b/src/qtile_bonsai/validation.py index 5579a89..366ff89 100644 --- a/src/qtile_bonsai/validation.py +++ b/src/qtile_bonsai/validation.py @@ -7,11 +7,6 @@ from qtile_bonsai.tree import BonsaiTree -def validate_across_options(multi_level_config: BonsaiTree.MultiLevelConfig): - for level, config in multi_level_config.items(): - pass - - def validate_border_size(key: str, value: Any) -> tuple[bool, str | None]: if not isinstance(value, int): err_msg = (