/// <summary> /// Construct a NumberEntry with the specified template. /// </summary> /// <param name="template"></param> public NumberEntry(NumberEntryTemplate template) : base(template) { MaximumValue = template.MaximumValue; MinimumValue = template.MinimumValue; TrySetField(template.StartingValue.ToString()); }
public override Size CalculateSize() { int width = 2; // for frame if (!string.IsNullOrEmpty(Label)) width += Canvas.TextLength(Label) + 1; width += NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue); width += 3; // for buttons return new Size(width, 3); }
protected internal override void OnSettingUp() { base.OnSettingUp(); if (!string.IsNullOrEmpty(Label)) { _labelRect = new Rectangle(new Point(1, 1), new Point(Label.Length + 1, 1)); _upButtonPos = new Point(Label.Length + 2, 1) + ScreenPosition; } else _upButtonPos = Point.One + ScreenPosition; int fieldWidth = NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue); Size fieldSize = new Size(fieldWidth, 1); _fieldRect = new Rectangle(_upButtonPos.Shift(2, 0), fieldSize); _downButtonPos = _fieldRect.TopRight; _numEntry = new NumberEntry(new NumberEntryTemplate() { HasFrameBorder = false, MinimumValue = this.MinimumValue, MaximumValue = this.MaximumValue, StartingValue = CurrentValue, CommitOnLostFocus = true, ReplaceOnFirstKey = true, TopLeftPos = _fieldRect.TopLeft }); _upButton = new EmitterButton(new EmitterButtonTemplate() { HasFrameBorder = false, Label = ((char) libtcod.TCODSpecialCharacter.ArrowNorthNoTail).ToString(), TopLeftPos = _upButtonPos, StartEmittingDelay = SpinDelay, Speed = SpinSpeed }); _downButton = new EmitterButton(new EmitterButtonTemplate() { HasFrameBorder = false, Label = ((char) libtcod.TCODSpecialCharacter.ArrowSouthNoTail).ToString(), TopLeftPos = _downButtonPos, StartEmittingDelay = SpinDelay, Speed = SpinSpeed }); _upButton.Emit += upButton_Emit; _downButton.Emit += downButton_Emit; _numEntry.EntryChanged += numEntry_EntryChanged; }
protected internal override void OnSettingUp() { base.OnSettingUp(); int fieldWidth = NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue); Size fieldSize = new Size(fieldWidth, 1); if (BarPigment == null) { BarPigment = DetermineMainPigment(); } _valueBar = new VerticalValueBar(new VerticalValueBarTemplate() { TopLeftPos = this.LocalToScreen(new Point(0, 0)), Length = this.Size.Height - 2, MaximumValue = this.MaximumValue, MinimumValue = this.MinimumValue, StartingValue = this.CurrentValue, BarPigment = this.BarPigment, }); _topButton = new EmitterButton(new EmitterButtonTemplate() { HasFrameBorder = false, Label = Char.ToString((char)libtcod.TCODSpecialCharacter.ArrowNorthNoTail), TopLeftPos = this.LocalToScreen(new Point(0, 0)), StartEmittingDelay = SpinDelay, Speed = SpinSpeed }); _bottomButton = new EmitterButton(new EmitterButtonTemplate() { HasFrameBorder = false, Label = Char.ToString((char)libtcod.TCODSpecialCharacter.ArrowSouthNoTail), TopLeftPos = this.LocalToScreen(new Point(0, 0).Shift(0, Size.Height - 1)), StartEmittingDelay = SpinDelay, Speed = SpinSpeed }); _valueBar.MouseMoved += valueBar_MouseMoved; _valueBar.MouseButtonDown += valueBar_MouseButtonDown; _topButton.Emit += topButton_Emit; _bottomButton.Emit += bottomButton_Emit; }
public override Size CalculateSize() { int width = HasFrameBorder ? 2 : 0; int height = HasFrameBorder ? 2 : 0; // frames add 2 if (!string.IsNullOrEmpty(Label)) { width += Canvas.TextLength(Label) + 1; } width += NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue); //width += 3; width = Math.Max(width, MinimumWidth); if (ShowLabel) // we don't have a label; { height++; } return(new Size(width, height)); }
/// <summary> /// Creates the NumberEntry and ValueBar for this slider. /// </summary> protected internal override void OnSettingUp() { base.OnSettingUp(); Point fieldPos; if (HasFrame) { if (!string.IsNullOrEmpty(Label)) { _labelRect = new Rectangle(new Point(1, 1), new Point(Label.Length + 1, 1)); fieldPos = new Point(Label.Length + 2, 1); } else { fieldPos = new Point(1, 1); } } else { if (!string.IsNullOrEmpty(Label)) { _labelRect = new Rectangle(new Point(0, 0), new Point(Label.Length + 1, 1)); fieldPos = new Point(Label.Length + 2, 0); } else { fieldPos = new Point(0, 0); } } int fieldWidth = NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue); Size fieldSize = new Size(fieldWidth, 1); _fieldRect = new Rectangle(fieldPos, fieldSize); if (BarPigment == null) { BarPigment = DetermineMainPigment(); } _numEntry = new NumberEntry(new NumberEntryTemplate() { HasFrameBorder = false, MinimumValue = this.MinimumValue, MaximumValue = this.MaximumValue, StartingValue = CurrentValue, CommitOnLostFocus = true, ReplaceOnFirstKey = true, CanHaveKeyboardFocus = true, TopLeftPos = this.LocalToScreen(_fieldRect.TopLeft) }); int w = 0, h = 0; if (ShowLabel) { h++; } if (HasFrame) { h++; w++; } _valueBar = new ValueBar(new ValueBarTemplate() { TopLeftPos = this.LocalToScreen(new Point(w, h)), Length = this.Size.Width - (HasFrame ? 4 : 2), MaximumValue = this.MaximumValue, MinimumValue = this.MinimumValue, StartingValue = this.CurrentValue, BarPigment = this.BarPigment }); _leftButton = new EmitterButton(new EmitterButtonTemplate() { HasFrameBorder = false, Label = "-", TopLeftPos = this.LocalToScreen(new Point(w, h)), StartEmittingDelay = SpinDelay, Speed = SpinSpeed }); _rightButton = new EmitterButton(new EmitterButtonTemplate() { HasFrameBorder = false, Label = "+", TopLeftPos = this.LocalToScreen(new Point(w, h).Shift(Size.Width - (HasFrame ? 3 : 1), 0)), StartEmittingDelay = SpinDelay, Speed = SpinSpeed }); _numEntry.EntryChanged += numEntry_EntryChanged; _valueBar.MouseMoved += valueBar_MouseMoved; _valueBar.MouseButtonDown += valueBar_MouseButtonDown; _leftButton.Emit += leftButton_Emit; _rightButton.Emit += rightButton_Emit; }