Many GUI controls indicating different states

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

  • Create one control for each cell and let the GUI library handle all events and stuff (on Windows 128 HWND: s)
  • Draw the entire matrix using lower-level graphical primitives.

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

+6
source share
1 answer

Of course there is a difference. I will try to illustrate this, as well as the assumptions on which it is based.

  • Control cost = memory for control + event handlers for control + links to the control + one additional control in the event pipeline

  • The advantage of "hard" control on the display of cells. Conceptually clean, simple code that is easiest to think about.

  • Hard Matching Cost: Multiply management costs by the number of cells.

The alternative that I am going to offer suggests that the important delta between tight matching and free "one ring" display is important.

alternative : just add one control that is registered for events only within the entire matrix representation you have, has a code snippet to determine the position of the pointer and the cell that matches, and then updates only that cell depending on user interaction.

The advantages of this you get the marginal cost of only one additional control, but the advantage of processing interactions for the entire matrix. Marginal benefit or this control is much higher than for one tight control. Aldo, the cost of implementation is low because it is a common model and not too complicated.

Good luck

+3
source

Source: https://habr.com/ru/post/916998/


All Articles