adding a basic other struct in rust... well trying...
This commit is contained in:
parent
7eba697dc2
commit
9644631f7c
11 changed files with 124 additions and 36 deletions
|
@ -1,11 +1,11 @@
|
|||
[package]
|
||||
name = "qml-minimal"
|
||||
name = "libre-presenter"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = [
|
||||
"Chris Cochrun <chris@cochrun.xyz>"
|
||||
]
|
||||
license = "MIT OR Apache-2.0"
|
||||
license = "GPL-3.0"
|
||||
|
||||
# This will instruct Cargo to create a static
|
||||
# library which CMake can link against
|
||||
|
|
|
@ -2,4 +2,5 @@ use cxx_qt_build::CxxQtBuilder;
|
|||
|
||||
fn main() {
|
||||
CxxQtBuilder::new().file("src/cxxqt_object.rs").build();
|
||||
CxxQtBuilder::new().file("src/service_thing.rs").build();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#[cxx_qt::bridge]
|
||||
mod my_object {
|
||||
use cxx_qt_lib::QVariantValue;
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("cxx-qt-lib/qstring.h");
|
||||
type QString = cxx_qt_lib::QString;
|
||||
include!("cxx-qt-lib/qvariant.h");
|
||||
type QVariant = cxx_qt_lib::QVariant;
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject]
|
||||
|
@ -31,11 +34,24 @@ mod my_object {
|
|||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn say_hi(&self, string: &QString, number: i32) {
|
||||
pub fn say_hi(self: Pin<&mut Self>, string: &QString, number: i32) {
|
||||
println!(
|
||||
"Hi from Rust! String is '{}' and number is {}",
|
||||
string, number
|
||||
);
|
||||
println!("length is: {}", string.to_string().len());
|
||||
let mut nstr: String = string.to_string();
|
||||
nstr.push_str(" hi");
|
||||
self.set_string(QString::from(nstr.as_str()));
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) {
|
||||
println!("wow!");
|
||||
match variant.value() {
|
||||
QVariantValue::QString(string) => self.set_string(string),
|
||||
_ => println!("Unknown QVariant type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,3 +14,4 @@ mod tests {
|
|||
}
|
||||
|
||||
mod cxxqt_object;
|
||||
mod service_thing;
|
||||
|
|
80
src/rust/src/service_thing.rs
Normal file
80
src/rust/src/service_thing.rs
Normal file
|
@ -0,0 +1,80 @@
|
|||
#[cxx_qt::bridge]
|
||||
mod service_thing {
|
||||
use cxx_qt_lib::QVariantValue;
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("cxx-qt-lib/qstring.h");
|
||||
type QString = cxx_qt_lib::QString;
|
||||
include!("cxx-qt-lib/qvariant.h");
|
||||
type QVariant = cxx_qt_lib::QVariant;
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject]
|
||||
pub struct ServiceThing {
|
||||
#[qproperty]
|
||||
name: QString,
|
||||
#[qproperty]
|
||||
kind: QString,
|
||||
#[qproperty]
|
||||
background: QString,
|
||||
#[qproperty]
|
||||
background_type: QString,
|
||||
#[qproperty]
|
||||
text: QString,
|
||||
#[qproperty]
|
||||
audio: QString,
|
||||
#[qproperty]
|
||||
font: QString,
|
||||
#[qproperty]
|
||||
font_size: QString,
|
||||
#[qproperty]
|
||||
active: bool,
|
||||
#[qproperty]
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
impl Default for ServiceThing {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: QString::from(""),
|
||||
kind: QString::from(""),
|
||||
background: QString::from(""),
|
||||
background_type: QString::from(""),
|
||||
text: QString::from(""),
|
||||
audio: QString::from(""),
|
||||
font: QString::from(""),
|
||||
font_size: QString::from(""),
|
||||
active: false,
|
||||
selected: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl qobject::ServiceThing {
|
||||
#[qinvokable]
|
||||
pub fn activate(self: Pin<&mut Self>) {
|
||||
self.set_active(true);
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn say_hi(self: Pin<&mut Self>, string: &QString, number: i32) {
|
||||
println!(
|
||||
"Hi from Rust! String is '{}' and number is {}",
|
||||
string, number
|
||||
);
|
||||
println!("length is: {}", string.to_string().len());
|
||||
let mut nstr: String = string.to_string();
|
||||
nstr.push_str(" hi");
|
||||
self.set_name(QString::from(nstr.as_str()));
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) {
|
||||
println!("wow!");
|
||||
match variant.value() {
|
||||
QVariantValue::QString(string) => self.set_name(string),
|
||||
_ => println!("Unknown QVariant type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue