Skip to content

Commit a344b1b

Browse files
committed
fix: left aligned sub-headings for grouping menu items
1 parent 939dd13 commit a344b1b

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

app/core/views.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,73 @@ def __init__(
869869
)
870870

871871

872+
class TNavigationMenuNoLeading(UserControl):
873+
"""
874+
Returns a navigation menu for the application without a leading content.
875+
876+
:param title: Title of the navigation menu.
877+
:param on_change: Callable function to be called when the selected item in the menu changes.
878+
:param selected_index: The index of the selected item in the menu.
879+
:param destinations: List of destinations in the menu.
880+
:param menu_height: The height of the menu.
881+
:return: A NavigationRail widget containing the navigation menu.
882+
"""
883+
884+
def __init__(
885+
self,
886+
title: str,
887+
on_change,
888+
selected_index: Optional[int] = 0,
889+
destinations=[],
890+
menu_height: int = 300,
891+
width: int = int(dimens.MIN_WINDOW_WIDTH * 0.3),
892+
left_padding: int = dimens.SPACE_STD,
893+
top_margin: int = dimens.SPACE_STD,
894+
):
895+
896+
super().__init__()
897+
self.titleContainer = Container(
898+
content=TSubHeading(
899+
subtitle=title,
900+
align=utils.TXT_ALIGN_LEFT,
901+
expand=True,
902+
color=colors.GRAY_DARK_COLOR,
903+
),
904+
expand=False,
905+
width=width,
906+
alignment=alignment.center_left,
907+
margin=margin.only(top=top_margin),
908+
padding=padding.only(left=left_padding),
909+
)
910+
self.navigationRail = NavigationRail(
911+
selected_index=selected_index,
912+
min_width=utils.COMPACT_RAIL_WIDTH,
913+
extended=True,
914+
height=menu_height,
915+
min_extended_width=width,
916+
destinations=destinations,
917+
on_change=on_change,
918+
)
919+
920+
def setBgColor(self, side_bar_bg_color):
921+
# set the background color of the navigation menu
922+
self.navigationRail.bgcolor = side_bar_bg_color
923+
self.titleContainer.bgcolor = side_bar_bg_color
924+
self.update()
925+
926+
def build(self):
927+
return Column(
928+
controls=[
929+
self.titleContainer,
930+
self.navigationRail,
931+
],
932+
alignment=utils.START_ALIGNMENT,
933+
horizontal_alignment=utils.START_ALIGNMENT,
934+
spacing=0,
935+
run_spacing=0,
936+
)
937+
938+
872939
class THomeGrid(GridView):
873940
"""Returns a grid view used in the home screen"""
874941

app/home/view.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,17 @@ def __init__(
241241
)
242242
self.selected_tab = 0
243243

244-
self.main_menu = views.TNavigationMenu(
244+
self.main_menu = views.TNavigationMenuNoLeading(
245245
title=self.main_menu_handler.menu_title,
246246
destinations=self.get_menu_destinations(),
247247
on_change=lambda e: self.on_menu_destination_change(e),
248+
248249
)
249-
self.secondary_menu = views.TNavigationMenu(
250+
self.secondary_menu = views.TNavigationMenuNoLeading(
250251
title=self.secondary_menu_handler.menu_title,
251252
destinations=self.get_menu_destinations(menu_level=1),
252253
on_change=lambda e: self.on_menu_destination_change(e, menu_level=1),
254+
253255
)
254256
self.current_menu_handler = self.main_menu_handler
255257
self.destination_view = self.current_menu_handler.items[0].destination
@@ -362,7 +364,10 @@ def build(self):
362364
)
363365
self.side_bar = Container(
364366
width=SIDEBAR_WIDTH,
365-
padding=padding.only(top=dimens.SPACE_XL),
367+
padding=padding.only(
368+
top=dimens.SPACE_XL,
369+
left=0,
370+
),
366371
content=Column(
367372
controls=[
368373
self.main_menu,
@@ -419,18 +424,14 @@ def load_preferred_theme(self):
419424
self.show_snack(result.error_msg, is_error=True)
420425
return
421426
self.preferred_theme = result.data
422-
side_bar_components = [
423-
self.side_bar,
424-
self.main_menu,
425-
self.secondary_menu,
426-
]
427427
side_bar_bg_color = colors.SIDEBAR_DARK_COLOR # default is dark mode
428428
self.action_bar.bgcolor = colors.ACTION_BAR_DARK_COLOR
429429
if self.preferred_theme == theme.THEME_MODES.light.value:
430430
side_bar_bg_color = colors.SIDEBAR_LIGHT_COLOR
431431
self.action_bar.bgcolor = colors.ACTION_BAR_LIGHT_COLOR
432-
for component in side_bar_components:
433-
component.bgcolor = side_bar_bg_color
432+
self.side_bar.bgcolor = side_bar_bg_color
433+
self.main_menu.setBgColor(side_bar_bg_color)
434+
self.secondary_menu.setBgColor(side_bar_bg_color)
434435
self.footer.bgcolor = side_bar_bg_color # footer and side bar have same bgcolor
435436
self.update_self()
436437

0 commit comments

Comments
 (0)