shoes/shoes4 — pull request #329 by PragTob (2013-07-10 15:54:56+00:00)
Title: Request for Feedback: Redraw timing

This is a pull request in the works. It is addressing my favorite issue #209 aka when should we redraw. SWT doesn't seem to always help us with this as according to a stackoverflow I posted.

This is my aspect oriented approach. What does this mean? This means I want all the information about when to redraw in **one file**. For now that is `swt/redraw_aspect.rb`. It needs the current app to do the redrawing. Right now the redrawing is just demonstrated with the `Animation` class.

To accomplish this I use the [after_do gem](https://github.com/PragTob/after_do) which I just released for this purpose, but I've been using it for some time. There aren't too many docs yet, as it's so fresh. But it's just ~60 lines and well tested. So what does it allow you to do? You can do the following (at its simplest):

```ruby
Animation.after :eval_block do app.real.redraw end
```

So here we can say after which method calls on which classes the app should be redrawn. This is the first example I implemented, and `simple-animation.rb` works.

This approach could be taken further, because right now it does little other than bringing all the changes into one file. We could also conditionally redraw here, only if it is needed. So not every animate call ever causes a need to redraw. For instance if we just increase a counter there nothing happens. Therefore we could mark an application as _dirty_ just when new elements were added (also through AfterDo e.g. `.after :para do app.dirty end` or something like that. Also we could implement clever solutions concerning nesting etc...

Ultimately I also believe that this approach is DRYer.

**question:** I had to use app.real.redraw for animation, not app.flush - anyone have an idea why?

Also I still gotta figure out how to integrate this in the test easily... for the spec now I just called the register method manually, but there has got to be a better way! :-)

Also this PR is work in progress and also includes the performance improvements for the `clear` method.

**So what do you think of this approach?**

Feedback and everything very much welcome!