onGetBoxModel method
Implementation
void onGetBoxModel(int? id, Map<String, dynamic> params) {
int nodeId = params['nodeId'];
Element? element = document.controller.view.getEventTargetById<Element>(nodeId);
// BoxModel design to BorderBox in kraken.
if (element != null && element.renderBoxModel != null && element.renderBoxModel!.hasSize) {
ui.Offset contentBoxOffset = element.renderBoxModel!.localToGlobal(ui.Offset.zero);
int widthWithinBorder = element.renderBoxModel!.size.width.toInt();
int heightWithinBorder = element.renderBoxModel!.size.height.toInt();
List<double> border = [
contentBoxOffset.dx, contentBoxOffset.dy,
contentBoxOffset.dx + widthWithinBorder, contentBoxOffset.dy,
contentBoxOffset.dx + widthWithinBorder, contentBoxOffset.dy + heightWithinBorder,
contentBoxOffset.dx, contentBoxOffset.dy + heightWithinBorder,
];
List<double> padding = [
border[0] + (element.renderBoxModel!.renderStyle.borderLeftWidth?.computedValue ?? 0), border[1] + (element.renderBoxModel!.renderStyle.borderTopWidth?.computedValue ?? 0),
border[2] - (element.renderBoxModel!.renderStyle.borderRightWidth?.computedValue ?? 0), border[3] + (element.renderBoxModel!.renderStyle.borderTopWidth?.computedValue ?? 0),
border[4] - (element.renderBoxModel!.renderStyle.borderRightWidth?.computedValue ?? 0), border[5] - (element.renderBoxModel!.renderStyle.borderBottomWidth?.computedValue ?? 0),
border[6] + (element.renderBoxModel!.renderStyle.borderLeftWidth?.computedValue ?? 0), border[7] - (element.renderBoxModel!.renderStyle.borderBottomWidth?.computedValue ?? 0),
];
List<double> content = [
padding[0] + element.renderBoxModel!.renderStyle.paddingLeft.computedValue, padding[1] + element.renderBoxModel!.renderStyle.paddingTop.computedValue,
padding[2] - element.renderBoxModel!.renderStyle.paddingRight.computedValue, padding[3] + element.renderBoxModel!.renderStyle.paddingTop.computedValue,
padding[4] - element.renderBoxModel!.renderStyle.paddingRight.computedValue, padding[5] - element.renderBoxModel!.renderStyle.paddingBottom.computedValue,
padding[6] + element.renderBoxModel!.renderStyle.paddingLeft.computedValue, padding[7] - element.renderBoxModel!.renderStyle.paddingBottom.computedValue,
];
List<double> margin = [
border[0] - element.renderBoxModel!.renderStyle.marginLeft.computedValue, border[1] - element.renderBoxModel!.renderStyle.marginTop.computedValue,
border[2] + element.renderBoxModel!.renderStyle.marginRight.computedValue, border[3] - element.renderBoxModel!.renderStyle.marginTop.computedValue,
border[4] + element.renderBoxModel!.renderStyle.marginRight.computedValue, border[5] + element.renderBoxModel!.renderStyle.marginBottom.computedValue,
border[6] - element.renderBoxModel!.renderStyle.marginLeft.computedValue, border[7] + element.renderBoxModel!.renderStyle.marginBottom.computedValue,
];
BoxModel boxModel = BoxModel(
content: content,
padding: padding,
border: border,
margin: margin,
width: widthWithinBorder,
height: heightWithinBorder,
);
sendToFrontend(id, JSONEncodableMap({
'model': boxModel,
}));
} else {
sendToFrontend(id, null);
}
}