(rect *sdl.FRect, worldSpace bool, onChoose func(index int), property *Property, options ...string)
| 937 | } |
| 938 | |
| 939 | func NewDropdown(rect *sdl.FRect, worldSpace bool, onChoose func(index int), property *Property, options ...string) *Dropdown { |
| 940 | |
| 941 | dropdown := &Dropdown{ |
| 942 | Choices: []*Button{}, |
| 943 | WorldSpace: worldSpace, |
| 944 | OnChoose: onChoose, |
| 945 | Property: property, |
| 946 | } |
| 947 | |
| 948 | dropdown.LeftButton = NewIconButton(0, 0, &sdl.FRect{48, 320, 32, 32}, globals.GUITexture, false, func() { |
| 949 | dropdown.ChosenIndex-- |
| 950 | if dropdown.ChosenIndex >= len(dropdown.Choices) { |
| 951 | dropdown.ChosenIndex = 0 |
| 952 | } else if dropdown.ChosenIndex < 0 { |
| 953 | dropdown.ChosenIndex = len(dropdown.Choices) - 1 |
| 954 | } |
| 955 | if dropdown.Property != nil { |
| 956 | dropdown.Property.Set(dropdown.Options[dropdown.ChosenIndex]) |
| 957 | } |
| 958 | if dropdown.OnChoose != nil { |
| 959 | dropdown.OnChoose(dropdown.ChosenIndex) |
| 960 | } |
| 961 | }) |
| 962 | |
| 963 | dropdown.LeftButton.Flip = sdl.FLIP_HORIZONTAL |
| 964 | |
| 965 | dropdown.RightButton = NewIconButton(0, 0, &sdl.FRect{48, 320, 32, 32}, globals.GUITexture, false, func() { |
| 966 | dropdown.ChosenIndex++ |
| 967 | if dropdown.ChosenIndex >= len(dropdown.Choices) { |
| 968 | dropdown.ChosenIndex = 0 |
| 969 | } else if dropdown.ChosenIndex < 0 { |
| 970 | dropdown.ChosenIndex = len(dropdown.Choices) - 1 |
| 971 | } |
| 972 | if dropdown.Property != nil { |
| 973 | dropdown.Property.Set(dropdown.Options[dropdown.ChosenIndex]) |
| 974 | } |
| 975 | if dropdown.OnChoose != nil { |
| 976 | dropdown.OnChoose(dropdown.ChosenIndex) |
| 977 | } |
| 978 | }) |
| 979 | |
| 980 | if rect != nil { |
| 981 | rect.X += 32 |
| 982 | rect.W -= 64 |
| 983 | } |
| 984 | |
| 985 | dropdown.Button = NewButton(options[0], rect, nil, worldSpace, func() { |
| 986 | if dropdown.OnOpen != nil { |
| 987 | dropdown.OnOpen() |
| 988 | } |
| 989 | dropdown.Open = !dropdown.Open |
| 990 | }) |
| 991 | |
| 992 | dropdown.Button.BackgroundColor = getThemeColor(GUIMenuColor).Accent() |
| 993 | |
| 994 | dropdown.SetOptions(options...) |
| 995 | |
| 996 | if property != nil { |
no test coverage detected