Make FOrders toolbar responsive without stretching filter controls.

Wrap selectors on narrow windows, cap text and combo widths on wide layouts, and move the comment button to a new row when space is tight.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Magomed 2026-07-14 15:06:09 +03:00
parent 36d4374db6
commit 46564ee942

View File

@ -86,64 +86,169 @@ namespace Электронная_Фармация.UserControls
UiThemeHelper.ApplyToControlTree(_btnSendOrder);
}
private static int FitControlWidth(int preferred, int minimum, int available)
{
return Math.Max(minimum, Math.Min(preferred, available));
}
private void ApplyToolbarLayout()
{
const int pad = 12;
const int gap = 8;
const int row1Y = 10;
const int controlHeight = 32;
const int filterHeight = 33;
const int buttonHeight = 34;
const int rowGap = 14;
const int row2Y = row1Y + buttonHeight + rowGap;
const int commentWidth = 200;
const int filterY = row1Y + (buttonHeight - filterHeight) / 2;
const int rowGap = 10;
const int dateWidth = 112;
const int deleteWidth = 138;
const int sendWidth = 158;
const int clearSize = 32;
const int commentMaxWidth = 200;
const int commentMinWidth = 132;
const int textMinWidth = 108;
const int textPreferredWidth = 220;
const int statusPreferredWidth = 150;
const int supplierPreferredWidth = 170;
const int consigneePreferredWidth = 190;
var panelWidth = Math.Max(panelToolbar.ClientSize.Width, 320);
int y = 10;
int x = pad;
label2.Location = new Point(x, row1Y + 5);
label2.Location = new Point(x, y + 5);
x = label2.Right + 6;
dtpDateFrom.SetBounds(x, row1Y, 118, controlHeight);
dtpDateFrom.SetBounds(x, y, dateWidth, controlHeight);
x = dtpDateFrom.Right + 6;
label1.Location = new Point(x, row1Y + 4);
label1.Location = new Point(x, y + 4);
x = label1.Right + 6;
dtpDateTo.SetBounds(x, row1Y, 118, controlHeight);
dtpDateTo.SetBounds(x, y, dateWidth, controlHeight);
int datesRight = dtpDateTo.Right;
int right = panelToolbar.ClientSize.Width - pad;
int deleteLeft = panelWidth - pad - deleteWidth;
btnDeleteOrder.SetBounds(deleteLeft, y, deleteWidth, buttonHeight);
int sendLeft = btnDeleteOrder.Left - gap - sendWidth;
_btnSendOrder.SetBounds(sendLeft, y, sendWidth, buttonHeight);
int actionsLeft = _btnSendOrder.Left;
btnDeleteOrder.SetBounds(right - 148, row1Y, 148, buttonHeight);
right = btnDeleteOrder.Left - gap;
int middleAvailable = actionsLeft - datesRight - gap;
int statusMin = 108;
int supplierMin = 118;
int consigneeMin = 128;
int combosMin = statusMin + supplierMin + consigneeMin + gap * 2;
int combosPreferred = statusPreferredWidth + supplierPreferredWidth + consigneePreferredWidth + gap * 2;
bool wrapCombos = middleAvailable < combosMin;
_btnSendOrder.SetBounds(right - 168, row1Y, 168, buttonHeight);
right = _btnSendOrder.Left - gap;
comboSuppliers.Visible = true;
_comboOrderStatus.Visible = true;
_comboConsignees.Visible = true;
_comboConsignees.SetBounds(right - 190, filterY, 190, filterHeight);
right = _comboConsignees.Left - gap;
if (wrapCombos)
{
y += buttonHeight + rowGap;
int filterY = y + (buttonHeight - filterHeight) / 2;
int comboRowWidth = panelWidth - pad * 2;
int statusWidth;
int supplierWidth;
int consigneeWidth;
comboSuppliers.SetBounds(right - 170, filterY, 170, filterHeight);
right = comboSuppliers.Left - gap;
_comboOrderStatus.SetBounds(right - 150, filterY, 150, filterHeight);
if (comboRowWidth >= combosPreferred)
{
statusWidth = statusPreferredWidth;
supplierWidth = supplierPreferredWidth;
consigneeWidth = consigneePreferredWidth;
}
else
{
float scale = (comboRowWidth - gap * 2) / (float)(statusPreferredWidth + supplierPreferredWidth + consigneePreferredWidth);
statusWidth = Math.Max(statusMin, (int)(statusPreferredWidth * scale));
supplierWidth = Math.Max(supplierMin, (int)(supplierPreferredWidth * scale));
consigneeWidth = Math.Max(consigneeMin, comboRowWidth - statusWidth - supplierWidth - gap * 2);
}
x = pad;
txtGoodFromOrders.SetBounds(x, row2Y, 220, controlHeight);
_comboOrderStatus.SetBounds(x, filterY, statusWidth, filterHeight);
x = _comboOrderStatus.Right + gap;
comboSuppliers.SetBounds(x, filterY, supplierWidth, filterHeight);
x = comboSuppliers.Right + gap;
_comboConsignees.SetBounds(x, filterY, consigneeWidth, filterHeight);
y += buttonHeight + rowGap;
}
else
{
int filterY = y + (buttonHeight - filterHeight) / 2;
int statusWidth = statusPreferredWidth;
int supplierWidth = supplierPreferredWidth;
int consigneeWidth = consigneePreferredWidth;
if (middleAvailable < combosPreferred)
{
float scale = middleAvailable / (float)combosPreferred;
statusWidth = Math.Max(statusMin, (int)(statusPreferredWidth * scale));
supplierWidth = Math.Max(supplierMin, (int)(supplierPreferredWidth * scale));
consigneeWidth = Math.Max(consigneeMin, middleAvailable - statusWidth - supplierWidth - gap * 2);
}
int comboRight = actionsLeft - gap;
_comboConsignees.SetBounds(comboRight - consigneeWidth, filterY, consigneeWidth, filterHeight);
comboRight = _comboConsignees.Left - gap;
comboSuppliers.SetBounds(comboRight - supplierWidth, filterY, supplierWidth, filterHeight);
comboRight = comboSuppliers.Left - gap;
_comboOrderStatus.SetBounds(comboRight - statusWidth, filterY, statusWidth, filterHeight);
y += buttonHeight + rowGap;
}
int searchY = y;
int contentWidth = panelWidth - pad * 2;
int fixedControlsWidth = clearSize * 2 + gap * 4 + commentMinWidth;
int textAreaWidth = contentWidth - fixedControlsWidth;
bool wrapComment = textAreaWidth < textMinWidth * 2;
int textWidth;
if (wrapComment)
{
int narrowTextArea = contentWidth - clearSize * 2 - gap * 2;
textWidth = FitControlWidth(textPreferredWidth, textMinWidth, narrowTextArea / 2);
}
else
{
textWidth = textPreferredWidth;
}
int commentWidth = wrapComment
? Math.Min(commentMaxWidth, contentWidth)
: commentMaxWidth;
x = pad;
txtGoodFromOrders.SetBounds(x, searchY, textWidth, controlHeight);
x = txtGoodFromOrders.Right + gap;
btnClearGoodSearch.SetBounds(x, row2Y, 32, controlHeight);
btnClearGoodSearch.SetBounds(x, searchY, clearSize, controlHeight);
x = btnClearGoodSearch.Right + gap;
txtOrderNumberFilter.SetBounds(x, row2Y, 220, controlHeight);
txtOrderNumberFilter.SetBounds(x, searchY, textWidth, controlHeight);
x = txtOrderNumberFilter.Right + gap;
btnClearOrderNumberFilter.SetBounds(x, row2Y, 32, controlHeight);
btnClearOrderNumberFilter.SetBounds(x, searchY, clearSize, controlHeight);
x = btnClearOrderNumberFilter.Right + gap;
btnAddComment.SetBounds(x, row2Y, commentWidth, buttonHeight);
if (wrapComment)
{
searchY += controlHeight + rowGap;
btnAddComment.SetBounds(pad, searchY, commentWidth, buttonHeight);
y = searchY + buttonHeight;
}
else
{
btnAddComment.SetBounds(x, searchY, commentWidth, buttonHeight);
ModernButtonStyles.FitToText(btnAddComment, buttonHeight);
y = searchY + buttonHeight;
}
ModernButtonStyles.ApplyClear(btnClearGoodSearch);
ModernButtonStyles.ApplyClear(btnClearOrderNumberFilter);
btnClearSuppliers.Visible = false;
panelToolbar.Height = row2Y + buttonHeight + pad + 8;
panelToolbar.Height = y + pad + 8;
panelToolbar.Padding = new Padding(pad, 10, pad, 14);
}