共用方式為


Twilight of the High-level UI Toolkit

I was reading Tim Sweeney’s write up on how fixed function GPUs and the APIs that depend on them are quickly becoming obsolete. Basically, as GPUs move toward programmable “shaders,” graphic engine writers can easily whip up their own efficient graphic functions. We are already seeing this in new graphics APIs: mobile-oriented OpenGL ES is basically a shader-mostly version of OpenGL sans most of the fixed-function features.

There is an analog with this move in how I program WPF: with retained graphics and convenient access to data binding functionality through signals, I mostly find myself avoiding all the high-level widgets in WPF like StackPanels and Grids because using low-level Canvas is (a) easy and (b) incredibly flexible. For example, consider a grids: WPF has Grid class of course, but with data binding it is rather trivial to get cells to align with whatever row and column abstractions you want to define. This means you can have grids whose columns expand and collapse, scroll bars that move per-row and column, arbitrary highlights, and so on…you no longer have to be limited to Grid functionality. Example from a prototype I’m working on:

image

The little + signs represent rows that can be expanded:

image

We can also layout row headers vertically if we want. All of this is built on low-level widget, mostly Canvas, Border, Button and Scrollbar, connected together through data binding. Its not even much more code than configuring a Grid would have required.

So I have a prediction to make: high-level UI toolkits (much of WPF, Swing) will become unpopular within 5 years. They will instead be replaced in popularity by low-level UI toolkits (Java2D/JavaFX, much of WPF) with high-level abstractions (data binding, signals). WPF can already be used like this, and it is very liberating.