Updownquark / Quick

Quark's User Interface Creation Kit
0 stars 0 forks source link

Ancestor layout event #40

Closed Updownquark closed 11 years ago

Updownquark commented 11 years ago

From #8 (Label):

This [label] is finished, but there's a problem. For example, when the new toggle button test starts, the value in the model is null, so the label has no text and its size is zero. When one clicks a button, the value in the model changes as does the text in the label, causing the label's preferred size to change; however, no event is fired instructing the main block to do a re-layout, so the label's actual layout size is zero. If the window is resized, the label shows up like it should.

This could of course be worked around by setting the size of the label, but that's a horrible hack. We need an way to signal parents to arbitrary depth that the size of one of their descendants has changed and a layout operation is required.

The ideal solution to this would involve some screening, i.e. no layout operation would be fired if the layout size of the widget were fixed by attributes, layouts would not be done beyond a scroll pane since the size of the widget in the scroll pane will probably have no effect on the size guide of the scroll pane, etc. However, implementing these sounds extremely difficult and like it would involve a lot of hackery. It does deserve some thinking though. The actual solution may end up being simpler. I may need to take a look at what Swing and AWT do.

Updownquark commented 11 years ago

I have solved this in a non-ideal but hopefully good way. When something happens that could potentially affect an element's sizing, a SizeNeedsChangeEvent is fired on the element (only on the element, not up the chain). This event is listened for by the parent element, which handles it thus:

if the current size is within the min-pref to max-pref range
    a new SizeNeedsChanged event is fired on the parent.
    if the event's handled flag is not marked after the event fires
        a relayout operation is queued
        the event is marked as handled (which marks all cause events as handled)
else
    a relayout operation is queued
    the event is marked as handled (which marks all cause events as handled)

Thus, the screen min-pref<=size<=max-pref is used to prevent relayouts at the root level every time anything in the document changes.

Updownquark commented 11 years ago

Reopening this. Although the label in the toggle button test does show up when the first button is selected, the size of the label doesn't appear to change when it needs to. For example, click Red initially and the text says "red". Then click "purple" and the text says "pur\nple" where \n is an actual line break.