06-22-2009 01:30 PM
In a screen I have 2 managers: 1) menu manager at the top and 2) body manager that has info/button elements. The menu manager does custom drawing so that its menu elements (LabelFields) are properly spaced.
Core Issue - Manager and subfield drawing order
The screen draws fine except when the user preforms an action (clicks a button) that results in an element withing the body manager being added/removed. Once field elements are added/removed from the body, the order in which the menu is drawn gets mixed up.
When the body manager adds or removes a field, instead of the menu manager drawing itself and then its sub elements (label fields), the menu manager begins to draw its sub elements and then itself; thus painting on top of the label fields and making them look like they've disapeared.
Already tried invalidate and other options -- I've tried to call invalidate, invalidateall, updateDisplay... after adding/removing field elements from body. All without success.
Removing custom sublayout works -- The only way that I can resolve this issue is to remove the menu managers custom sublayout logic. Unfortunatly the menu system then draws in a traditional manner and does not provide enough spacing.
Below is the sublayout code for the menu manager, am I missing somethinghere.
public void sublayout(int iWidth, int iHeight)
final int iNumFields = getFieldCount();
int maxHeight = 0;
final int segmentWidth = iWidth / iNumFields;
final int segmentWidthHalf = segmentWidth / 2;
for (int i = 0; i < iNumFields; i++)
final Item currentField = (Item)this.getField(i);
// 1. Use index to compute bounds of the field
final int xSegmentTrueCenter = segmentWidth * i + segmentWidthHalf;
// 2. center field inbetween bounds using field width (find fill width of text)
final int xFieldStart = xSegmentTrueCenter - currentField.getFont().getAdvance(currentField.get
// set up position
setPositionChild(currentField, xFieldStart, getContentTop() + MenuAbstract.PADDING_VERTICAL);
// allow child to draw itself
layoutChild(currentField, iWidth, currentField.getHeight());
// compute max height of the field
//int fieldheight = currentField.getHeight();
maxHeight = currentField.getHeight() > maxHeight
? currentField.getHeight() + 2 * MenuAbstract.PADDING_VERTICAL
As you can see above, I'm just making sure each menu element looks as if it was drawn horizontally with even spacing between all elements.
Ultimately I want to keep the custom layout of the menu manager while being allowed to redraw field elements. Here are my final questions:
1. Have you experienced this before?
2. Why would the menu manager begin drawing in the wrong order when a field element is added/remove to the screen?
3. Does the native Manager.sublayout() do something that I'm not to maintain drawing order?
06-22-2009 01:42 PM
I don't really understand your post, but here is one suggestion. When you change fields and/or their positions, you should call relayout to adjust the positions of the fields (they are not updated automatically...layout is only called when the manager is being created). If the issue you are speaking of is the new fields are drawing over the old fields and leaving spaces, etc, then this may be your issue. Also, if you are creating all or your fields up front, you can try using the replace method to switch fields in and out of the manager.
06-22-2009 01:54 PM
>I don't really understand your post, but here is one suggestion
The scenario is this
1. screen has two manager one that acts as a menu and one that acts as the body (has inputs and all that)
2. User interacts with an element in the body manager that causes a field to get removed from the body manager.
3. Now the entire screen redraws, when this happens, rather than the menu manager drawing itself (background color and all that jazz) and
then its hosted field elements, it instead draws the hosted field elements and then itself.
>layout is only called when the manager is being created
Correct, but the reason why I mention sublayout is because when I DO NOT implement a custom drawing layout, the menu manager and its field elements draw in the correct order.
>you should call relayout
I can't find a relayout mentod, I've arleady tried invalidatelayout, updatedisplay and forcing sublayout to be drawn again.
06-22-2009 03:02 PM
you need to call updateLayout()on the field thats going away. that flags the managers to relayout.
also, since your issues are with painting, are you overriding paint/subpaint in your menu manager? if so posting that code would be helpful to diagnose the issue.