Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A lot of GUI controls indicating different states

This question is very open and probably, the answer to this question will depend on the system, but say in average which is the best way to show a large matrix (say 128 elements) of different states?

  • Create one control for each cell and let GUI library deal with all events and stuff (In Windows 128 HWND:s)
  • Draw the entire matrix by using lower-level graphics primitives

Is there a difference in memory/CPU performance depending on choice? The number of states in my application is 4 for each cell so they need 2 bits each to represent their state. Each cell will be represented by an image related to the state.

like image 811
user877329 Avatar asked May 30 '12 11:05

user877329


1 Answers

Sure there is a difference. I will try to illustrate this and also the assumptions this is based on.

  1. Cost of a control = memory for control + event handlers for control + references to control + one extra control in event pipeline

  2. Benefit of "tight" control per cell mapping. Conceptually clean, simple code, easiest to think about.

  3. Cost of tight mapping : multiply the cost per control by the number of cells.

The alternative I'm about to suggest assumes that the cost delta between tight mapping and a loose "one ring" mapping is important.

alternative : just add one control that is registered for events only within the bounds of the whole matrix view you present, has a piece of code to determine the pointer position and what cell that corresponds to, and then updates only that cell depending on the user interaction there.

The advantages of this are you get the marginal cost of only one extra control but the benefit of handling interactions for the entire matrix. The marginal benefit or this control is much higher than for a single tight control. Aldo, the implementation cost is small as it is a common pattern and not too difficult.

Good luck!

like image 126
Cris Stringfellow Avatar answered Oct 04 '22 02:10

Cris Stringfellow