(rect *sdl.FRect, worldSpace bool, property *Property)
| 574 | } |
| 575 | |
| 576 | func NewNumberSpinner(rect *sdl.FRect, worldSpace bool, property *Property) *NumberSpinner { |
| 577 | |
| 578 | spinner := &NumberSpinner{ |
| 579 | Rect: rect, |
| 580 | Visible: true, |
| 581 | Property: property, |
| 582 | MinValue: -math.MaxFloat32, |
| 583 | MaxValue: math.MaxFloat32, |
| 584 | } |
| 585 | |
| 586 | if rect == nil { |
| 587 | spinner.Rect = &sdl.FRect{0, 0, 1, globals.GridSize} |
| 588 | } |
| 589 | |
| 590 | spinner.Label = NewLabel("0", nil, worldSpace, AlignCenter) |
| 591 | |
| 592 | spinner.Label.RegexString = RegexOnlyDigits |
| 593 | spinner.Label.Editable = true |
| 594 | spinner.Label.OnClickOut = func() { |
| 595 | if spinner.Property != nil { |
| 596 | spinner.Property.Set(spinner.EnforceCaps(float64(spinner.Label.TextAsInt()))) |
| 597 | } else { |
| 598 | spinner.Value = spinner.EnforceCaps(float64(spinner.Label.TextAsInt())) |
| 599 | } |
| 600 | if spinner.OnChange != nil { |
| 601 | spinner.OnChange() |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | spinner.Increase = NewIconButton(0, 0, &sdl.FRect{48, 96, 32, 32}, globals.GUITexture, worldSpace, func() { |
| 606 | if spinner.Property != nil { |
| 607 | f := spinner.Property.AsFloat() |
| 608 | spinner.Property.Set(spinner.EnforceCaps(f + 1)) |
| 609 | } else { |
| 610 | spinner.Value = spinner.EnforceCaps(float64(spinner.Value + 1)) |
| 611 | } |
| 612 | if spinner.OnChange != nil { |
| 613 | spinner.OnChange() |
| 614 | } |
| 615 | }) |
| 616 | |
| 617 | spinner.Decrease = NewIconButton(0, 0, &sdl.FRect{80, 96, 32, 32}, globals.GUITexture, worldSpace, func() { |
| 618 | if spinner.Property != nil { |
| 619 | f := spinner.Property.AsFloat() |
| 620 | spinner.Property.Set(spinner.EnforceCaps(f - 1)) |
| 621 | } else { |
| 622 | spinner.Value = spinner.EnforceCaps(float64(spinner.Value - 1)) |
| 623 | } |
| 624 | if spinner.OnChange != nil { |
| 625 | spinner.OnChange() |
| 626 | } |
| 627 | }) |
| 628 | |
| 629 | return spinner |
| 630 | |
| 631 | } |
| 632 | |
| 633 | func (spinner *NumberSpinner) SetLimits(min, max float64) { |
no test coverage detected