selectLayerAt method
根据点击位置选择文本图层
Implementation
String? selectLayerAt(Offset tapPosition, Size canvasSize) {
// 从最上层的图层开始检查(按添加顺序的逆序)
final layersList = _layers.values.toList().reversed;
for (final layer in layersList) {
final bounds = getTextLayerBounds(layer, canvasSize);
// 增加一些触摸范围判定,特别是对于较小的文字
final touchBounds = bounds.inflate(8.0);
if (touchBounds.contains(tapPosition)) {
_selectedLayerId = layer.id;
return layer.id;
}
}
return null;
}