Refactor layout pipeline, add KEY5 regression, and fix tooltip hide

This commit is contained in:
Codex
2026-04-10 23:26:25 +08:00
parent 241a564095
commit b7ad960518
13 changed files with 719 additions and 290 deletions
+215 -1
View File
@@ -1,6 +1,220 @@
// StellarX 星垣GUI框架 - 测试用例
#include"StellarX.h"
#define KEY 4
#ifndef KEY
#define KEY 5
#endif
#if 5 == KEY
#include"StellarX.h"
int main()
{
StellarX::SxLogger::setGBK();
StellarX::SxLogger::Get().enableConsole(true);
StellarX::SxLogger::Get().setMinLevel(StellarX::SxLogLevel::Debug);
StellarX::SxLogger::Get().setLanguage(StellarX::SxLogLanguage::ZhCN);
const COLORREF headerColor = RGB(232, 238, 245);
const COLORREF horizontalColor = RGB(217, 233, 252);
const COLORREF nestedColor = RGB(219, 244, 223);
const COLORREF verticalColor = RGB(255, 233, 205);
const COLORREF tableZoneColor = RGB(235, 226, 250);
const COLORREF movingColor = RGB(249, 224, 232);
Window win(1280, 780, 1, RGB(246, 248, 251), "StellarX 布局系统专项回归 KEY5");
auto header = std::make_unique<Canvas>(20, 20, 1240, 100);
auto headerPtr = header.get();
headerPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
headerPtr->setCanvasBkColor(headerColor);
headerPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
headerPtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto headerTitle = std::make_unique<Label>(18, 8, "KEY5:布局系统专项回归");
headerTitle->textStyle.nHeight = 26;
headerTitle->setTextdisap(true);
auto headerLine1 = std::make_unique<Label>(18, 46, "观察点 1:蓝色区域横向拉伸;绿色嵌套区域随父容器一起变化。");
headerLine1->setTextdisap(true);
auto headerLine2 = std::make_unique<Label>(18, 70, "观察点 2:橙色区域纵向拉伸;紫色区域中 Table 只做横向拉伸;粉色区域整体随底边移动。");
headerLine2->setTextdisap(true);
headerPtr->addControl(std::move(headerTitle));
headerPtr->addControl(std::move(headerLine1));
headerPtr->addControl(std::move(headerLine2));
auto horizontalZone = std::make_unique<Canvas>(20, 140, 1240, 220);
auto horizontalZonePtr = horizontalZone.get();
horizontalZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
horizontalZonePtr->setCanvasBkColor(horizontalColor);
horizontalZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
horizontalZonePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto horizontalTitle = std::make_unique<Label>(18, 10, "区域 A(蓝):顶层 Left+Right 拉伸,内部同时验证 Left only / Right only / NoAnchor / 嵌套 Canvas。");
horizontalTitle->setTextdisap(true);
auto fixedLabel = std::make_unique<Label>(18, 42, "固定参考标签:不设置锚点");
fixedLabel->setTextdisap(true);
auto leftFixedBtn = std::make_unique<Button>(18, 78, 130, 36, "左边固定");
leftFixedBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
leftFixedBtn->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::NoAnchor);
auto rightFixedBtn = std::make_unique<Button>(1090, 78, 130, 36, "右边固定");
rightFixedBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
rightFixedBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
auto stretchBox = std::make_unique<TextBox>(178, 78, 892, 36, "左右拉伸输入框:窗口变宽时我会伸长");
stretchBox->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
stretchBox->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto nestedZone = std::make_unique<Canvas>(80, 126, 1080, 78);
auto nestedZonePtr = nestedZone.get();
nestedZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
nestedZonePtr->setCanvasBkColor(nestedColor);
nestedZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
nestedZonePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto nestedTitle = std::make_unique<Label>(12, 10, "区域 A-1(绿):嵌套 Canvas。父容器拉伸后,这里的左右锚点和世界坐标都要同步更新。");
nestedTitle->setTextdisap(true);
auto nestedLeftBtn = std::make_unique<Button>(18, 40, 120, 30, "内层左固定");
nestedLeftBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
nestedLeftBtn->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::NoAnchor);
auto nestedRightBtn = std::make_unique<Button>(942, 40, 120, 30, "内层右固定");
nestedRightBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
nestedRightBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
nestedZonePtr->addControl(std::move(nestedTitle));
nestedZonePtr->addControl(std::move(nestedLeftBtn));
nestedZonePtr->addControl(std::move(nestedRightBtn));
horizontalZonePtr->addControl(std::move(horizontalTitle));
horizontalZonePtr->addControl(std::move(fixedLabel));
horizontalZonePtr->addControl(std::move(leftFixedBtn));
horizontalZonePtr->addControl(std::move(rightFixedBtn));
horizontalZonePtr->addControl(std::move(stretchBox));
horizontalZonePtr->addControl(std::move(nestedZone));
auto verticalZone = std::make_unique<Canvas>(20, 380, 420, 278);
auto verticalZonePtr = verticalZone.get();
verticalZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
verticalZonePtr->setCanvasBkColor(verticalColor);
verticalZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
verticalZonePtr->setAnchor(StellarX::Anchor::Top, StellarX::Anchor::Bottom);
auto verticalTitle = std::make_unique<Label>(18, 14, "区域 B(橙):Top+Bottom 拉伸,Bottom only 控件要随底边移动。");
verticalTitle->setTextdisap(true);
verticalTitle->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
verticalTitle->setAnchor(StellarX::Anchor::Top, StellarX::Anchor::NoAnchor);
auto verticalHint = std::make_unique<Label>(18, 88, "中部参考标签:不设置锚点,用来观察固定位置。");
verticalHint->setTextdisap(true);
auto bottomBox = std::make_unique<TextBox>(22, 204, 220, 34, "底边固定输入框");
bottomBox->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
bottomBox->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
auto bottomBtn = std::make_unique<Button>(270, 204, 120, 34, "底边固定");
bottomBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
bottomBtn->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
verticalZonePtr->addControl(std::move(verticalTitle));
verticalZonePtr->addControl(std::move(verticalHint));
verticalZonePtr->addControl(std::move(bottomBox));
verticalZonePtr->addControl(std::move(bottomBtn));
auto tabControl = std::make_unique<TabControl>(460, 380, 800, 168);
auto tabControlPtr = tabControl.get();
tabControlPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
tabControlPtr->setCanvasfillMode(StellarX::FillMode::Null);
tabControlPtr->setTabPlacement(StellarX::TabPlacement::Top);
tabControlPtr->setTabBarHeight(28);
tabControlPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
tabControlPtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto tabPage1 = std::make_unique<Canvas>(0, 0, 800, 132);
auto tabPage1Ptr = tabPage1.get();
tabPage1Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
tabPage1Ptr->setCanvasBkColor(RGB(241, 247, 255));
auto tabPage2 = std::make_unique<Canvas>(0, 0, 800, 132);
auto tabPage2Ptr = tabPage2.get();
tabPage2Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
tabPage2Ptr->setCanvasBkColor(RGB(248, 244, 236));
auto page1Label = std::make_unique<Label>(16, 12, "区域 C(页 1):TabControl 外层参与统一解算,页内 TextBox 继续由 Canvas 负责拉伸。");
page1Label->setTextdisap(true);
auto page1Box = std::make_unique<TextBox>(20, 52, 650, 34, "页内左右拉伸输入框");
page1Box->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
page1Box->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto page1Btn = std::make_unique<Button>(692, 52, 90, 34, "右固定");
page1Btn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
page1Btn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
tabPage1Ptr->addControl(std::move(page1Label));
tabPage1Ptr->addControl(std::move(page1Box));
tabPage1Ptr->addControl(std::move(page1Btn));
auto page2Label = std::make_unique<Label>(16, 18, "区域 C(页 2):切页后再次拖动窗口,页签栏和页区域都应保持稳定。");
page2Label->setTextdisap(true);
auto page2Btn = std::make_unique<Button>(20, 60, 120, 34, "普通按钮");
tabPage2Ptr->addControl(std::move(page2Label));
tabPage2Ptr->addControl(std::move(page2Btn));
tabControlPtr->add(std::make_pair(std::make_unique<Button>(0, 0, 120, 28, "布局页"), std::move(tabPage1)));
tabControlPtr->add(std::make_pair(std::make_unique<Button>(0, 0, 120, 28, "切换页"), std::move(tabPage2)));
tabControlPtr->setActiveIndex(0);
auto tableZone = std::make_unique<Canvas>(460, 566, 800, 132);
auto tableZonePtr = tableZone.get();
tableZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
tableZonePtr->setCanvasBkColor(tableZoneColor);
tableZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
tableZonePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
auto tableTitle = std::make_unique<Label>(16, 10, "区域 D(紫):Table 当前只回归 X 轴拉伸,不做 Y 轴拉伸。");
tableTitle->setTextdisap(true);
auto table = std::make_unique<Table>(20, 46);
auto tablePtr = table.get();
tablePtr->setHeaders({ "编号", "回归点", "预期" });
tablePtr->setData({
{"01", "左右拉伸", "窗口变宽后列宽一起增大"},
{"02", "纵向固定", "表格高度保持当前设计值"},
{"03", "页脚重排", "分页按钮和页码随宽度重排"}
});
tablePtr->setRowsPerPage(2);
tablePtr->setTableBorderWidth(1);
tablePtr->setTableBorder(RGB(86, 88, 132));
tablePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
tablePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
tableZonePtr->addControl(std::move(tableTitle));
tableZonePtr->addControl(std::move(table));
auto movingZone = std::make_unique<Canvas>(934, 706, 326, 70);
auto movingZonePtr = movingZone.get();
movingZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
movingZonePtr->setCanvasBkColor(movingColor);
movingZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
movingZonePtr->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
auto movingLabel = std::make_unique<Label>(14, 10, "区域 E(粉):Bottom only 容器。");
movingLabel->setTextdisap(true);
auto movingHint = std::make_unique<Label>(14, 30, "窗口变高时整体向下移动。");
movingHint->setTextdisap(true);
auto movingBtn = std::make_unique<Button>(208, 38, 100, 24, "右固定");
movingBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
movingBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
movingZonePtr->addControl(std::move(movingLabel));
movingZonePtr->addControl(std::move(movingHint));
movingZonePtr->addControl(std::move(movingBtn));
win.addControl(std::move(header));
win.addControl(std::move(horizontalZone));
win.addControl(std::move(verticalZone));
win.addControl(std::move(tabControl));
win.addControl(std::move(tableZone));
win.addControl(std::move(movingZone));
win.draw();
return win.runEventLoop();
}
#endif
#if 1 == KEY
int main()