Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Dirty widget redraw in new ui code base #664

Open
houqp opened this issue Dec 13, 2012 · 4 comments
Open

Dirty widget redraw in new ui code base #664

houqp opened this issue Dec 13, 2012 · 4 comments

Comments

@houqp
Copy link
Member

houqp commented Dec 13, 2012

I was playing with the menu widget today and found a problem that I have no idea how to solve without changing part of the core ui code.

So menu widget itself is inherited from FocusManager, which listen on arrow key press and flag itself dirty for redraw.

The flag dirty mechanism is implemented as follow: a widget have to first register itself in the UIManager. Then in UIManager:run, UIManager will loop through all the registered widgets and repaint the widget if it is dirty. If a widget is not registered in UIManager, it won't be repainted even though it flags itself dirty.

Now the problem is in order to center a menu in screen, I put a menu widget inside a CenterContainer and register the CenterContainer in UIManager. When an arrow key is pressed, the menu widget will receive it, update the ui and set itself dirty. However, since it is not registered in UIManager (I only registered its parent CenterContainer), it won't get repainted on the screen.

My question is, shouldn't we loop through all the dirty widgets in UIManager:run method and repaint all the dirty widgets even though they are not registered in UIManager? Did I miss anything important?

@hwhw
Copy link
Member

hwhw commented Dec 14, 2012

IIRC, I made this decision in order to do the repainting in the correct
order - last registered widget is painted last. So the window stack is
indeed a stack - painted from bottom to top.

Maybe the repaint logic must go into the widgets, so widgets keep track of
"dirty" child widgets and do repaint them. So top-level items are childs of
the UI manager, and below that each widget can have and do keep track of
their own childs.

@houqp
Copy link
Member Author

houqp commented Dec 14, 2012

I see, painting order is exactly what I missed ;)

If every registered widget keep track of its children, then probably we need to add a reference to its parent in every child? So children can register as dirty in their parent.

@hwhw
Copy link
Member

hwhw commented Dec 15, 2012

That's what I thought of. It might come handy in other places, too.
However, it probably means that we need to add childs via an "add" method,
not just as array elements.

I think I'll do a bit of testing and will report back.

@houqp
Copy link
Member Author

houqp commented Dec 15, 2012

Just two quick thoughts regarding :)

  • we are adding child via new method now, so probably, we can add parent references in that method
  • if all children have parent reference, then I might not need to all parents keep track of "dirty" child. When a child called setDirty, we can set its parent as dirty instead, which will successfully trigger a redraw.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants