kas-gui / kas

Another GUI toolkit
Apache License 2.0
892 stars 27 forks source link

Widget status tracker and method shims #408

Closed dhardy closed 10 months ago

dhardy commented 10 months ago

The widget API makes some requirements of the call order of methods.

Should we add a tracker to enforce this (in debug builds)?

Rules

Rules (x: y → z means that after x changes/happens, y must happen before z):

Failure to respect these rules can cause issues, e.g. invalid WidgetId (due to something before configure) or out-of-range in MatrixView due to set_rect then draw before the requested re-configure.

Proposal

Add an enum like:

pub enum WidgetStatus {
    New,
    Configured,
    SizeRulesX,
    SizeRulesY,
    SetRect,
}

(Note: this omits "data change" since the widget cannot reliably detect this.)

Add a status: WidgetStatus field to widget_core!() (in debug builds).

Add shims around all relevant widget methods which test and update this status. Problem: we need a solution to #407.