Inserting controls

In order to extend the set of basic control-generating actions, Linquid provides a special action UIM.Insert with the following signature:

UI<Source<C>> Insert<B, C>(
        Func<Font, B> getControl, 
        Func<B, Source<C>> getSource, 
        float xStretch, 
        float yStretch)
getControl is a function that creates a control given the font it will have when layout is executed. Size of the returned control is assumed to be its minimal size.
getSource determines what will be the result of the generated action (source types in UI<Source<C>> and Func<B, Source<C>> refer to the same value).
xStretch and yStretch set the stretching priorities used for layout.

To illustrate it, here is an example, that creates an UI action for generating a multiline TextBox:

var ui =
UIM.Insert(
        font => new TextBox()
        {
             Multiline = true,
             Font = font,
             ScrollBars = ScrollBars.Vertical,
             Width = 300,
             Height = 300
        },
        textBox => textBox.TextSource(),
        1.0f, 1.0f);
TextSource is an extension method placed in Linquid.Controls namespace along with other methods generating sources of common controls' properties. Alternatively, sources can be created explicitly like this:

var source = new Source<string>(textBox.Text);
textBox.TextChanged += delegate {source.SetValue(textBox.Text);};
Sources also have parameterless constructor. It creates a source that doesn't hold any value, so any sources created by applying transformations to it will also be empty, until SetValue is called on the root source.

Last edited Dec 5, 2008 at 9:43 PM by Yuuki, version 3

Comments

No comments yet.