private GuiWidget GetPopupContent(ThemeConfig menuTheme) { var widget = new IgnoredPopupWidget() { Width = 300, HAnchor = HAnchor.Absolute, VAnchor = VAnchor.Fit, Padding = new BorderDouble(12, 0), BackgroundColor = menuTheme.BackgroundColor }; var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit | VAnchor.Top, }; widget.AddChild(container); GuiWidget hotendRow; container.AddChild(hotendRow = new SettingsItem( "Heated Bed".Localize(), menuTheme, new SettingsItem.ToggleSwitchConfig() { Checked = false, ToggleAction = (itemChecked) => { var goalTemp = itemChecked ? printer.Settings.GetValue <double>(SettingsKey.bed_temperature) : 0; if (itemChecked) { SetTargetTemperature(goalTemp); } else { SetTargetTemperature(0); } } }, enforceGutter: false)); var toggleWidget = hotendRow.Children.Where(o => o is ICheckbox).FirstOrDefault(); toggleWidget.Name = "Toggle Heater"; heatToggle = toggleWidget as ICheckbox; int tabIndex = 0; var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All); var settingsData = PrinterSettings.SettingsData[SettingsKey.bed_temperature]; var temperatureRow = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields); container.AddChild(temperatureRow); // Add the temperature row to the always enabled list ensuring the field can be set when disconnected alwaysEnabled.Add(temperatureRow); // add in the temp graph var graph = new DataViewGraph() { DynamicallyScaleRange = false, MinValue = 0, ShowGoal = true, GoalColor = menuTheme.PrimaryAccentColor, GoalValue = printer.Settings.GetValue <double>(SettingsKey.bed_temperature), MaxValue = 150, // could come from some profile value in the future Width = widget.Width - 20, Height = 35, // this works better if it is a common multiple of the Width Margin = new BorderDouble(0, 5, 0, 0), }; runningInterval = UiThread.SetInterval(() => { graph.AddData(this.ActualTemperature); }, 1); var settingsRow = temperatureRow.DescendantsAndSelf <SliceSettingsRow>().FirstOrDefault(); void Printer_SettingChanged(object s, StringEventArgs stringEvent) { if (stringEvent != null) { string settingsKey = stringEvent.Data; if (this.allUiFields.TryGetValue(settingsKey, out UIField uifield)) { string currentValue = settingsContext.GetValue(settingsKey); if (uifield.Value != currentValue) { uifield.SetValue( currentValue, userInitiated: false); } } if (stringEvent.Data == SettingsKey.bed_temperature) { var temp = printer.Settings.GetValue <double>(SettingsKey.bed_temperature); graph.GoalValue = temp; // TODO: Why is this only when enabled? How does it get set to if (heatToggle.Checked) { // TODO: Why is a UI widget who is listening to model events driving this behavior? What when it's not loaded? SetTargetTemperature(temp); } settingsRow.UpdateStyle(); } } } printer.Settings.SettingChanged += Printer_SettingChanged; printer.Disposed += (s, e) => printer.Settings.SettingChanged -= Printer_SettingChanged; container.AddChild(graph); return(widget); }
private GuiWidget GetPopupContent(ThemeConfig theme) { var widget = new IgnoredPopupWidget() { Width = 300, HAnchor = HAnchor.Absolute, VAnchor = VAnchor.Fit, BackgroundColor = theme.Colors.PrimaryBackgroundColor, Padding = new BorderDouble(12, 0) }; var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit | VAnchor.Top, }; widget.AddChild(container); GuiWidget hotendRow; container.AddChild(hotendRow = new SettingsItem( "Heated Bed".Localize(), theme, new SettingsItem.ToggleSwitchConfig() { Checked = false, ToggleAction = (itemChecked) => { var goalTemp = itemChecked ? printer.Settings.GetValue <double>(SettingsKey.bed_temperature) : 0; if (itemChecked) { SetTargetTemperature(goalTemp); } else { SetTargetTemperature(0); } } }, enforceGutter: false)); var toggleWidget = hotendRow.Children.Where(o => o is ICheckbox).FirstOrDefault(); toggleWidget.Name = "Toggle Heater"; heatToggle = toggleWidget as ICheckbox; int tabIndex = 0; var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All); var settingsData = SettingsOrganizer.Instance.GetSettingsData(SettingsKey.bed_temperature); var temperatureRow = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, theme, ref tabIndex); SliceSettingsRow.AddBordersToEditFields(temperatureRow); container.AddChild(temperatureRow); alwaysEnabled.Add(hotendRow); // add in the temp graph var graph = new DataViewGraph() { DynamiclyScaleRange = false, MinValue = 0, ShowGoal = true, GoalColor = ActiveTheme.Instance.PrimaryAccentColor, GoalValue = printer.Settings.GetValue <double>(SettingsKey.bed_temperature), MaxValue = 150, // could come from some profile value in the future Width = widget.Width - 20, Height = 35, // this works better if it is a common multiple of the Width Margin = new BorderDouble(0, 5, 0, 0), }; var runningInterval = UiThread.SetInterval(() => { graph.AddData(this.ActualTemperature); }, 1); this.Closed += (s, e) => runningInterval.Continue = false; var valueField = temperatureRow.Descendants <MHNumberEdit>().FirstOrDefault(); var settingsRow = temperatureRow.DescendantsAndSelf <SliceSettingsRow>().FirstOrDefault(); ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) => { if (e is StringEventArgs stringEvent) { var temp = printer.Settings.GetValue <double>(SettingsKey.bed_temperature); valueField.Value = temp; graph.GoalValue = temp; settingsRow.UpdateStyle(); if (stringEvent.Data == SettingsKey.bed_temperature && heatToggle.Checked) { SetTargetTemperature(temp); } } ; }, ref unregisterEvents); container.AddChild(graph); return(widget); }