Skip to content

INTERNALS: KalGridView and KalMonthView

klazuka edited this page Sep 13, 2010 · 1 revision

Purpose

KalGridView manages the square grid portion of KalView. Its primary responsibility is to coordinate the slide animation when the user switches between months. KalGridView’s secondary responsibility is to respond to incoming touch events. The only thing that KalGridView draws is the subtle gray gradient background. The actual rendering of each day in the grid is handled by KalMonthView and KalTileView.

KalMonthView has a KalTileView subview for each visible date in the currently selected month. KalMonthView’s primary responsibility is to act as a container of KalTileViews and to draw the gridlines between each tile.

KalTileView is responsible for drawing the day number, the marker dot and, if selected, a highlight gradient.

Double-buffering

KalGridView double-buffers the views that represent the grid of tiles (KalMonthView). When the calendar is created, KalGridView allocates 2 KalMonthView objects, each with 42 KalTileView subviews. These 2 KalMonthView objects are referenced by KalMonthView’s "frontMonthView” and “backMonthView” pointers. The frontMonthView pointer always points at the view that is being displayed on-screen. The backMonthView pointer always points at the object that will slide into view the next time that the user switches between months.

By taking the double-buffered approach, we avoid making costly dynamic allocations when the user switches between months since the KalMonthViews and KalTileViews are reused each time we “flip the buffers.”