Attribute VB_Name = "Common_Shape"
Option Explicit

' ================= Common Layout Engine (position only) =================

Public Sub AlignIconsByCenter(sheetName As String, anchorAddr As String, _
                          iconArr As Variant, gapPt As Double)
    Dim ws As Worksheet
    Dim anchor As Range
    Dim shp As Shape
    Dim i As Long
    Dim shapeCount As Long
    On Error GoTo ErrHandler
    Set ws = ThisWorkbook.Worksheets(sheetName)
    ' ws exists, continue
    
    Set anchor = ws.Range(anchorAddr)
    shapeCount = UBound(iconArr) - LBound(iconArr) + 1
    
    ' First icon left-aligns to B3 left edge
    Dim curX As Double: curX = anchor.Left
    Dim prevX As Double: prevX = 0
    Dim cy As Double: cy = anchor.Top + anchor.Height / 2
    
    Application.ScreenUpdating = False
    For i = LBound(iconArr) To UBound(iconArr)
        Set shp = ws.Shapes(iconArr(i))
        shp.Placement = xlFreeFloating
        shp.Left = curX
        shp.Top = cy - shp.Height / 2
        If i = LBound(iconArr) Then
            Debug.Print iconArr(i) & ": left=" & curX & ", width=" & shp.Width
        Else
            Debug.Print iconArr(i) & ": left=" & curX & ", gap=" & (curX - prevX) & ", width=" & shp.Width
        End If
        prevX = curX + shp.Width
        curX = curX + shp.Width + gapPt
    Next i
    Application.ScreenUpdating = True
    Exit Sub

ErrHandler:
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "AlignIconsByCenter"
    Application.ScreenUpdating = True
End Sub

' ================= Entry point =================
Sub RunAlignForMySheet()
    AlignIconsByCenter _
        sheetName:=CACHE_M1, _
        anchorAddr:="B3", _
        iconArr:=Array("input", "check", "output", "sort", "filter", "fit", "load"), _
        gapPt:=10
End Sub