grid based dynamic ui drawing function