add simple layout demo

This commit is contained in:
王劲鹏 2021-03-01 18:59:09 +08:00 committed by osborn
parent 257f3f0dab
commit e35f0a79c4
6 changed files with 71 additions and 36 deletions

View File

@ -8,33 +8,37 @@
DoricDemoBridge::DoricDemoBridge(QObject *parent) : QObject(parent) {}
void DoricDemoBridge::navigate(QVariant route) {
QString name;
switch (route.toInt()) {
case 0:
QString name = "Snake.es5.js";
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
QQuickView *view = new QQuickView();
{
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml"));
view->setSource(url);
view->setWidth(450);
view->setHeight(800);
}
{
QQmlComponent component(view->engine());
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
component.loadUrl(url);
QQuickItem *quickItem = qobject_cast<QQuickItem *>(component.create());
DoricPanel *panel = new DoricPanel(view->engine(), quickItem);
quickItem->setWidth(450);
quickItem->setHeight(800);
quickItem->setParentItem(view->rootObject());
panel->config(script, name, NULL);
}
view->show();
name = "SimpleDemo.es5.js";
break;
case 1:
name = "Snake.es5.js";
break;
}
QString script = DoricUtils::readAssetFile("/doric/bundles", name);
QQuickView *view = new QQuickView();
{
const QUrl url(QStringLiteral("qrc:/doric/qml/view.qml"));
view->setSource(url);
view->setWidth(450);
view->setHeight(800);
}
{
QQmlComponent component(view->engine());
const QUrl url(QStringLiteral("qrc:/doric/qml/panel.qml"));
component.loadUrl(url);
QQuickItem *quickItem = qobject_cast<QQuickItem *>(component.create());
DoricPanel *panel = new DoricPanel(view->engine(), quickItem);
quickItem->setWidth(450);
quickItem->setHeight(800);
quickItem->setParentItem(view->rootObject());
panel->config(script, name, NULL);
}
view->show();
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.14.0, 2021-03-01T11:14:08. -->
<!-- Written by QtCreator 4.14.0, 2021-03-01T18:01:24. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -4,13 +4,11 @@
<file alias="qtquickcontrols2.conf">./resources/qtquickcontrols2.conf</file>
</qresource>
<qresource prefix="/doric">
<file alias="doric-sandbox.js">../../doric-js/bundle/doric-sandbox.js</file>
<file alias="doric-sandbox.es5.js">../../doric-js/bundle/doric-sandbox.es5.js</file>
<file alias="doric-lib.js">../../doric-js/bundle/doric-lib.js</file>
<file alias="doric-lib.es5.js">../../doric-js/bundle/doric-lib.es5.js</file>
</qresource>
<qresource prefix="/doric/bundles">
<file alias="Snake.js">../../doric-demo/bundle/src/Snake.js</file>
<file alias="SimpleDemo.es5.js">../../doric-demo/bundle/src/SimpleDemo.es5.js</file>
<file alias="Snake.es5.js">../../doric-demo/bundle/src/Snake.es5.js</file>
</qresource>
<qresource prefix="/doric/qml">

View File

@ -12,19 +12,28 @@ ApplicationWindow {
ListView {
width: parent.width
model: 1
model: 2
delegate: Rectangle {
Column {
anchors.centerIn: parent
Text {
text: {return "Snake.js"}
text: {
switch (index) {
case 0:
return "SimpleDemo.es5.js"
case 1:
return "Snake.es5.js"
}
}
}
}
width: parent.width
height: 60
MouseArea {
anchors.fill: parent
onClicked: {demoBridge.navigate(index)}
onClicked: {
demoBridge.navigate(index)
}
}
}
}

View File

@ -3,9 +3,5 @@ import QtQuick.Controls 2.5
Flex {
flexDirection: "column"
alignItems: "center"
alignSelf: "center"
justifyContent: "spaceAround"
alignContent: "stretch"
}

View File

@ -0,0 +1,28 @@
import { Group, Panel, text, gravity, Color, LayoutSpec, vlayout, hlayout, scroller, layoutConfig, stack, Gravity } from "doric";
@Entry
class LayoutDemo extends Panel {
build(rootView: Group) {
hlayout([
stack([], {
width: 100,
height: 100,
backgroundColor: Color.RED
}),
stack([], {
width: 100,
height: 100,
backgroundColor: Color.GREEN
}),
stack([], {
width: 100,
height: 100,
backgroundColor: Color.BLUE
})
], {
width: 300,
height: 300,
backgroundColor: Color.BLACK
}).in(rootView)
}
}