CoDriven Advanced UI documentation

Go back

CmTextField

CmTextField

CmTextField is an input text control. You can enter text inside it.

It's extension of TextField control from UI Toolkit.

    CmTextField textField = new CmTextField();

Style CmTextField elements

CmTextField modifiers contains a few elements to style. Each element has its own method in modifiers:

CmTextField.GetModifiersBuilder() will return CmTextFieldModifiers. You will use it to style Background, Label or TextInput of this control

    public class CmTextFieldModifiers : ICmControlModifiers
    {
        public CmTextFieldModifiers Background(CmModifierBackground modifier)
        public CmTextFieldModifiers Label(CmModifierText modifier)
        public CmTextFieldModifiers TextInput(CmModifierText modifier)
    }

When you add CmTextField (which is TextField inside) to your scene and open UI Toolkit Debugger then you will see that TextField as

textfield.png

here is example styling

    public CmTextField InputField(bool enabled, string text, string inputText, string name)
    {
        var textField = new CmTextField(GetScreen(), text, cmUIEventsHandler: GetUIEventsHandler());
        textField.SetName(name);

        textField.SetInputText(inputText);

        textField.SetStyle(GetTheme().InputField);
        return textField;
    }

    // in your theme
    public override CmTextFieldModifiers InputField()
    {
        var modifiers = CmTextField.GetModifiersBuilder();
        modifiers.Label(
            new CmModifierText(CmSelector.DefaultState)
                .Weight(1)
                .TextAlign(CmTextAlign.CENTER)
        );

        // input background inactive
        modifiers.Background(
            new CmModifierBackground(CmSelector.DefaultState)
                .AnimDuration(_animDurSlow)
                .WidthAuto()
        );

        // input text inactive
        modifiers.TextInput(
            new CmModifierText(CmSelector.DefaultState)
                .Weight(1)
                .AnimDuration(_animDurSlow)
                .TextAlign(CmTextAlign.CENTER)
        );

        // background focus
        modifiers.Background(
            new CmModifierBackground(CmSelector.Focus)
                .AnimDuration(_animDurSlow)
                .CopyFrom(DefBorderRadiusAndWidth())
                .BorderColorRGBA(_inputBorderActiveColor)
        );
        return modifiers;
    }

to learn about modifiers for all controls click here

// events - under construction