combobox, minor fixes

This commit is contained in:
Sarah Jamie Lewis 2020-07-11 14:32:43 -07:00
parent 232e19d0a9
commit 4b86519fa0
7 changed files with 148 additions and 51 deletions

62
Cargo.lock generated
View File

@ -139,9 +139,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.57"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe"
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
[[package]]
name = "cfg-if"
@ -281,9 +281,9 @@ dependencies = [
[[package]]
name = "deflate"
version = "0.8.4"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e5d2a2273fed52a7f947ee55b092c4057025d7a3e04e5ecdbd25d6c3fb1bd7"
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
dependencies = [
"adler32",
"byteorder",
@ -359,9 +359,9 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
name = "euclid"
version = "0.20.13"
version = "0.20.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "555d51b9a929edb14183fad621e2d5736fc8760707a24246047288d4c142b6bd"
checksum = "2bb7ef65b3777a325d1eeefefab5b6d4959da54747e33bd6258e789640f307ad"
dependencies = [
"num-traits",
]
@ -427,9 +427,9 @@ checksum = "452b31b3ffe7cf13de531eefae493301c85995a953c808d7c79a8f45abae0706"
[[package]]
name = "hermit-abi"
version = "0.1.14"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
@ -463,9 +463,9 @@ dependencies = [
[[package]]
name = "instant"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69da7ce1490173c2bf4d26bc8be429aaeeaf4cce6c4b970b7949651fa17655fe"
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -480,9 +480,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "jpeg-decoder"
version = "0.1.19"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b47b4c4e017b01abdc5bcc126d2d1002e5a75bbe3ce73f9f4f311a916363704"
checksum = "cc797adac5f083b8ff0ca6f6294a999393d76e197c36488e2ef732c4715f6fa3"
dependencies = [
"byteorder",
"rayon",
@ -505,9 +505,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.71"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
[[package]]
name = "libloading"
@ -699,7 +699,7 @@ dependencies = [
[[package]]
name = "orbtk"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"dces",
"orbtk-api",
@ -716,7 +716,7 @@ dependencies = [
[[package]]
name = "orbtk-api"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"dces",
"derive_more",
@ -738,7 +738,7 @@ dependencies = [
[[package]]
name = "orbtk-css-engine"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"cssparser",
"orbtk-utils",
@ -747,7 +747,7 @@ dependencies = [
[[package]]
name = "orbtk-proc-macros"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"case",
"proc-macro2",
@ -758,7 +758,7 @@ dependencies = [
[[package]]
name = "orbtk-render"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"image",
"orbtk-utils",
@ -770,7 +770,7 @@ dependencies = [
[[package]]
name = "orbtk-shell"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"console_error_panic_hook",
"derive_more",
@ -787,7 +787,7 @@ dependencies = [
[[package]]
name = "orbtk-theme"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"lazy_static",
"orbtk-css-engine",
@ -796,7 +796,7 @@ dependencies = [
[[package]]
name = "orbtk-tree"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"dces",
]
@ -804,12 +804,12 @@ dependencies = [
[[package]]
name = "orbtk-utils"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
[[package]]
name = "orbtk-widgets"
version = "0.3.1-alpha3"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#e8b0f9a3f8dc322414f1ea64de57f72979e17496"
source = "git+https://github.com/redox-os/orbtk.git?branch=develop#cef2271030b413d680e3d73c6f9c733f1971229a"
dependencies = [
"dces",
"lazy_static",
@ -914,9 +914,9 @@ dependencies = [
[[package]]
name = "pkg-config"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "png"
@ -938,7 +938,7 @@ checksum = "c150bf7479fafe3dd8740dbe48cc33b2a3efb7b0fe3483aced8bbc39f6d0238d"
dependencies = [
"bitflags",
"crc32fast",
"deflate 0.8.4",
"deflate 0.8.6",
"miniz_oxide",
]
@ -1183,9 +1183,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.56"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_users"
@ -1408,9 +1408,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.4.0"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
[[package]]
name = "spin_sleep"

View File

@ -1,6 +1,6 @@
Grid {
rows:2
cols:2
columns:2
Rectangle {
color: "#F3F0F4"
Text {

View File

@ -6,18 +6,20 @@ Grid {
}
HelloTwitter {
}
Rectangle {
color: "#8c63a4"
color: "#634B72"
Text {
id: target
anchors.centerIn: parent
text: "Hello, World!"
}
}
Grid {
rows: 2
columns: 2
@ -43,6 +45,20 @@ Grid {
]]
}
}
Rectangle {
color: "#b29dbe"
ComboBox {
id: combobox
anchors.centerIn: parent
items = [[
["1", "World", "@@#$@#"]
]]
selected: 2
onselect = [[
update_property("target", "text", get_property("combobox","selected"));
]]
}
}
Rectangle {
color: "#F3F0F4"
Button {
@ -54,12 +70,6 @@ Grid {
]]
}
}
Rectangle {
color: "#b29dbe"
Text {
anchors.centerIn: parent
text: "Hello, World!"
}
}
}
}

View File

@ -1,7 +1,7 @@
use orbtk::prelude::*;
use rhai::Engine;
use rhai::RegisterFn;
use rhai::{Array, Engine};
use std::sync::mpsc::{Receiver, Sender};
use std::time::Duration;
pub mod parser;
@ -14,6 +14,7 @@ use evmap::{ReadHandle, WriteHandle};
use rand::Rng;
use std::borrow::BorrowMut;
use std::collections::VecDeque;
use std::ops::Index;
use std::sync::mpsc;
#[macro_use]
@ -131,13 +132,6 @@ impl State for MVState {
rng.gen_range(0.0, 1.0) as f32
});
for ((entity, property), code) in self.ids.code.iter() {
let result = self.engine.eval::<(f32)>(code.as_str());
let point = result.unwrap();
println!("{}.{} = {} {:?}", entity, property, code, point);
ctx.child(entity.as_str()).set::<f32>(property, point);
}
for id in self.ids.indexes.iter() {
if ctx.child(id.as_str()).has::<String16>("text") {
let res = ctx.child(id.as_str()).get::<String16>("text").clone();
@ -147,6 +141,21 @@ impl State for MVState {
}
w.update(id.clone() + ".text", res.as_string());
}
if ctx.child(id.as_str()).has::<i32>("selected_index") {
let index = ctx.child(id.as_str()).get::<i32>("selected_index").clone();
match self.ids.code.get(&(id.clone(), String::from("items").clone())) {
Some(code) => {
let engine = Engine::new();
match engine.eval::<Array>(code.as_str()) {
Ok(list) => {
w.update(id.clone() + ".selected", list.index(index as usize).to_string());
}
_ => {}
}
}
_ => {}
}
}
}
w.refresh();
}

View File

@ -0,0 +1,75 @@
use crate::parser::Value::{QmlIdent, QmlString};
use crate::parser::{Value, QML};
use crate::state;
use crate::widget_builders::{parse_number, QmlContext, WidgetBuilder};
use orbtk::prelude::HashMap;
use orbtk::prelude::*;
use orbtk::Entity;
use rhai::{Array, Engine};
use std::ops::Index;
pub struct ComboBoxBuilder {}
impl WidgetBuilder for ComboBoxBuilder {
fn build(&self, properties: HashMap<String, Value>, _children: Vec<(String, QML)>) -> Box<dyn Fn(Entity, &mut BuildContext, usize, usize, &mut QmlContext) -> Entity> {
return Box::new(move |id, ctx, row, col, qmlctx| -> Entity {
let mut combo_box = ComboBox::new();
combo_box = combo_box.attach(Grid::row(row as usize));
combo_box = combo_box.attach(Grid::column(col as usize));
let widget_id = match properties.get("id") {
Some(QmlIdent(text)) => {
combo_box = combo_box.id(text.clone());
qmlctx.indexes.push(text.clone());
text.clone()
}
_ => String::new(),
};
let items = match properties.get("items").unwrap() {
QmlString(code) => {
qmlctx.code.insert((widget_id, String::from("items")), code.to_string());
let engine = Engine::new();
match engine.eval::<Array>(code.as_str()) {
Ok(list) => {
println!("Found Combobox with {} items {:?}", list.len(), list);
list.to_vec()
}
_ => vec![],
}
}
_ => vec![],
};
combo_box = combo_box.count(items.len());
combo_box = combo_box.items_builder(move |bc, index| {
let text = items.index(index);
TextBlock::new().margin((0., 0., 0., 0.)).v_align("center").text(text.to_string()).build(bc)
});
let code = match properties.get("onselect").unwrap() {
QmlString(code) => code.clone(),
_ => String::new(),
};
combo_box = combo_box.on_changed(move |states, _| {
state(id, states).action(code.clone());
});
let selected = parse_number(properties.get("selected")) as u32;
combo_box = combo_box.selected_index(selected as i32);
match properties.get("anchors.centerIn") {
Some(QmlIdent(str)) => {
if str.eq("parent") {
combo_box = combo_box.v_align(Alignment::Center);
combo_box = combo_box.h_align(Alignment::Center);
}
}
_ => {}
}
return combo_box.build(ctx);
});
}
}

View File

@ -13,7 +13,7 @@ impl WidgetBuilder for GridBuilder {
grid = grid.attach(Grid::row(row as usize));
grid = grid.attach(Grid::column(col as usize));
let rows = parse_number(properties.get("rows")) as u32;
let _cols = parse_number(properties.get("cols")) as u32;
let cols = parse_number(properties.get("columns")) as u32;
let mut grid_rows = Rows::new();
for _i in 0..rows {
@ -29,14 +29,14 @@ impl WidgetBuilder for GridBuilder {
let mut grow = 0u32;
let mut gcol = 0u32;
//rect = rect.attach(Grid::column(gcol as usize));
let qwb = QmlWidgetBuilder::new();
for (child_type, child_qml) in children.iter() {
grid = grid.child(qwb.build(id, grow as usize, gcol as usize, child_type.clone(), child_qml.clone(), ctx, qmlctx));
grow += 1;
if grow as u32 == rows {
grow = 0;
gcol += 1;
gcol = (gcol + 1) % cols;
}
}
return grid.build(ctx);

View File

@ -8,11 +8,13 @@ use crate::widget_builders::textfield::TextBuilder;
use orbtk::prelude::*;
use orbtk::Entity;
use crate::widget_builders::combobox::ComboBoxBuilder;
use crate::widget_builders::image::ImageBuilder;
use crate::widget_builders::import::ImportBuilder;
use std::collections::HashMap;
pub mod button;
pub mod combobox;
pub mod grid;
pub mod image;
pub mod import;
@ -61,6 +63,7 @@ impl QmlWidgetBuilder {
qwb.widgets.insert(String::from("TextField"), Box::new(TextEditBuilder {}));
qwb.widgets.insert(String::from("Button"), Box::new(ButtonBuilder {}));
qwb.widgets.insert(String::from("Image"), Box::new(ImageBuilder {}));
qwb.widgets.insert(String::from("ComboBox"), Box::new(ComboBoxBuilder {}));
qwb
}