Skip to content
Giorgos Michaelides edited this page Jan 18, 2021 · 12 revisions

Control Factory

The control factory can be accessed in a GemGui instance. It is instantiated by using the ControlTarget and the IConfigurationResolver. You can provide your own implementation of IConfigurationResolver if you want to override the default control factory.

See the fluent builder for more configuration possibilities.

IColorPattern

IColorPattern describes how the color is set in the control's Texture2D sprite. When none is specified Pattern.SolidColor is used.

You can specify a pattern upon declaring a control using the static properties in Pattern or by declaring your own pattern

       Pattern.SolidColor(Color color)
       Pattern.Border(Color border, Color filling)
       Pattern.TextViewPattern(Color border, Color filling)

       new Pattern( (sizeX,sizeY) => 
           Enumerable.Range(1,sizeX * sizeY).Select(x=> Color.White).ToArray());

You can also create a Texture2D from an IColorPattern

      gui.GetTexture(int width, int height, IColorPattern pattern)

Button

The button is a plain old button.

           Button Button(int x, int y,
                         int sizeX, int sizeY,
                         Style style,
                         IColorPattern pattern)

TextField

When the TextField is focused, it listens to the keyboard signals and converts them to characters.

 TextField TextField(int x, int y,
                     int sizeX, int sizeY,
                     Color textColor,
                     SpriteFont font,
                     Style style,
                     IHorizontalAlignable horizontalAlignment = null,
                     IVerticalAlignable verticalAlignment = null,
                     IAlignmentTransition alignmentTransition = null,
                     IColorPattern pattern = null,
                     TextAppenderHelper appender = null)

You can provide your own TextAppenderHelper to customise the TextField's behavior

    TextAppenderHelper(KeyboardInputHelper input,
                       char cursor = '_',
                       double cursorFlickInterval = 500.0d,
                       double keyRepeatStartDuration = 0.3d
                       double keyRepeatDuration = 0.003d)

If you want some keys to not be appended, you can intercept the Func<Keys,char,bool> ShouldHandleKey in TextAppenderHelper

This handles all characters except 'a'

  ShouldHandleKey+= (key,convertedChar) => convertedChar!='a';

The TextField has the following events

    event EventHandler<TextFieldEventArgs> OnTextChanged;
    event EventHandler<string> OnTextEntered;

and the following public methods

   void InsertText(string text)
   void RemoveCharacters(int count)

If you wish to add your own key-to-character map, you can use the AddKeyMap(Keys key, string charPair).

If it is two characters, first character is for not holding the shift key, and the second character for holding the shift key.

   Gem.Gui.Input.KeyboarUtils.AddKeyMap(Keys.D1, "1!");

Slider

A Slider is an easy way to select a value within a custom range.

The factory has two methods. One that uses the IColorPattern

    Slider Slider(int x, int y,
                  int sizeX, int sizeY,
                  int sliderSizeX, int sliderSizeY,
                  SliderInfo sliderInfo,
                  IColorPattern background,
                  IColorPattern slider,
                  IColorPattern filling,
                  IColorPattern border,
                  ARenderStyle style);

And one that uses Texture2D

           Slider Slider(int x, int y,
                         int sizeX, int sizeY,
                         int sliderSizeX, int sliderSizeY,
                         SliderInfo sliderInfo,
                         Texture2D backgroundTexture,
                         Texture2D slider,
                         Texture2D filling,
                         Texture2D border,
                         ARenderStyle style)

The SliderInfo specifies the range of the Slider and has the following constructors.

One that uses a number of step

  SliderInfo(float minValue, 
             float maxValue, 
             int stepsUntilFull, 
             float initialPosition)

And one that uses the actual step.

  SliderInfo(float minValue,
             float maxValue, 
             float step, 
             float initialPosition)

The Slider specifies the following event

   event EventHandler<float> OnValueChanging

which is fired every time the Slider's value is changing, and

   event EventHandler<float> OnValueChanged

which is fired when the Slider's value has reached final state.

Also it has the following properties

    Region SliderRegion { get; }
    float SliderValue { get; }

Label

A Label is not aggregated and it is primarily used to render text in an area.

           Label Label(int x, int y,
                       int sizeX, int sizeY,
                       string text,
                       SpriteFont font,
                       Color textColor,
                       IColorPattern pattern,
                       IHorizontalAlignable horizontalAlignment = null,
                       IVerticalAlignable verticalAlignment = null,
                       IAlignmentTransition alignmentTransition = null)

The Label exposes the following property

           bool StretchToText{ get; set;}

which when is set to true, the label's background is stretched to the text's size.

CheckBox

A Checkbox has a true and false state.

You can create a CheckBox either by IColorPattern

                 CheckBox CheckBox(int x, int y,
                                   int sizeX, int sizeY,
                                   IColorPattern backgroundPattern,
                                   int checkboxSizeX, int checkboxSizeY,
                                   IColorPattern checkedPattern,
                                   IColorPattern unCheckedPattern,
                                   ARenderStyle style,
                                   string text,
                                   SpriteFont font) 

or by Texture2D

                 CheckBox CheckBox(int x, int y,
                                   int sizeX, int sizeY,
                                   Texture2D backgroundTexture,
                                   Texture2D checkedTexture,
                                   Texture2D unCheckedTexture,
                                   ARenderStyle style,
                                   string text,
                                   SpriteFont font)

The CheckBox exposes the following properties

    AControl Box { get; }
    bool IsChecked { get; }

with box being the CheckBox square, and the following event

   event EventHandler<bool> CheckChanged

ListView

The ListView is used to group and align controls

           ListView ListView(int x, int y,
                             int sizeX, int sizeY,
                             Orientation orientation,
                             IHorizontalAlignable horizontalAlignment,
                             IVerticalAlignable verticalAlignment,
                             IAlignmentTransition alignmentTransition,
                             IColorPattern pattern = null,
                             params AControl[] controls)
Clone this wiki locally