UI tweak and optimization
This commit is contained in:
parent
747451d243
commit
8d7872a376
@ -7,20 +7,13 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
{
|
{
|
||||||
internal partial class ProcessBookControl : UserControl
|
internal partial class ProcessBookControl : UserControl
|
||||||
{
|
{
|
||||||
private static int ControlNumberCounter = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The control's position within <see cref="VirtualFlowControl"/>
|
|
||||||
/// </summary>
|
|
||||||
public int ControlNumber { get; }
|
|
||||||
private ProcessBookStatus Status { get; set; } = ProcessBookStatus.Queued;
|
|
||||||
private readonly int CancelBtnDistanceFromEdge;
|
private readonly int CancelBtnDistanceFromEdge;
|
||||||
private readonly int ProgressBarDistanceFromEdge;
|
private readonly int ProgressBarDistanceFromEdge;
|
||||||
|
|
||||||
public static Color FailedColor = Color.LightCoral;
|
private static Color FailedColor { get; } = Color.LightCoral;
|
||||||
public static Color CancelledColor = Color.Khaki;
|
private static Color CancelledColor { get; } = Color.Khaki;
|
||||||
public static Color QueuedColor = SystemColors.Control;
|
private static Color QueuedColor { get; } = SystemColors.Control;
|
||||||
public static Color SuccessColor = Color.PaleGreen;
|
private static Color SuccessColor { get; } = Color.PaleGreen;
|
||||||
|
|
||||||
private ProcessBookViewModelBase m_Context;
|
private ProcessBookViewModelBase m_Context;
|
||||||
public ProcessBookViewModelBase Context
|
public ProcessBookViewModelBase Context
|
||||||
@ -37,6 +30,17 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProcessBookControl()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
remainingTimeLbl.Visible = false;
|
||||||
|
progressBar1.Visible = false;
|
||||||
|
etaLbl.Visible = false;
|
||||||
|
|
||||||
|
CancelBtnDistanceFromEdge = Width - cancelBtn.Location.X;
|
||||||
|
ProgressBarDistanceFromEdge = Width - progressBar1.Location.X - progressBar1.Width;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnContextChanging()
|
private void OnContextChanging()
|
||||||
{
|
{
|
||||||
if (Context is not null)
|
if (Context is not null)
|
||||||
@ -65,29 +69,12 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
ResumeLayout();
|
ResumeLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessBookControl()
|
private void SetCover(Image cover) => pictureBox1.Image = cover;
|
||||||
{
|
private void SetBookInfo(string title) => bookInfoLbl.Text = title;
|
||||||
InitializeComponent();
|
private void SetRemainingTime(TimeSpan remaining)
|
||||||
remainingTimeLbl.Visible = false;
|
=> remainingTimeLbl.Text = $"{remaining:mm\\:ss}";
|
||||||
progressBar1.Visible = false;
|
|
||||||
etaLbl.Visible = false;
|
|
||||||
|
|
||||||
CancelBtnDistanceFromEdge = Width - cancelBtn.Location.X;
|
private void SetProgress(int progress)
|
||||||
ProgressBarDistanceFromEdge = Width - progressBar1.Location.X - progressBar1.Width;
|
|
||||||
ControlNumber = ControlNumberCounter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCover(Image cover)
|
|
||||||
{
|
|
||||||
pictureBox1.Image = cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetBookInfo(string title)
|
|
||||||
{
|
|
||||||
bookInfoLbl.Text = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetProgress(int progress)
|
|
||||||
{
|
{
|
||||||
//Disable slow fill
|
//Disable slow fill
|
||||||
//https://stackoverflow.com/a/5332770/3335599
|
//https://stackoverflow.com/a/5332770/3335599
|
||||||
@ -96,16 +83,9 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
progressBar1.Value = progress;
|
progressBar1.Value = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRemainingTime(TimeSpan remaining)
|
private void SetStatus(ProcessBookStatus status, string statusText)
|
||||||
{
|
{
|
||||||
remainingTimeLbl.Text = $"{remaining:mm\\:ss}";
|
Color backColor = status switch
|
||||||
}
|
|
||||||
|
|
||||||
public void SetStatus(ProcessBookStatus status, string statusText)
|
|
||||||
{
|
|
||||||
Status = status;
|
|
||||||
|
|
||||||
Color backColor = Status switch
|
|
||||||
{
|
{
|
||||||
ProcessBookStatus.Completed => SuccessColor,
|
ProcessBookStatus.Completed => SuccessColor,
|
||||||
ProcessBookStatus.Cancelled => CancelledColor,
|
ProcessBookStatus.Cancelled => CancelledColor,
|
||||||
@ -114,23 +94,21 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
_ => FailedColor
|
_ => FailedColor
|
||||||
};
|
};
|
||||||
|
|
||||||
SuspendLayout();
|
cancelBtn.Visible = status is ProcessBookStatus.Queued or ProcessBookStatus.Working;
|
||||||
|
moveLastBtn.Visible = status == ProcessBookStatus.Queued;
|
||||||
cancelBtn.Visible = Status is ProcessBookStatus.Queued or ProcessBookStatus.Working;
|
moveDownBtn.Visible = status == ProcessBookStatus.Queued;
|
||||||
moveLastBtn.Visible = Status == ProcessBookStatus.Queued;
|
moveUpBtn.Visible = status == ProcessBookStatus.Queued;
|
||||||
moveDownBtn.Visible = Status == ProcessBookStatus.Queued;
|
moveFirstBtn.Visible = status == ProcessBookStatus.Queued;
|
||||||
moveUpBtn.Visible = Status == ProcessBookStatus.Queued;
|
remainingTimeLbl.Visible = status == ProcessBookStatus.Working;
|
||||||
moveFirstBtn.Visible = Status == ProcessBookStatus.Queued;
|
progressBar1.Visible = status == ProcessBookStatus.Working;
|
||||||
remainingTimeLbl.Visible = Status == ProcessBookStatus.Working;
|
etaLbl.Visible = status == ProcessBookStatus.Working;
|
||||||
progressBar1.Visible = Status == ProcessBookStatus.Working;
|
statusLbl.Visible = status != ProcessBookStatus.Working;
|
||||||
etaLbl.Visible = Status == ProcessBookStatus.Working;
|
|
||||||
statusLbl.Visible = Status != ProcessBookStatus.Working;
|
|
||||||
statusLbl.Text = statusText;
|
statusLbl.Text = statusText;
|
||||||
BackColor = backColor;
|
BackColor = backColor;
|
||||||
|
|
||||||
int deltaX = Width - cancelBtn.Location.X - CancelBtnDistanceFromEdge;
|
int deltaX = Width - cancelBtn.Location.X - CancelBtnDistanceFromEdge;
|
||||||
|
|
||||||
if (Status is ProcessBookStatus.Queued or ProcessBookStatus.Working && deltaX != 0)
|
if (status is ProcessBookStatus.Queued or ProcessBookStatus.Working && deltaX != 0)
|
||||||
{
|
{
|
||||||
//If the last book to occupy this control before resizing was not
|
//If the last book to occupy this control before resizing was not
|
||||||
//queued, the buttons were not Visible so the Anchor property was
|
//queued, the buttons were not Visible so the Anchor property was
|
||||||
@ -154,13 +132,8 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
{
|
{
|
||||||
bookInfoLbl.Width = moveLastBtn.Location.X - bookInfoLbl.Location.X - bookInfoLbl.Padding.Left + moveLastBtn.Padding.Right;
|
bookInfoLbl.Width = moveLastBtn.Location.X - bookInfoLbl.Location.X - bookInfoLbl.Padding.Left + moveLastBtn.Padding.Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResumeLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString() => bookInfoLbl.Text ?? "[NO TITLE]";
|
||||||
{
|
|
||||||
return bookInfoLbl.Text ?? "[NO TITLE]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -165,13 +165,13 @@ namespace LibationWinForms.ProcessQueue
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
vScrollBar1.Enabled = true;
|
vScrollBar1.Enabled = true;
|
||||||
vScrollBar1.LargeChange = LargeScrollChange;
|
|
||||||
|
|
||||||
//https://stackoverflow.com/a/2882878/3335599
|
//https://stackoverflow.com/a/2882878/3335599
|
||||||
int newMaximum = VirtualHeight + vScrollBar1.LargeChange - 1;
|
int newMaximum = VirtualHeight + LargeScrollChange - 1;
|
||||||
if (newMaximum < vScrollBar1.Maximum)
|
if (newMaximum < vScrollBar1.Maximum)
|
||||||
vScrollBar1.Value = Math.Max(vScrollBar1.Value - (vScrollBar1.Maximum - newMaximum), 0);
|
vScrollBar1.Value = Math.Max(vScrollBar1.Value - (vScrollBar1.Maximum - newMaximum), 0);
|
||||||
vScrollBar1.Maximum = newMaximum;
|
vScrollBar1.Maximum = newMaximum;
|
||||||
|
vScrollBar1.LargeChange = LargeScrollChange;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user