fix: 样式区线宽行改为按可用宽度等比自适应,面板收窄时不再溢出
- 线宽行先按设计尺寸排布,仅在可用宽度不足时整体等比缩小, 面板默认宽度下保持原有比例(数值框不会被拉宽变形),最窄宽度下也不会溢出面板。 - 面板极窄时数值框自动省略 "px" 单位、仅显示数值,避免出现被截断的省略号。
This commit is contained in:
1 parent
0f98dd9a85
commit
2d09935063
1 file changed
+40
-26
@@ -482,33 +482,35 @@ namespace jdi
|
||||
swatchSize, swatchSize);
|
||||
|
||||
// ---- 第二行:线宽(最细 / 数值旋钮 / 最粗)----
|
||||
const float presetWidth = kWidthPresetWidth * m_scale;
|
||||
const float spinButton = kWidthSpinButton * m_scale;
|
||||
const float valueWidth = kWidthValueWidth * m_scale;
|
||||
float groupGap = 8.0f * m_scale;
|
||||
|
||||
float spinnerWidth = spinButton * 2.0f + valueWidth;
|
||||
float groupWidth = presetWidth * 2.0f + spinnerWidth + groupGap * 2.0f;
|
||||
if (groupWidth > contentWidth)
|
||||
{
|
||||
const float fit = contentWidth / groupWidth;
|
||||
groupGap = std::max(3.0f * m_scale, groupGap * fit);
|
||||
spinnerWidth = std::max(spinButton * 2.0f + 36.0f * m_scale, spinnerWidth * fit);
|
||||
groupWidth = std::min(contentWidth, presetWidth * 2.0f + spinnerWidth + groupGap * 2.0f);
|
||||
}
|
||||
|
||||
// 先按设计尺寸排布,仅在可用宽度不足时整体等比缩小,保证不溢出也不被拉伸变形。
|
||||
const float row1Top = row0Top + (kStyleRowHeight + kStyleRowGap) * m_scale;
|
||||
const float naturalGap = 8.0f * m_scale;
|
||||
const float naturalPreset = kWidthPresetWidth * m_scale;
|
||||
const float naturalSpinner = (kWidthSpinButton * 2.0f + kWidthValueWidth) * m_scale;
|
||||
|
||||
const float naturalTotal = naturalPreset * 2.0f + naturalSpinner + naturalGap * 2.0f;
|
||||
const float widthFactor =
|
||||
(naturalTotal > contentWidth && naturalTotal > 0.0f) ? (contentWidth / naturalTotal) : 1.0f;
|
||||
|
||||
const float presetWidth = naturalPreset * widthFactor;
|
||||
const float spinnerWidth = naturalSpinner * widthFactor;
|
||||
const float rowGap = std::max(2.0f * m_scale, naturalGap * widthFactor);
|
||||
|
||||
const float spinButtonWidth = std::min(kWidthSpinButton * m_scale, spinnerWidth * 0.26f);
|
||||
const float innerValueWidth = std::max(12.0f * m_scale, spinnerWidth - spinButtonWidth * 2.0f);
|
||||
|
||||
const float groupWidth = presetWidth * 2.0f + spinnerWidth + rowGap * 2.0f;
|
||||
const float groupLeft = contentLeft + std::max(0.0f, (contentWidth - groupWidth) * 0.5f);
|
||||
const float innerSpinButton = std::min(spinButton, spinnerWidth * 0.25f);
|
||||
const float innerValueWidth = std::max(24.0f * m_scale, spinnerWidth - innerSpinButton * 2.0f);
|
||||
|
||||
m_widthThinRect = gd::RectF(groupLeft, row1Top, presetWidth, rowHeight);
|
||||
m_widthSpinnerRect = gd::RectF(groupLeft + presetWidth + groupGap, row1Top, spinnerWidth, rowHeight);
|
||||
m_widthMinusRect = gd::RectF(m_widthSpinnerRect.X, row1Top, innerSpinButton, rowHeight);
|
||||
m_widthValueRect = gd::RectF(m_widthMinusRect.X + innerSpinButton, row1Top, innerValueWidth, rowHeight);
|
||||
m_widthPlusRect = gd::RectF(m_widthValueRect.X + innerValueWidth, row1Top, innerSpinButton, rowHeight);
|
||||
m_widthSpinnerRect = gd::RectF(groupLeft + presetWidth + rowGap, row1Top, spinnerWidth, rowHeight);
|
||||
m_widthMinusRect = gd::RectF(m_widthSpinnerRect.X, row1Top, spinButtonWidth, rowHeight);
|
||||
m_widthValueRect =
|
||||
gd::RectF(m_widthMinusRect.X + spinButtonWidth, row1Top, innerValueWidth, rowHeight);
|
||||
m_widthPlusRect =
|
||||
gd::RectF(m_widthValueRect.X + innerValueWidth, row1Top, spinButtonWidth, rowHeight);
|
||||
m_widthThickRect =
|
||||
gd::RectF(m_widthSpinnerRect.X + spinnerWidth + groupGap, row1Top, presetWidth, rowHeight);
|
||||
gd::RectF(m_widthSpinnerRect.X + spinnerWidth + rowGap, row1Top, presetWidth, rowHeight);
|
||||
|
||||
// ---- 第三行:样式(线段 / 散点 / 点线)----
|
||||
const float row2Top = row1Top + (kStyleRowHeight + kStyleRowGap) * m_scale;
|
||||
@@ -930,10 +932,16 @@ namespace jdi
|
||||
{
|
||||
const std::wstring editText =
|
||||
m_widthEditText.empty() ? std::wstring(L" ") : m_widthEditText;
|
||||
const float textWidth = UiTextWidth(g, editText, m_fonts->monoSmall);
|
||||
// 面板极窄时省略单位,保证数值本身完整可读。
|
||||
const std::wstring fullText = editText + L" px";
|
||||
const std::wstring shown =
|
||||
(UiTextWidth(g, fullText, m_fonts->monoSmall) > m_widthValueRect.Width - 6.0f * m_scale)
|
||||
? editText
|
||||
: fullText;
|
||||
const float textWidth = UiTextWidth(g, shown, m_fonts->monoSmall);
|
||||
const float caretX =
|
||||
m_widthValueRect.X + m_widthValueRect.Width - 6.0f * m_scale - textWidth;
|
||||
UiText(g, editText + L" px", m_fonts->monoSmall, m_widthValueRect, m_theme->textStrong,
|
||||
UiText(g, shown, m_fonts->monoSmall, m_widthValueRect, m_theme->textStrong,
|
||||
TextAlign::RIGHT);
|
||||
if (caretX > m_widthValueRect.X)
|
||||
{
|
||||
@@ -944,8 +952,14 @@ namespace jdi
|
||||
}
|
||||
else
|
||||
{
|
||||
UiText(g, FormatNumber(style->lineWidth, 1) + L" px", m_fonts->monoSmall, m_widthValueRect,
|
||||
m_theme->textStrong, TextAlign::CENTER);
|
||||
const std::wstring numberText = FormatNumber(style->lineWidth, 1);
|
||||
const std::wstring fullText = numberText + L" px";
|
||||
const std::wstring shown =
|
||||
(UiTextWidth(g, fullText, m_fonts->monoSmall) > m_widthValueRect.Width - 6.0f * m_scale)
|
||||
? numberText
|
||||
: fullText;
|
||||
UiText(g, shown, m_fonts->monoSmall, m_widthValueRect, m_theme->textStrong,
|
||||
TextAlign::CENTER);
|
||||
}
|
||||
|
||||
const bool minusHot = (m_hoverStyle == StyleHit::WIDTH_MINUS);
|
||||
|
||||
Reference in new issue
Block a user