Как решить проблему с гридом?

Ребят, такая проблема. Грид не хочет работать нормально

При открытий другой вкладки а потом возвращений обратно всё нормально

Код вкладки

  local PANEL = {}
  
  function PANEL:Init()
      self:DockPadding(8,8,8,8)
      self.layout = self:Add("ThreeGrid")
      self.layout:Dock(FILL)
      self.layout:DockMargin(4,4,4,4)
      self.layout:SetColumns(3)
      self.layout:SetHorizontalMargin(3)
      self.layout:SetVerticalMargin(4)
      self.scrollbar = self.layout:GetVBar()
      
      self.layout:InvalidateParent(true )
      self:InvalidateLayout(true)
      self.scrollbar:SetHideButtons(true)
  
  end
  
  function PANEL:AddLightAlco(cat, index, value)
      local panel = self.layout:Add("DPanel")
      panel:SetTall(235)
  
      panel.BuyButton = panel:Add(DButton)
      
  
      panel.BuyButton:AlignLeft(8 / 2 * 2)    
      panel.BuyButton:AlignBottom(25)
      panel.BuyButton:SetText("Buy " .. DarkRP.formatMoney(value.price))
      panel.BuyButton:SetFont("Panton.Light")
      function panel.BuyButton.Paint(btn, w, h)
          draw.RoundedBoxEx(6, 0, 0, w, h, Color(24,24,24), true, true, true, true)
      end
  
      panel.BuyButton.DoClick = function(pnl)
          local itemId = index
  
          net.Start("Light.Purchasing")
              net.WriteUInt(cat, 8)
              net.WriteUInt(itemId, 16)
          net.SendToServer()
  
      end
  
      panel.PerformLayout = function(pnl, w, h)
  
          panel.BuyButton:SizeToContentsX(24)
          panel.BuyButton:SizeToContentsY(18)
          
      end
  
      panel.model = panel:Add("DModelPanel")
      panel.model:Dock(TOP)
      panel.model:SetTall(100)
  
      panel.model:SetMouseInputEnabled(false)
      panel.model.LayoutEntity = function() end
  
      local oldPaint = baseclass.Get("DModelPanel").Paint
  
      panel.model.Paint = function(pnl, w, h)
          draw.RoundedBoxEx(3, 0, 0, w, h, Color(22, 22, 22, 194), true, true, false, false)
  
          oldPaint(pnl, w, h)
      end
  
      panel.model:SetModel(value.mdl)
      local mn, mx = panel.model.Entity:GetRenderBounds()
      local size = 0
      size = math.max(size, math.abs(mn.x) + math.abs(mx.x))
      size = math.max(size, math.abs(mn.y) + math.abs(mx.y))
      size = math.max(size, math.abs(mn.z) + math.abs(mx.z))
      panel.model:SetFOV(55)
      panel.model:SetCamPos(Vector(
        size + 65,
        size - 0,
        size + 15
        )
      )
  
      panel.model:SetLookAt((mn + mx) * 0.5)
  
      function panel.Paint(pnl, w, h)
  
          draw.RoundedBoxEx(3, 0, 0, w, h, Color(43,43,43), true, true, true, true)
  
          local x = pnl.model:GetWide() - 150
          local y = h / 1.6 - draw.GetFontHeight("Panton.Light") / 2
  
          draw.SimpleText(value.name, "Panton.Light", x, y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  
      end
  
      self.layout:AddCell(panel)
      self:InvalidateLayout(true)
      self.layout:InvalidateParent(true )
      
  
  end
  
  function PANEL:SetData(tbl)
  
      self.layout:Clear()
      local index = tbl.index
      
      for i, v in pairs(tbl.alcohols) do
          self:AddLightAlco(index, i, v )
      end
  end
  
  vgui.Register("Bartender.LA.Category", PANEL)

Код грида из гитхаба

local PANEL = {}

AccessorFunc(PANEL, "horizontalMargin", "HorizontalMargin", FORCE_NUMBER)
AccessorFunc(PANEL, "verticalMargin", "VerticalMargin", FORCE_NUMBER)
AccessorFunc(PANEL, "columns", "Columns", FORCE_NUMBER)

function PANEL:Init()
    self:SetHorizontalMargin(0)
    self:SetVerticalMargin(0)

    self.Rows = {}
    self.Cells = {}
end
function PANEL:AddCell(pnl)
    local cols = self:GetColumns()
    local idx = math.floor(#self.Cells/cols)+1
    local margin = self:GetHorizontalMargin()
    pnl:SetWide((self:GetWide()-margin*(cols-1))/cols - 8)

    self.Rows[idx] = self.Rows[idx] || self:CreateRow()

    
    pnl:SetParent(self.Rows[idx])
    pnl:Dock(LEFT)
    pnl:DockMargin(0, 0, #self.Rows[idx].Items+1 < cols && self:GetHorizontalMargin() || 0, 0)
    table.insert(self.Rows[idx].Items, pnl)
    table.insert(self.Cells, pnl)
    self:CalculateRowHeight(self.Rows[idx])
end

function PANEL:CreateRow()
    local row = self:Add("DPanel")
    
    row:Dock(TOP)
    row:DockMargin(0, 0, 0, self:GetVerticalMargin())
    row.Paint = nil
    row.Items = {}
    return row
end

function PANEL:CalculateRowHeight(row)
    local height = 0

    for k, v in pairs(row.Items) do
        height = math.max(height, v:GetTall())
    end

    row:SetTall(height)
end

function PANEL:Skip()
    local cell = vgui.Create("DPanel")
    cell.Paint = nil
    self:AddCell(cell)
end

function PANEL:Clear()
    for _, row in pairs(self.Rows) do
        for _, cell in pairs(row.Items) do
            cell:Remove()
        end
        row:Remove()
    end

    self.Cells, self.Rows = {}, {}
end

PANEL.OnRemove = PANEL.Clear

vgui.Register("ThreeGrid", PANEL, "DScrollPanel")

Делать вот так

self.layout:SetWide(920)

Я не буду

Да оно будет работать, но меню вкладок если будет шире то панельки будут выезжать за рамки фрейма

Вот пример что будет

Любые идей, буду очень признателен!