Search code examples
pythonkivymaterial-designkivy-languagekivymd

How to make a clipped navigation drawer with KivyMD (so it doesn't cover the MDToolbar)?


How can I implement a KivyMD Navigation Drawer so that it is "clipped" and doesn't cover the top toolbar (where the hamburger menu icon button resides)?

The KivyMD documentation for the NavigationDrawer component implements the drawer so that it spans from the very top of the screen to the very bottom of the screen. This is unfortunate because it covers the hamburger menu used to close it, which I'd like to leave uncovered so the user can toggle the drawer (in both directions) using this button.

Here is an example visual of what happens by default in KivyMD when implementing a Navigation Drawer (as described above):

enter image description here

Meanwhile, the Google Material Design (MD) specification (of which KivyMD is following) states that the Navigation Drawer component can be "clipped" -- where the drawer spans from the bottom of the toolbar down to the very bottom of the app.

Here's an image taken from the Google MD spec documentation link above showing what a "clipped" drawer should look like

Image of an app with a clipped Navigation Drawer (source: Google Material Design spec)

How can I implement an MDNavigationDrawer in KivyMD that is "clipped" such that it doesn't cover the MDToolbar?


Solution

  • The following hack redraws a new MDToolbar inside the Navigation Drawer, which is what I'm using until someone provides a better solution.

    I just added an MDToolbar to my main.kv file so it looks like this

                    MDNavigationDrawer:
                            id: nav_drawer
    
                            BoxLayout:
                                    orientation: 'vertical'
    
                                    MDToolbar:
                                            title: 'BusKill'
                                            left_action_items: [[ 'menu', lambda x: nav_drawer.set_state('toggle') ]]
    
                                    MDList:
    
                                            OneLineIconListItem:
                                                    text: 'Update'
    
                                                    IconLeftWidget:
                                                            icon: 'update'
    

    Which produced the following:

    KivyMD double MDToolbar so Navigation Drawer doesn't hide the menu button (clipped toolbar)