rqml/src/widget_builders/textedit.rs

56 lines
1.8 KiB
Rust
Raw Permalink Normal View History

2020-07-05 21:29:44 +00:00
use crate::parser::Value::{QmlIdent, QmlString};
use crate::parser::{Value, QML};
use crate::state;
2020-07-06 03:45:19 +00:00
use crate::widget_builders::{QmlContext, WidgetBuilder};
2020-07-05 21:29:44 +00:00
use orbtk::prelude::HashMap;
use orbtk::prelude::*;
2020-08-14 22:57:31 +00:00
2020-07-05 21:29:44 +00:00
pub struct TextEditBuilder {}
impl WidgetBuilder for TextEditBuilder {
2020-07-06 03:45:09 +00:00
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 {
2020-07-05 21:29:44 +00:00
let text = match properties.get("text") {
Some(QmlString(text)) => text.clone(),
_ => String::new(),
};
let mut tt = TextBox::new();
tt = tt.text(text);
tt = tt.attach(Grid::row(row as usize));
tt = tt.attach(Grid::column(col as usize));
tt = tt.enabled(true);
match properties.get("id") {
Some(QmlIdent(text)) => {
tt = tt.id(text.clone());
2020-07-06 03:45:09 +00:00
qmlctx.indexes.push(text.clone())
2020-07-05 21:29:44 +00:00
}
_ => {}
};
let code = match properties.get("onchange").unwrap() {
QmlString(code) => code.clone(),
_ => String::new(),
};
2020-08-14 22:57:31 +00:00
tt = tt.on_changed(move |states, _entity: Entity,_| {
2020-07-05 21:29:44 +00:00
state(id, states).action(code.clone());
});
match properties.get("anchors.centerIn") {
Some(QmlIdent(str)) => {
if str.eq("parent") {
tt = tt.v_align(Alignment::Center);
tt = tt.h_align(Alignment::Center);
}
}
_ => {}
}
let entity = tt.build(ctx);
return entity;
});
}
}