parseProperties method

void parseProperties([
  1. Media? targetMedia
])

Implementation

void parseProperties([Media? targetMedia]) {
  final m = targetMedia ?? media;
  if (m == null) return;
  isPositioned = true;
  id = m.id;
  String? backgroundVal;
  String? boundsVal;
  String? leftVal;
  String? topVal;
  String? widthVal;
  String? heightVal;
  String? zIndexVal;
  for (var prop in m.getProperties()) {
    if (prop.name == 'background') {
      backgroundVal = prop.value;
    } else if (prop.name == 'bounds') {
      boundsVal = prop.value;
    } else if (prop.name == 'left') {
      leftVal = prop.value;
    } else if (prop.name == 'top') {
      topVal = prop.value;
    } else if (prop.name == 'width') {
      widthVal = prop.value;
    } else if (prop.name == 'height') {
      heightVal = prop.value;
    } else if (prop.name == 'zIndex' || prop.name == 'zOrder') {
      zIndexVal = prop.value;
    } else if (prop.name == 'soundLevel') {
      final slStr = prop.value?.trim() ?? '';
      if (slStr.endsWith('%')) {
        final pct = double.tryParse(slStr.substring(0, slStr.length - 1));
        if (pct != null) soundLevel = (pct / 100.0).clamp(0.0, 1.0);
      } else {
        final val = double.tryParse(slStr);
        if (val != null) {
          soundLevel = val.clamp(0.0, 1.0);
        }
      }
    }
  }

  if (boundsVal != null) {
    final boundsParts = boundsVal.split(',');
    if (boundsParts.length == 4) {
      leftStr = boundsParts[0].trim();
      topStr = boundsParts[1].trim();
      widthStr = boundsParts[2].trim();
      heightStr = boundsParts[3].trim();
    }
  } else {
    leftStr = m.rawAttributes['resolvedLeft'] ?? '0%';
    topStr = m.rawAttributes['resolvedTop'] ?? '0%';
    widthStr = m.rawAttributes['resolvedWidth'] ?? '100%';
    heightStr = m.rawAttributes['resolvedHeight'] ?? '100%';
  }
  if (leftVal != null) leftStr = leftVal;
  if (topVal != null) topStr = topVal;
  if (widthVal != null) widthStr = widthVal;
  if (heightVal != null) heightStr = heightVal;
  if (zIndexVal != null) {
    zindex = int.tryParse(zIndexVal) ?? 0;
  } else if (m.rawAttributes.containsKey('resolvedZIndex')) {
    zindex = int.tryParse(m.rawAttributes['resolvedZIndex']!) ?? 0;
  } else {
    zindex = 0;
  }
  final visibleStr = m.rawAttributes['visible'] ?? 'true';
  visible = visibleStr.toLowerCase() == 'true';
  background = _parseColor(backgroundVal);
  focusBorderColor = _parseColor(m.rawAttributes['focusBorderColor']);
  selBorderColor = _parseColor(m.rawAttributes['selBorderColor']);
}