onGetBoxModel method
Implementation
void onGetBoxModel(int? id, Map<String, dynamic> params) {
int nodeId = params['nodeId'];
Element? element = elementManager.getEventTargetByTargetId<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.borderLeft, border[1] + element.renderBoxModel!.renderStyle.borderTop,
border[2] - element.renderBoxModel!.renderStyle.borderRight, border[3] + element.renderBoxModel!.renderStyle.borderTop,
border[4] - element.renderBoxModel!.renderStyle.borderRight, border[5] - element.renderBoxModel!.renderStyle.borderBottom,
border[6] + element.renderBoxModel!.renderStyle.borderLeft, border[7] - element.renderBoxModel!.renderStyle.borderBottom,
];
List<double> content = [
padding[0] + element.renderBoxModel!.renderStyle.paddingLeft, padding[1] + element.renderBoxModel!.renderStyle.paddingTop,
padding[2] - element.renderBoxModel!.renderStyle.paddingRight, padding[3] + element.renderBoxModel!.renderStyle.paddingTop,
padding[4] - element.renderBoxModel!.renderStyle.paddingRight, padding[5] - element.renderBoxModel!.renderStyle.paddingBottom,
padding[6] + element.renderBoxModel!.renderStyle.paddingLeft, padding[7] - element.renderBoxModel!.renderStyle.paddingBottom,
];
List<double> margin = [
border[0] - element.renderBoxModel!.renderStyle.marginLeft.length!, border[1] - element.renderBoxModel!.renderStyle.marginTop.length!,
border[2] + element.renderBoxModel!.renderStyle.marginRight.length!, border[3] - element.renderBoxModel!.renderStyle.marginTop.length!,
border[4] + element.renderBoxModel!.renderStyle.marginRight.length!, border[5] + element.renderBoxModel!.renderStyle.marginBottom.length!,
border[6] - element.renderBoxModel!.renderStyle.marginLeft.length!, border[7] + element.renderBoxModel!.renderStyle.marginBottom.length!,
];
BoxModel boxModel = BoxModel(
content: content,
padding: padding,
border: border,
margin: margin,
width: widthWithinBorder,
height: heightWithinBorder,
);
sendToFrontend(id, JSONEncodableMap({
'model': boxModel,
}));
} else {
sendToFrontend(id, null);
}
}