I am working on a chess engine which is written in C ( ttps://launchpad.net/enpassant) . By the time it is completed, I plan to have different versions for the Desktop and mobile. Now, is it possible for me to have a GUI written with the help of the Ubuntu mobile SDK while uses the C engine internally?
Ubuntu – Is it possible to write a Mobile app with a engine written in C
application-developmentubuntu-touch
Related Solutions
The rules for the contest is that your application must entirely run in /opt
. While in future contests we hope to be able to relax this requirement (as we sandbox Ubuntu better in the future), right now we need to require that your app runs fully in /opt
.
Changing aspects of the layout depending on the size of the window can be accomplished in a number of ways. At the most basic level, you can just set properties to different values based on the dimensions. Here is a minimal example that draws a grey square that turns orange if you make the window bigger:
Run with 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
}
}
Of course, if you have more complex elements to your application this can get a bit tedious. To help with this, the Ubuntu Toolkit provides a ConditionalLayout component where you can define different layouts that will be activated when a condition is met. This happens dynamically, and you can see the changes as you resize the window.
Here is a more complex example using 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
When in the default phone-like size, it looks like:
When it is expanded to a tablet or desktop-like size, it looks like:
Related Question
- Application Development – Can Apps Install in /usr Directory?
- Ubuntu – Can a single Ubuntu SDK target touch and desktop with separate layouts
- Ubuntu – How to install the Ubuntu SDK on Debian
- Ubuntu – Ubuntu Touch App with Simple UI (QMake) – how to connect C++ to QML
- Ubuntu – Building Full Perl Support in Ubuntu SDK
Best Answer
This should work since the SDK is based on Qt5 and QtQuick 2.0 you should be able to port (integrate) your C code because you are able to embed C code in C++. Maybe you have to write a Qt wrapper to connect the QML UI with the C backend.