2020-07-06 03:45:09 +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-06 03:45:09 +00:00
|
|
|
use orbtk::prelude::HashMap;
|
|
|
|
use orbtk::prelude::*;
|
2020-08-14 22:57:31 +00:00
|
|
|
|
2020-07-06 03:45:09 +00:00
|
|
|
|
|
|
|
pub struct ImageBuilder {}
|
|
|
|
|
|
|
|
impl WidgetBuilder for ImageBuilder {
|
|
|
|
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 image = ImageWidget::new();
|
|
|
|
image = image.attach(Grid::row(row as usize));
|
|
|
|
image = image.attach(Grid::column(col as usize));
|
|
|
|
|
|
|
|
let widget_id = match properties.get("id") {
|
|
|
|
Some(QmlIdent(text)) => {
|
|
|
|
image = image.id(text.clone());
|
|
|
|
qmlctx.indexes.push(text.clone());
|
|
|
|
text.clone()
|
|
|
|
}
|
2020-07-06 03:45:19 +00:00
|
|
|
_ => String::new(),
|
2020-07-06 03:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let src = match properties.get("source") {
|
|
|
|
Some(QmlString(src)) => src.clone(),
|
|
|
|
_ => String::new(),
|
|
|
|
};
|
|
|
|
image = image.image(src);
|
|
|
|
match properties.get("anchors.centerIn") {
|
|
|
|
Some(QmlIdent(str)) => {
|
|
|
|
if str.eq("parent") {
|
|
|
|
image = image.v_align(Alignment::Center);
|
|
|
|
image = image.h_align(Alignment::Center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
return image.build(ctx);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|