We have moved to a new Sailfish OS Forum. Please start new discussions there.
5

How to implement a menu sidebar, that slides in and out?

asked 2018-10-21 17:48:39 +0300

jsommer gravatar image

updated 2018-10-21 17:50:13 +0300

I wand to implement a menu sidebar with the following requirements:

  1. The user should be able to slide in and out the sidebar
  2. The expanded sidebar should overlapp the page content respectively columns
  3. The list should beginn from the bottom to improve one hand control

A Drawer or DockedPanel seem to be the appropriate UI elements. It's possible to embed SilicaListView in both of them. I'm struggling with the following challenges:

  • The Drawer has a full trasparent background. How to confiugre a background like the DockedPanel? The Drawer's animation feels more fluent than the animation of the DockedPanel.
  • I could only manage to align the SilicaListView to the top of the panel, not at the button. I didn't found any property to invert the alignment.

Here are some code snippets:

DockedPanel {
         id: panel

         height: parent.height
         width: Theme.itemSizeExtraLarge+ 2 * Theme.paddingLarge

         dock: Dock.Right

         SilicaListView {
               anchors.fill : parent

               model: ListModel {
                        ListElement { content: "one" }
                        ListElement { content: "two" }
                        ListElement { content: "three" }
                        ListElement { content: "four" }
                        ListElement { content: "five" }
               }

               VerticalScrollDecorator {}

               delegate: ListItem {
                    id: menuItem
                    Label {
                             x: Theme.horizontalPageMargin
                             y: Theme.paddingLarge
                             text: content
                             anchors.leftMargin: Theme.horizontalPageMargin
                             anchors.bottom: parent.Bottom
                             color: menuItem.highlighted ? Theme.highlightColor : Theme.primaryColor
                    }
               }
         }
     }

And this is the one for the Drawer:

Drawer {
    id: leftMenu

    anchors.fill: parent
    dock: Dock.Left

    background: SilicaListView {
        anchors.fill: parent
        model: 5

        VerticalScrollDecorator {}

        delegate: ListItem {
            id: listItem

            Label {
                x: Theme.horizontalPageMargin
                text: "Menu Item " + modelData
                anchors.verticalCenter: parent.verticalCenter
                color: listItem.highlighted ? Theme.highlightColor : Theme.primaryColor
            }
        }
    }
}
edit retag flag offensive close delete

Comments

You should look at the installed contents of the default media player which contains a docked panel for the music controls within the app.

There are a couple of paths to examine,

/usr/share/jolla-mediaplayer/*

and;

/usr/lib/qt5/qml/Sailfish/Media/*

Spam Hunter ( 2018-10-21 18:58:41 +0300 )edit

Quickbar doesn't already do this?

bocephus ( 2018-10-22 22:58:35 +0300 )edit

@bocephus I don't find this UI element in the Silica documentation. Could you post a link to the documentation? If the element is not covered by Silica, it may break a consistent look and feel.

@Edz Indeed. So it should work. I will have a look at the recommended path. The apps are not deployed as binaries but readable qml files? I'm surprised.

jsommer ( 2018-10-28 12:06:56 +0300 )edit

@bocephus I seems, that Jolla uses a DockedPanel, defined in the MediaPlayerControlsPanel.qml.

DockedPanel {
    id: panel

    ...

    width: parent.width
    height: column.height + (_isLandscape ? Theme.paddingLarge : Theme.paddingLarge * 2)
    contentHeight: height
    flickableDirection: Flickable.VerticalFlick

    opacity: Qt.inputMethod.visible ? 0.0 : 1.0
    Behavior on opacity { FadeAnimation {}}

    onActiveChanged: if (!active) hideControls()
    onPositionChanged: if (!slider.pressed) slider.value = position

    background: MediaPlayerPanelBackground { }

It seems, that the app drwas the background and doesn't use a standard:

import QtQuick 2.0
import Sailfish.Silica 1.0

Rectangle {
    gradient: Gradient {
        GradientStop { position: 0.0; color: "transparent" }
        GradientStop { position: 0.7; color: Theme.rgba(Theme.highlightBackgroundColor, Theme.highlightBackgroundOpacity) }
    }
}

Do I also need the opacity property? I'm new with QML.

jsommer ( 2018-10-28 18:44:47 +0300 )edit

@jsommer Quickbar is a 3rd party app in Harbour.

bocephus ( 2018-11-01 19:40:49 +0300 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-11-01 18:27:00 +0300

jsommer gravatar image

I came to the conlusion, that both Ui elements are possible, while the Drawer opens faster and requires an additional background definition. I aligned the menu to the bottom of the pache with the anchor property.

Drawer {
    id: leftMenu

    anchors.fill: parent
    dock: Dock.Left

    background: Rectangle {
        anchors.fill: parent

        color: Theme.rgba(Theme.highlightBackgroundColor, Theme.highlightBackgroundOpacity)

        SilicaListView {
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.right: parent.right

            ...

            height: Theme.itemSizeMedium * (model.count - 1)
        }
    }
}
edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
4 followers

Stats

Asked: 2018-10-21 17:48:39 +0300

Seen: 1,361 times

Last updated: Nov 01 '18