Refine dialog initialization and noisy repaint logs
This commit is contained in:
+34
-21
@@ -102,27 +102,19 @@ bool Dialog::handleEvent(const ExMessage& msg)
|
||||
void Dialog::SetTitle(const std::string& title)
|
||||
{
|
||||
this->titleText = title;
|
||||
if (this->title)
|
||||
{
|
||||
this->title->setText(title);
|
||||
}
|
||||
dirty = true;
|
||||
invalidateLayout(true);
|
||||
}
|
||||
|
||||
void Dialog::SetMessage(const std::string& message)
|
||||
{
|
||||
this->message = message;
|
||||
splitMessageLines();
|
||||
getTextSize();
|
||||
dirty = true;
|
||||
invalidateLayout(true);
|
||||
}
|
||||
|
||||
void Dialog::SetType(StellarX::MessageBoxType type)
|
||||
{
|
||||
this->type = type;
|
||||
// 重新初始化按钮
|
||||
initButtons();
|
||||
dirty = true;
|
||||
invalidateLayout(true);
|
||||
}
|
||||
|
||||
void Dialog::SetModal(bool modal)
|
||||
@@ -255,9 +247,11 @@ void Dialog::setInitialization(bool init)
|
||||
{
|
||||
if (init)
|
||||
{
|
||||
initDialogSize();
|
||||
saveBackground((x - BorderWidth), (y - BorderWidth), (width + 2 * BorderWidth), (height + 2 * BorderWidth));
|
||||
this->dirty = true;
|
||||
invalidateLayout(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
needsInitialization = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,8 +541,8 @@ void Dialog::getTextSize()
|
||||
settextstyle(textStyle.nHeight, textStyle.nWidth, textStyle.lpszFace,
|
||||
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
|
||||
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut);
|
||||
int tempHeight = 0;
|
||||
int tempWidth = 0;
|
||||
this->textHeight = 0;
|
||||
this->textWidth = 0;
|
||||
for (auto& text : lines)
|
||||
{
|
||||
int w = textwidth(LPCTSTR(text.c_str()));
|
||||
@@ -558,13 +552,27 @@ void Dialog::getTextSize()
|
||||
if (this->textWidth < w)
|
||||
this->textWidth = w;
|
||||
}
|
||||
|
||||
|
||||
restoreStyle();
|
||||
}
|
||||
|
||||
void Dialog::invalidateLayout(bool clearChildren)
|
||||
{
|
||||
if (clearChildren)
|
||||
clearControls();
|
||||
|
||||
this->textWidth = 0;
|
||||
this->textHeight = 0;
|
||||
this->buttonNum = 0;
|
||||
this->needsInitialization = true;
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
// 计算逻辑:对话框宽度取【文本区域最大宽度】和【按钮区域总宽度】中的较大值。
|
||||
// 对话框高度 = 标题栏 + 文本区 + 按钮区 + 各种间距。
|
||||
void Dialog::initDialogSize()
|
||||
{
|
||||
this->textStyle.nHeight = 20;
|
||||
splitMessageLines(); // 分割消息行
|
||||
getTextSize(); // 获取文本最大尺寸
|
||||
|
||||
@@ -591,9 +599,17 @@ void Dialog::initDialogSize()
|
||||
|
||||
// 计算文本区域宽度(包括边距)
|
||||
int textAreaWidth = textWidth + textToBorderMargin * 2;
|
||||
saveStyle();
|
||||
settextstyle(textStyle.nHeight, textStyle.nWidth, textStyle.lpszFace,
|
||||
textStyle.nEscapement, textStyle.nOrientation, textStyle.nWeight,
|
||||
textStyle.bItalic, textStyle.bUnderline, textStyle.bStrikeOut);
|
||||
int titleAreaWidth = textwidth(LPCTSTR(titleText.c_str())) + textToBorderMargin * 2 + closeButtonWidth + buttonMargin;
|
||||
restoreStyle();
|
||||
|
||||
// 对话框宽度取两者中的较大值,并确保最小宽度
|
||||
// 对话框宽度取文本、标题和按钮区域中的较大值,并确保最小宽度
|
||||
this->width = buttonAreaWidth > textAreaWidth ? buttonAreaWidth : textAreaWidth;
|
||||
if (titleAreaWidth > this->width)
|
||||
this->width = titleAreaWidth;
|
||||
this->width = this->width > 200 ? this->width : 200;
|
||||
|
||||
// 计算对话框高度
|
||||
@@ -608,9 +624,6 @@ void Dialog::initDialogSize()
|
||||
this->x = (hWnd.getWidth() - this->width) / 2;
|
||||
this->y = (hWnd.getHeight() - this->height) / 2;
|
||||
|
||||
//this->textStyle.nWidth = 10;
|
||||
this->textStyle.nHeight = 20;
|
||||
|
||||
initButtons(); // 初始化按钮
|
||||
initTitle(); // 初始化标题标签
|
||||
initCloseButton(); // 初始化关闭按钮
|
||||
|
||||
Reference in New Issue
Block a user