Completed the layout manager that adjusts according to borders and margins