public ButtonToggle(string title, Func <bool> getValueCallback, Action <bool> setValueCallback) : base(title, null) { _valueComponent = new ValueComponent <bool>(getValueCallback, setValueCallback); SetOnClickCallback(() => { Value = !Value; }); Theme.Current.Apply(this, typeof(Button)); }
public RadialSlider(string title, Func <float> getValueCallback, Action <float> setValueCallback, float min = 0, float max = 1, float radius = 25f) : base(radius) { _radius = radius; _min = min; _max = max; _emptySpace = new EmptySpace(_radius * 2, _radius * 2); AddChild(_emptySpace); AddChild(new ValueLabel(title, () => string.Format("{0:0.00}", Value))); _valueComponent = new ValueComponent <float>(getValueCallback, setValueCallback); }
public ColorPicker(string title, Func <Col> getValueCallback = null, Action <Col> setValueCallback = null, float pickerHeight = 100) : base(100) { // Initialize texture here _colorDisplayWidth = 10f; Title = title; _valueComponent = new ValueComponent <Col>(getValueCallback, setValueCallback); _colorDisplayBlock = new EmptySpace(ColorDisplayWidth, pickerHeight); TargetColor = _valueComponent.Value; Init(); // Inititialize texture end... _header = new HeaderWidget(Title); _header.SetToggleCallback(x => { if (!x) { _header.Style.Set <Col>(Styles.BackgroundColor, TargetColor); } else { _header.Style.Set <Col>(Styles.BackgroundColor, HeaderColor); } _pickerLayout.Style.Set(Styles.Hidden, !x); }); // vertical layout _pickerLayout = new VerticalLayout(); var horizontalGrid = new HorizontalLayout(); _colorDisplayBlock = new EmptySpace(ColorDisplayWidth, pickerHeight); _pickerBlock = new TextureWidget(_pickingTexture, InnerWidth - _colorDisplayWidth, pickerHeight); _colorDisplayBlock.Style.Set <Col>(Styles.BackgroundColor, TargetColor); _pickerBlock.Style.Set <Col>(Styles.BackgroundColor, new Col(0, 0, 0, 0)); ColorDisplayWidth = _colorDisplayWidth; horizontalGrid.Attach(_colorDisplayBlock, _pickerBlock); // add slider _hueSlider = new TextureWidget(_hueTexture, InnerWidth, 10); _hueSlider.Style.Set <Col>(Styles.BackgroundColor, Col.red); _pickerLayout.Attach(horizontalGrid, _hueSlider); AddChild(_header); AddChild(_pickerLayout); }
public ImageSampler(Texture texture, float width = 0, float height = 0, Action <Col> setValueCallback = null, Func <Vec2> getSamplerPostionCallback = null, Action <Vec2> setSamplerPostionCallback = null) : base(texture, width, height) { if (getSamplerPostionCallback == null) { getSamplerPostionCallback = () => _pos; } if (setSamplerPostionCallback == null) { setSamplerPostionCallback = x => _pos = x; } _valueComponent = new ValueComponent <Vec2>(getSamplerPostionCallback, setSamplerPostionCallback); _setValueCallback = setValueCallback; }
public VerticalSlider(string title, Func <float> getValueCallback, Action <float> setValueCallback, float min = 0, float max = 1, float width = 12, float height = 50) { _min = min; _max = max; _width = width; _height = height; _valueComponent = new ValueComponent <float>(getValueCallback, setValueCallback); Attach( new HorizontalLayout().Attach( (_placeHolder = new VerticalLayout(_width)).Attach( (_inactiveBar = new EmptySpace(_width, _height)), (_activeBar = new EmptySpace(_width, 0)) ) ), (_valueLabel = new Label(title)) ); Value = getValueCallback(); }
public NumberDialer(string title, Func <float> getValueCallback, Action <float> setValueCallback, float min = -10000, float max = 10000, int precision = 3) : base() { _min = min; _max = max; _valueComponent = new ValueComponent <float>(getValueCallback, setValueCallback); Title = title; // if min < 0 then need +- switch // if max and min < 0 then always - // 1 is for sign int numCount = 1; // sign var rmin = ((int)System.Math.Abs(min)).ToString().Length; var rmax = ((int)System.Math.Abs(max)).ToString().Length; _integerNums = System.Math.Max(rmin, rmax); numCount += _integerNums; numCount++; // . _precision = precision; numCount += _precision; // fractional { _formatString = "{0:"; for (int i = 0; i < _integerNums; i++) { _formatString += '0'; } _formatString += '.'; for (int i = 0; i < _precision; i++) { _formatString += '0'; } _formatString += "}"; } _valueArr = new char[numCount]; _numberLabels = new Label[_valueArr.Length]; var index = 0; foreach (var ch in _valueArr) { var label = new Label(); if (index == 0) { _labelStyle = label.Style; } else { label.SetStyle(_labelStyle); } label .AddEventListener(EventType.MouseDown, () => _currentDraggingLabel = label) .AddEventListener(EventType.Hover, () => _currentHoveredLabel = label); _numberLabels[index++] = label; } // add horizontal layout Attach(new HorizontalLayout() .Attach(new Label(" ").SetStyle(_labelStyle)) .Attach(_numberLabels) .Attach(new Label(" ").SetStyle(_labelStyle)) .Attach( _textLabel = new Label(title) ) ); }