private string GetBorderWidth(Side pointingDirection, ValueAndUnit heightAndUnit, ValueAndUnit widthAndUnit) { string fullWidth = $"{widthAndUnit.Value}{widthAndUnit.Unit}"; string halfWidth = $"{double.Parse(widthAndUnit.Value) / 2}{widthAndUnit.Unit}"; string fullHeight = $"{heightAndUnit.Value}{heightAndUnit.Unit}"; string halfHeight = $"{double.Parse(heightAndUnit.Value) / 2}{heightAndUnit.Unit}"; switch (pointingDirection) { case Side.Top: return($"0 {halfWidth} {fullHeight} {halfWidth}"); case Side.TopLeft: return($"{fullWidth} {fullHeight} 0 0"); case Side.Left: return($"{halfHeight} {fullWidth} {halfHeight} 0"); case Side.BottomLeft: return($"{fullWidth} 0 0 {fullHeight}"); case Side.Bottom: return($"{fullHeight} {halfWidth} 0 {halfWidth}"); case Side.BottomRight: return($"0 0 {fullWidth} {fullHeight}"); case Side.Right: return($"{halfHeight} 0 {halfHeight} {fullWidth}"); case Side.TopRight: default: return($"0 {fullWidth} {fullHeight} 0"); } }
/// <inheritdoc /> public string Between(string fromSize, string toSize, string minScreen = "320px", string maxScreen = "1200px") { ValueAndUnit fromSizeValueAndUnit = _helpers.GetValueAndUnit(fromSize); ValueAndUnit toSizeValueAndUnit = _helpers.GetValueAndUnit(toSize); ValueAndUnit minScreenValueAndUnit = _helpers.GetValueAndUnit(minScreen); ValueAndUnit maxScreenValueAndUnit = _helpers.GetValueAndUnit(maxScreen); if (!double.TryParse(fromSizeValueAndUnit.Value, out double fromSizeNum) || !double.TryParse(toSizeValueAndUnit.Value, out double toSizeNum) || string.IsNullOrWhiteSpace(fromSizeValueAndUnit.Unit) || string.IsNullOrWhiteSpace(toSizeValueAndUnit.Unit) || fromSizeValueAndUnit.Unit != toSizeValueAndUnit.Unit) { throw PolishedException.GetPolishedException(47); } if (!double.TryParse(minScreenValueAndUnit.Value, out double minScreenNum) || !double.TryParse(maxScreenValueAndUnit.Value, out double maxScreenNum) || string.IsNullOrWhiteSpace(minScreenValueAndUnit.Unit) || string.IsNullOrWhiteSpace(maxScreenValueAndUnit.Unit) || minScreenValueAndUnit.Unit != maxScreenValueAndUnit.Unit) { throw PolishedException.GetPolishedException(48); } double slope = (fromSizeNum - toSizeNum) / (minScreenNum - maxScreenNum); double baseNum = toSizeNum - slope * maxScreenNum; return($"calc({Math.Round(baseNum, 2)}{fromSizeValueAndUnit.Unit} + {Math.Round(100 * slope, 2)}vw)"); }
/// <inheritdoc /> public string Triangle(Side pointingDirection, string height, string width, string foregroundColor, string backgroundColor = "transparent") { ValueAndUnit heightAndUnit = _helpers.GetValueAndUnit(height); ValueAndUnit widthAndUnit = _helpers.GetValueAndUnit(width); if (!double.TryParse(heightAndUnit.Value, out double h) || !double.TryParse(widthAndUnit.Value, out double w)) { throw PolishedException.GetPolishedException(60); } string backgourndColorDefault = !string.IsNullOrWhiteSpace(backgroundColor) ? backgroundColor : "transparent"; StringBuilder sb = new StringBuilder(); sb.Append("width:0;"); sb.Append("height:0;"); sb.Append("border-color:").Append(GetBorderColor(pointingDirection, foregroundColor, backgourndColorDefault)).Append(";"); sb.Append("border-style:solid;"); sb.Append("border-width:").Append(GetBorderWidth(pointingDirection, heightAndUnit, widthAndUnit)).Append(";"); return(sb.ToString()); }