forked from cyndis/qmlrs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expanding ffi.rs to other types: bool
ffi.rs understands bool now modified the factorial example such that `compute` takes and returns a `bool`. The user interface randomly returns `true` or `false` (Inspired by cyndis#10)
- Loading branch information
Showing
5 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[macro_use] | ||
extern crate qmlrs; | ||
|
||
struct DummyOracle; | ||
impl DummyOracle { | ||
fn calculate(&self, x: bool) -> bool { | ||
x | ||
} | ||
} | ||
|
||
Q_OBJECT! { DummyOracle: | ||
slot fn calculate(bool); | ||
// signal fn test(); | ||
} | ||
|
||
fn main() { | ||
let mut engine = qmlrs::Engine::new(); | ||
|
||
engine.set_property("oracle", DummyOracle); | ||
engine.load_local_file("examples/oracle_ui.qml"); | ||
|
||
engine.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import QtQuick 2.2 | ||
import QtQuick.Controls 1.2 | ||
import QtQuick.Layouts 1.0 | ||
import QtQuick.XmlListModel 2.0 | ||
|
||
ApplicationWindow { | ||
visible: true | ||
title: "NaiveLieDetector" | ||
|
||
property int margin: 11 | ||
width: mainLayout.implicitWidth + 2 * margin | ||
height: mainLayout.implicitHeight + 2 * margin | ||
minimumWidth: mainLayout.Layout.minimumWidth + 2 * margin | ||
minimumHeight: mainLayout.Layout.minimumHeight + 2 * margin | ||
|
||
ColumnLayout { | ||
id: mainLayout | ||
anchors.fill: parent | ||
anchors.margins: margin | ||
|
||
RowLayout { | ||
TextField { | ||
id: numberField | ||
Layout.fillWidth: true | ||
|
||
placeholderText: "Enter a statement" | ||
focus: true | ||
|
||
onAccepted: doCalculate() | ||
} | ||
|
||
Button { | ||
text: "Calculate" | ||
|
||
onClicked: doCalculate() | ||
} | ||
} | ||
|
||
TextArea { | ||
id: resultArea | ||
Layout.fillWidth: true | ||
Layout.fillHeight: true | ||
} | ||
} | ||
|
||
function doCalculate() { | ||
//var num = parseInt(numberField.text); | ||
resultArea.text = oracle.calculate( (Math.random() < 0.5 ? true : false) ); | ||
} | ||
|
||
/* | ||
Connections { | ||
target: oracle | ||
onTest: console.log("Got test signal!") | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters