Skip to content

Commit

Permalink
feat(home_widget): add distance parameter for menu positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
amnweb committed Dec 22, 2024
1 parent 27da0e7 commit b169188
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/core/validation/widgets/yasb/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'blur': False,
'alignment': 'left',
'direction': 'down',
'distance': 6,
'menu_labels': {'shutdown': 'Shutdown', 'restart': 'Restart', 'logout': 'Logout', 'lock': 'Lock', 'sleep': 'Sleep', 'system': 'System Settings', 'about': 'About This PC', 'task_manager': 'Task Manager'},
'callbacks': {
'on_left': 'toggle_menu'
Expand Down Expand Up @@ -58,6 +59,11 @@
'default': DEFAULTS['direction'],
'required': False
},
'distance': {
'type': 'integer',
'default': DEFAULTS['distance'],
'required': False
},
'menu_labels': {
'type': 'dict',
'required': False,
Expand Down
6 changes: 4 additions & 2 deletions src/core/widgets/yasb/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
blur: bool,
alignment: str,
direction: str,
distance: int,
menu_labels: dict[str, str],
callbacks: dict[str, str],
menu_list: list[str, dict[str]] = None
Expand All @@ -35,6 +36,7 @@ def __init__(
self._blur = blur
self._alignment = alignment
self._direction = direction
self._distance = distance
self._menu_labels = menu_labels
# Construct container
self._widget_container_layout: QHBoxLayout = QHBoxLayout()
Expand Down Expand Up @@ -199,10 +201,10 @@ def _toggle_menu(self):
return

self._menu.adjustSize()
widget_global_pos = self.mapToGlobal(QPoint(0, self.height() + 6))
widget_global_pos = self.mapToGlobal(QPoint(0, self.height() + self._distance))

if self._direction == 'up':
global_y = self.mapToGlobal(QPoint(0, 0)).y() - self._menu.height()
global_y = self.mapToGlobal(QPoint(0, 0)).y() - self._menu.height() - self._distance
widget_global_pos = QPoint(self.mapToGlobal(QPoint(0, 0)).x(), global_y)

if self._alignment == 'left':
Expand Down

0 comments on commit b169188

Please sign in to comment.