diff options
author | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-18 01:04:05 +0300 |
---|---|---|
committer | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-18 01:04:05 +0300 |
commit | ab5baa1c9a028ec7de143b69f92aa356173103e3 (patch) | |
tree | 1655530d608afe1d8e7d378c1b4743f43d2850d4 | |
parent | d055f35514ea0c3dd0f4f9eb63a34c3014b95a77 (diff) |
added limits on number of custom actions and temperature presets that are added
-rwxr-xr-x | ui/ControlPanel.go | 22 | ||||
-rwxr-xr-x | ui/TemperaturePresetsPanel.go | 17 |
2 files changed, 26 insertions, 13 deletions
diff --git a/ui/ControlPanel.go b/ui/ControlPanel.go index b53e0f6..2bea460 100755 --- a/ui/ControlPanel.go +++ b/ui/ControlPanel.go @@ -37,20 +37,32 @@ func ControlPanel( func (this *controlPanel) initialize() { defer this.Initialize() - for _, controlDefinition := range this.getDefaultControls() { + defaultControls := this.getDefaultControls() + for _, controlDefinition := range defaultControls { icon := strings.ToLower(strings.Replace(controlDefinition.Name, " ", "-", -1)) button := uiWidgets.CreateControlButton(this.UI.Client, this.UI.window, controlDefinition, icon) this.AddButton(button) } + + // 12 (max) - Back button = 11 available slots to display. + const maxSlots = 11 + currentButtonCount := len(defaultControls) + for _, controlDefinition := range this.getCustomControls() { - button := uiWidgets.CreateControlButton(this.UI.Client, this.UI.window, controlDefinition, "custom-script") - this.AddButton(button) + if currentButtonCount < maxSlots { + button := uiWidgets.CreateControlButton(this.UI.Client, this.UI.window, controlDefinition, "custom-script") + this.AddButton(button) + currentButtonCount++ + } } for _, commandDefinition := range this.getCommands() { - button := uiWidgets.CreateCommandButton(this.UI.Client, this.UI.window, commandDefinition, "custom-script") - this.AddButton(button) + if currentButtonCount < maxSlots { + button := uiWidgets.CreateCommandButton(this.UI.Client, this.UI.window, commandDefinition, "custom-script") + this.AddButton(button) + currentButtonCount++ + } } } diff --git a/ui/TemperaturePresetsPanel.go b/ui/TemperaturePresetsPanel.go index 2045bed..98489f6 100755 --- a/ui/TemperaturePresetsPanel.go +++ b/ui/TemperaturePresetsPanel.go @@ -37,9 +37,15 @@ func TemperaturePresetsPanel( func (this *temperaturePresetsPanel) initialize() { defer this.Initialize() + this.createAllOffButton() this.createTemperaturePresetButtons() } +func (this *temperaturePresetsPanel) createAllOffButton() { + allOffButton := uiWidgets.CreateCoolDownButton(this.UI.Client, this.UI.GoToPreviousPanel) + this.AddButton(allOffButton) +} + func (this *temperaturePresetsPanel) createTemperaturePresetButtons() { settings, err := (&octoprintApis.SettingsRequest{}).Do(this.UI.Client) if err != nil { @@ -47,11 +53,12 @@ func (this *temperaturePresetsPanel) createTemperaturePresetButtons() { return } - this.createAllOffButton() + // 12 (max) - Back button - All Off button = 10 available slots to display. + const maxSlots = 10 count := 0 for _, temperaturePreset := range settings.Temperature.TemperaturePresets { - if count < 10 { + if count < maxSlots { temperaturePresetButton := uiWidgets.CreateTemperaturePresetButton( this.UI.Client, this.selectHotendStepButton, @@ -63,10 +70,4 @@ func (this *temperaturePresetsPanel) createTemperaturePresetButtons() { count++ } } - -} - -func (this *temperaturePresetsPanel) createAllOffButton() { - allOffButton := uiWidgets.CreateCoolDownButton(this.UI.Client, this.UI.GoToPreviousPanel) - this.AddButton(allOffButton) } |