单个 Ubuntu SDK 可以针对具有单独布局的触摸和桌面吗?

sjm*_*der 9 application-development qml ubuntu-sdk ubuntu-touch

我知道触摸应用程序将在具有相同 UI 的桌面上运行,但我想知道在桌面模式下运行时,单个 Ubuntu SDK 应用程序是否有可能具有带有桌面样式 UI 元素的多窗口 UI,同时也在触摸平台上运行时提供单独的触摸 UI。

and*_*ing 6

可以通过多种方式根据窗口的大小更改布局的各个方面。在最基本的层面上,您可以根据维度将属性设置为不同的值。这是一个最小的例子,它绘制一个灰色方块,如果你把窗口变大,它就会变成橙色:

运行 qmlscene path/to/file.qml

import QtQuick 2.0
import Ubuntu.Components 0.1

MainView {
    id: root
    width: units.gu(50)
    height: units.gu(50)

    Rectangle {
        id: hello
        color: parent.width > units.gu(60) ? UbuntuColors.orange : UbuntuColors.warmGrey
        anchors.fill: parent
    }
}
Run Code Online (Sandbox Code Playgroud)

当然,如果您的应用程序有更复杂的元素,这可能会变得有点乏味。为了解决这个问题,Ubuntu Toolkit 提供了一个ConditionalLayout 组件,您可以在其中定义在满足条件时将激活的不同布局。这是动态发生的,您可以在调整窗口大小时看到更改。

这是一个更复杂的例子,使用ConditionalLayout

import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import Ubuntu.Layouts 0.1

MainView {
    id: root
    width: units.gu(50)
    height: units.gu(75)

    Page {
        anchors.fill: parent

        Layouts {
            id: layouts
            anchors.fill: parent
            layouts: [

                ConditionalLayout {
                    name: "flow"
                    when: layouts.width > units.gu(60)

                    Flow {
                        anchors.fill: parent
                        flow: Flow.LeftToRight

                        ItemLayout {
                            item: "sidebar"
                            id: sidebar
                            anchors {
                                top: parent.top
                                bottom: parent.bottom
                            }
                            width: parent.width / 3
                        }

                        ItemLayout {
                            item: "colors"
                            anchors {
                                top: parent.top
                                bottom: parent.bottom
                                right: parent.right
                                left: sidebar.right
                            }
                        }
                    }
                }
            ]

            Column {
                id: sidebar
                anchors {
                    left: parent.left
                    top: parent.top
                    right: parent.right
                }
                Layouts.item: "sidebar"

                ListItem.Header {
                    text: "Ubuntu Color Palette"
                }

                ListItem.Standard {
                    id: orangeBtn
                    text: "Ubuntu Orange"
                    control: Button {
                        text: "Click me"
                        onClicked: {
                            hello.color = UbuntuColors.orange
                        }
                    }
                }

                ListItem.Standard {
                    id: auberBtn
                    text: "Canonical Aubergine"
                    control: Button {
                        text: "Click me"
                        onClicked: {
                            hello.color = UbuntuColors.lightAubergine
                        }
                    }
                }

                ListItem.Standard {
                    id: grayBtn
                    text: "Warm Grey"
                    control: Button {
                        text: "Click me"
                        onClicked: {
                            hello.color = UbuntuColors.warmGrey
                        }
                    }
                }
            } // Column

            Rectangle {
                id: hello
                Layouts.item: "colors"
                color: UbuntuColors.warmGrey
                anchors {
                    top: sidebar.bottom
                    bottom: parent.bottom
                    left: parent.left
                    right: parent.right
                }

                Label {
                    anchors.centerIn: parent
                    text: "Hello (ConditionalLayout) World!"
                    color: "black"
                    fontSize: "large"
                }
            }
        } // Layouts
    } // Page
} // Main View
Run Code Online (Sandbox Code Playgroud)

在默认的类似电话的大小时,它看起来像:

手机布局

当它扩展到平板电脑或类似桌面的大小时,它看起来像:

平板电脑布局


fco*_*e90 0

我认为您可以使用条件布局获得此结果。