public RunningTaskRow(string title, RunningTaskDetails taskDetails, ThemeConfig theme) : base(FlowDirection.TopToBottom) { this.taskDetails = taskDetails; this.theme = theme; this.MinimumSize = new Vector2(100, 20); var detailsPanel = new GuiWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, }; var rowContainer = new GuiWidget() { VAnchor = VAnchor.Fit, HAnchor = HAnchor.Stretch, }; this.AddChild(rowContainer); var topRow = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, Padding = 0, }; rowContainer.AddChild(topRow); progressBar = new ProgressBar() { HAnchor = HAnchor.Stretch, Height = 2, VAnchor = VAnchor.Absolute | VAnchor.Bottom, FillColor = ActiveTheme.Instance.PrimaryAccentColor, BorderColor = Color.Transparent, BackgroundColor = ActiveTheme.Instance.TertiaryBackgroundColor, Margin = new BorderDouble(32, 7, theme.ButtonHeight * 2 + 14, 0), }; rowContainer.AddChild(progressBar); expandButton = new ExpandCheckboxButton(!string.IsNullOrWhiteSpace(title) ? title : taskDetails.Title, theme, 10) { VAnchor = VAnchor.Center | VAnchor.Fit, HAnchor = HAnchor.Stretch, Checked = false, Padding = 0 }; expandButton.CheckedStateChanged += (s, e) => { taskDetails.IsExpanded = expandButton.Checked; SetExpansionMode(theme, detailsPanel, expandButton.Checked); }; topRow.AddChild(expandButton); IconButton resumeButton = null; var pauseButton = new IconButton(AggContext.StaticData.LoadIcon("fa-pause_12.png", theme.InvertIcons), theme) { Margin = theme.ButtonSpacing, Enabled = taskDetails.Options?.PauseAction != null, ToolTipText = taskDetails.Options?.PauseToolTip ?? "Pause".Localize() }; if (taskDetails.Options?.IsPaused != null) { RunningInterval runningInterval = null; runningInterval = UiThread.SetInterval(() => { if (taskDetails.Options.IsPaused()) { pauseButton.Visible = false; resumeButton.Visible = true; } else { pauseButton.Visible = true; resumeButton.Visible = false; } if (this.HasBeenClosed) { runningInterval.Continue = false; } }, .2); } pauseButton.Click += (s, e) => { taskDetails.Options?.PauseAction(); pauseButton.Visible = false; resumeButton.Visible = true; }; topRow.AddChild(pauseButton); resumeButton = new IconButton(AggContext.StaticData.LoadIcon("fa-play_12.png", theme.InvertIcons), theme) { Visible = false, Margin = theme.ButtonSpacing, ToolTipText = taskDetails.Options?.ResumeToolTip ?? "Resume".Localize(), Name = "Resume Task Button" }; resumeButton.Click += (s, e) => { taskDetails.Options?.ResumeAction(); pauseButton.Visible = true; resumeButton.Visible = false; }; topRow.AddChild(resumeButton); var stopButton = new IconButton(AggContext.StaticData.LoadIcon("fa-stop_12.png", theme.InvertIcons), theme) { Margin = theme.ButtonSpacing, Name = "Stop Task Button", ToolTipText = taskDetails.Options?.StopToolTip ?? "Cancel".Localize() }; stopButton.Click += (s, e) => { var stopAction = taskDetails.Options?.StopAction; if (stopAction == null) { taskDetails.CancelTask(); } else { stopAction.Invoke(); } }; topRow.AddChild(stopButton); this.AddChild(detailsPanel); // Add rich progress controls if (taskDetails.Options?.RichProgressWidget?.Invoke() is GuiWidget guiWidget) { detailsPanel.AddChild(guiWidget); } if (taskDetails.Options?.ReadOnlyReporting == true) { stopButton.Visible = false; pauseButton.Visible = false; resumeButton.Visible = false; // Ensure the top row is as big as it would be with buttons topRow.MinimumSize = new Vector2(0, resumeButton.Height); } SetExpansionMode(theme, detailsPanel, taskDetails.IsExpanded); taskDetails.ProgressChanged += TaskDetails_ProgressChanged; }
public RunningTaskRow(string title, RunningTaskDetails taskDetails, ThemeConfig theme) : base(FlowDirection.TopToBottom) { this.taskDetails = taskDetails; this.theme = theme; this.MinimumSize = new Vector2(100 * GuiWidget.DeviceScale, 20 * GuiWidget.DeviceScale); var detailsPanel = new GuiWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, }; var rowContainer = new GuiWidget() { VAnchor = VAnchor.Fit, HAnchor = HAnchor.Stretch, }; this.AddChild(rowContainer); var topRow = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, Padding = 0, }; rowContainer.AddChild(topRow); progressBar = new ProgressBar() { HAnchor = HAnchor.Stretch, Height = 2 * GuiWidget.DeviceScale, VAnchor = VAnchor.Absolute | VAnchor.Bottom, FillColor = theme.PrimaryAccentColor, BorderColor = Color.Transparent, Margin = new BorderDouble(32, 7, theme.ButtonHeight * 2 + 14, 0), Visible = !taskDetails.IsExpanded }; rowContainer.AddChild(progressBar); expandButton = new ExpandCheckboxButton(!string.IsNullOrWhiteSpace(title) ? title : taskDetails.Title, theme, 10) { VAnchor = VAnchor.Center | VAnchor.Fit, HAnchor = HAnchor.Stretch, Checked = false, Padding = 0, AlwaysShowArrow = true }; expandButton.CheckedStateChanged += (s, e) => { taskDetails.IsExpanded = expandButton.Checked; SetExpansionMode(theme, detailsPanel, expandButton.Checked); }; topRow.AddChild(expandButton); GuiWidget resumeButton = null; GuiWidget pauseButton = CreateIconOrTextButton("fa-pause_12.png", taskDetails.Options?.PauseText, taskDetails.Options?.PauseAction, taskDetails.Options?.PauseToolTip ?? "Pause".Localize(), "", theme, 0); if (taskDetails.Options?.IsPaused != null) { RunningInterval runningInterval = null; runningInterval = UiThread.SetInterval(() => { if (taskDetails.Options.IsPaused()) { pauseButton.Visible = false; resumeButton.Visible = true; } else { pauseButton.Visible = true; resumeButton.Visible = false; } if (this.HasBeenClosed) { UiThread.ClearInterval(runningInterval); } }, .2); } pauseButton.Click += (s, e) => { taskDetails.Options?.PauseAction(); pauseButton.Visible = false; resumeButton.Visible = true; }; topRow.AddChild(pauseButton); resumeButton = CreateIconOrTextButton("fa-play_12.png", taskDetails.Options?.ResumeText, taskDetails.Options?.ResumeAction, taskDetails.Options?.ResumeToolTip ?? "Resume".Localize(), "Resume Task Button", theme, 0); // start with it hidden resumeButton.Visible = false; resumeButton.Click += (s, e) => { taskDetails.Options?.ResumeAction(); pauseButton.Visible = true; resumeButton.Visible = false; }; topRow.AddChild(resumeButton); var stopButton = CreateIconOrTextButton("fa-stop_12.png", taskDetails.Options?.StopText, taskDetails.Options?.StopAction, taskDetails.Options?.StopToolTip ?? "Cancel".Localize(), "Stop Task Button", theme, 5); stopButton.Enabled = true; stopButton.Click += (s, e) => { var stopAction = taskDetails.Options?.StopAction; if (stopAction == null) { taskDetails.CancelTask(); } else { stopAction.Invoke(() => { stopButton.Enabled = true; }); } stopButton.Enabled = false; }; topRow.AddChild(stopButton); this.AddChild(detailsPanel); // Add rich progress controls if (taskDetails.Options?.RichProgressWidget?.Invoke() is GuiWidget guiWidget) { detailsPanel.AddChild(guiWidget); } else { expandButton.Expandable = false; } if (taskDetails.Options?.ReadOnlyReporting == true) { stopButton.Visible = false; pauseButton.Visible = false; resumeButton.Visible = false; // Ensure the top row is as big as it would be with buttons topRow.MinimumSize = new Vector2(0, resumeButton.Height); } SetExpansionMode(theme, detailsPanel, taskDetails.IsExpanded); taskDetails.ProgressChanged += TaskDetails_ProgressChanged; }