1333 lines
57 KiB
C++
1333 lines
57 KiB
C++
// StellarX 星垣GUI框架 - 测试用例
|
||
#include"StellarX.h"
|
||
#include <vector>
|
||
#ifndef KEY
|
||
#define KEY 4
|
||
#endif
|
||
|
||
#if 5 == KEY
|
||
|
||
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 nestedZoneColor = RGB(217, 233, 252);
|
||
const COLORREF level1Color = RGB(224, 244, 255);
|
||
const COLORREF level2Color = RGB(222, 244, 228);
|
||
const COLORREF level3Color = RGB(255, 239, 215);
|
||
const COLORREF tabZoneColor = RGB(220, 241, 240);
|
||
const COLORREF behaviorZoneColor = RGB(243, 238, 214);
|
||
const COLORREF overlayZoneColor = RGB(255, 228, 206);
|
||
const COLORREF tableZoneColor = RGB(235, 226, 250);
|
||
const COLORREF floatingColor = RGB(249, 224, 232);
|
||
const COLORREF buttonFalseColor = RGB(246, 247, 249);
|
||
const COLORREF buttonHoverColor = RGB(255, 225, 92);
|
||
const COLORREF buttonTrueColor = RGB(236, 138, 88);
|
||
|
||
Window win(1380, 880, 1, RGB(246, 248, 251), "StellarX KEY5 第二阶段专项回归");
|
||
|
||
auto configureTooltip = [](Button* button, const std::string& text)
|
||
{
|
||
button->enableTooltip(true);
|
||
button->setTooltipDelay(120);
|
||
button->setTooltipText(text);
|
||
};
|
||
auto makeTestButton = [&](int x, int y, int width, int height, const std::string& text)
|
||
{
|
||
auto button = std::make_unique<Button>(x, y, width, height, text, buttonTrueColor, buttonFalseColor, buttonHoverColor);
|
||
configureTooltip(button.get(), text);
|
||
return button;
|
||
};
|
||
|
||
auto header = std::make_unique<Canvas>(20, 20, 1340, 90);
|
||
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->setDirty(true);
|
||
headerTitle->setTextdisap(true);
|
||
auto headerLine1 = std::make_unique<Label>(18, 44, "A 三层嵌套 B TabControl C Label/跨容器 hover D 同父 overlay E Table/顶层浮层");
|
||
headerLine1->setTextdisap(true);
|
||
auto headerLine2 = std::make_unique<Label>(18, 64, "重点看:stretch、父局部到世界坐标、tooltip 清理、overlay 补画、分页按钮与页码");
|
||
headerLine2->setTextdisap(true);
|
||
headerPtr->addControl(std::move(headerTitle));
|
||
headerPtr->addControl(std::move(headerLine1));
|
||
headerPtr->addControl(std::move(headerLine2));
|
||
|
||
auto nestedZone = std::make_unique<Canvas>(20, 130, 650, 280);
|
||
auto nestedZonePtr = nestedZone.get();
|
||
nestedZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
nestedZonePtr->setCanvasBkColor(nestedZoneColor);
|
||
nestedZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
nestedZonePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto nestedTitle = std::make_unique<Label>(16, 16, "A 蓝:三层 Canvas 嵌套");
|
||
nestedTitle->setTextdisap(true);
|
||
auto nestedHint = std::make_unique<Label>(16, 40, "看父局部到世界坐标链。");
|
||
nestedHint->setTextdisap(true);
|
||
|
||
auto nestedLeftBtn = makeTestButton(20, 74, 110, 34, "左固定");
|
||
nestedLeftBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
nestedLeftBtn->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::NoAnchor);
|
||
|
||
auto nestedStretchBox = std::make_unique<TextBox>(150, 74, 350, 34, "A 区横向拉伸输入框");
|
||
nestedStretchBox->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
nestedStretchBox->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto nestedRightBtn = makeTestButton(520, 74, 110, 34, "右固定");
|
||
nestedRightBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
nestedRightBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
|
||
auto level1 = std::make_unique<Canvas>(18, 126, 614, 134);
|
||
auto level1Ptr = level1.get();
|
||
level1Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
level1Ptr->setCanvasBkColor(level1Color);
|
||
level1Ptr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
level1Ptr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto level1Title = std::make_unique<Label>(14, 10, "A-1 青:第一层");
|
||
level1Title->setTextdisap(true);
|
||
auto level1Btn = makeTestButton(18, 42, 110, 30, "内层左");
|
||
level1Btn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
level1Btn->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::NoAnchor);
|
||
|
||
auto level2 = std::make_unique<Canvas>(142, 36, 454, 84);
|
||
auto level2Ptr = level2.get();
|
||
level2Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
level2Ptr->setCanvasBkColor(level2Color);
|
||
level2Ptr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
level2Ptr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto level2Title = std::make_unique<Label>(12, 8, "A-2 绿:第二层");
|
||
level2Title->setTextdisap(true);
|
||
auto level2Btn = makeTestButton(332, 8, 108, 28, "右固定");
|
||
level2Btn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
level2Btn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
|
||
auto level3 = std::make_unique<Canvas>(16, 42, 422, 28);
|
||
auto level3Ptr = level3.get();
|
||
level3Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
level3Ptr->setCanvasBkColor(level3Color);
|
||
level3Ptr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
level3Ptr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto level3Label = std::make_unique<Label>(10, 6, "A-3 橙:第三层");
|
||
level3Label->setTextdisap(true);
|
||
auto level3Btn = makeTestButton(312, 2, 98, 24, "右按钮");
|
||
level3Btn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
level3Btn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(level3Btn.get(), "第三层 Canvas 里的右固定按钮");
|
||
|
||
level3Ptr->addControl(std::move(level3Label));
|
||
level3Ptr->addControl(std::move(level3Btn));
|
||
level2Ptr->addControl(std::move(level2Title));
|
||
level2Ptr->addControl(std::move(level2Btn));
|
||
level2Ptr->addControl(std::move(level3));
|
||
level1Ptr->addControl(std::move(level1Title));
|
||
level1Ptr->addControl(std::move(level1Btn));
|
||
level1Ptr->addControl(std::move(level2));
|
||
|
||
nestedZonePtr->addControl(std::move(nestedTitle));
|
||
nestedZonePtr->addControl(std::move(nestedHint));
|
||
nestedZonePtr->addControl(std::move(nestedLeftBtn));
|
||
nestedZonePtr->addControl(std::move(nestedStretchBox));
|
||
nestedZonePtr->addControl(std::move(nestedRightBtn));
|
||
nestedZonePtr->addControl(std::move(level1));
|
||
|
||
auto tabZone = std::make_unique<Canvas>(690, 130, 670, 280);
|
||
auto tabZonePtr = tabZone.get();
|
||
tabZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
tabZonePtr->setCanvasBkColor(tabZoneColor);
|
||
tabZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
tabZonePtr->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
|
||
auto tabTitle = std::make_unique<Label>(16, 16, "B 青:TabControl 外层 resize");
|
||
tabTitle->setTextdisap(true);
|
||
auto tabHint = std::make_unique<Label>(16, 40, "看页签、页面和页内控件。");
|
||
tabHint->setTextdisap(true);
|
||
|
||
auto tabControl = std::make_unique<TabControl>(18, 60, 634, 200);
|
||
auto tabControlPtr = tabControl.get();
|
||
tabControlPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
tabControlPtr->setCanvasfillMode(StellarX::FillMode::Null);
|
||
tabControlPtr->setTabPlacement(StellarX::TabPlacement::Top);
|
||
tabControlPtr->setTabBarHeight(30);
|
||
tabControlPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
tabControlPtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto tabPage1 = std::make_unique<Canvas>(0, 0, 634, 170);
|
||
auto tabPage1Ptr = tabPage1.get();
|
||
tabPage1Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
tabPage1Ptr->setCanvasBkColor(RGB(241, 247, 255));
|
||
|
||
auto tabPage2 = std::make_unique<Canvas>(0, 0, 634, 170);
|
||
auto tabPage2Ptr = tabPage2.get();
|
||
tabPage2Ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
tabPage2Ptr->setCanvasBkColor(RGB(248, 244, 236));
|
||
|
||
auto page1Label = std::make_unique<Label>(14, 12, "页 1:页内 TextBox 继续由 Canvas 管。");
|
||
page1Label->setTextdisap(true);
|
||
auto page1Box = std::make_unique<TextBox>(18, 44, 468, 34, "页 1 左右拉伸输入框");
|
||
page1Box->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
page1Box->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
auto page1Btn = makeTestButton(504, 44, 96, 34, "右固定");
|
||
page1Btn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
page1Btn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(page1Btn.get(), "页 1 右固定按钮");
|
||
|
||
auto page1InnerCanvas = std::make_unique<Canvas>(18, 92, 582, 56);
|
||
auto page1InnerCanvasPtr = page1InnerCanvas.get();
|
||
page1InnerCanvasPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
page1InnerCanvasPtr->setCanvasBkColor(RGB(223, 236, 248));
|
||
page1InnerCanvasPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
page1InnerCanvasPtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto page1InnerLabel = std::make_unique<Label>(10, 8, "页 1 内层 Canvas");
|
||
page1InnerLabel->setTextdisap(true);
|
||
auto page1InnerBtn = makeTestButton(462, 14, 108, 28, "右按钮");
|
||
page1InnerBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
page1InnerBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(page1InnerBtn.get(), "页 1 内层 Canvas 按钮");
|
||
|
||
page1InnerCanvasPtr->addControl(std::move(page1InnerLabel));
|
||
page1InnerCanvasPtr->addControl(std::move(page1InnerBtn));
|
||
tabPage1Ptr->addControl(std::move(page1Label));
|
||
tabPage1Ptr->addControl(std::move(page1Box));
|
||
tabPage1Ptr->addControl(std::move(page1Btn));
|
||
tabPage1Ptr->addControl(std::move(page1InnerCanvas));
|
||
|
||
auto page2Label = std::make_unique<Label>(14, 12, "页 2:切页后继续测 hover 和 resize。");
|
||
page2Label->setTextdisap(true);
|
||
auto page2Btn = makeTestButton(18, 44, 126, 34, "Tooltip 按钮");
|
||
configureTooltip(page2Btn.get(), "页 2 普通按钮 Tooltip");
|
||
|
||
auto page2InnerCanvas = std::make_unique<Canvas>(166, 36, 434, 84);
|
||
auto page2InnerCanvasPtr = page2InnerCanvas.get();
|
||
page2InnerCanvasPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
page2InnerCanvasPtr->setCanvasBkColor(RGB(235, 229, 214));
|
||
|
||
auto page2InnerLabel = std::make_unique<Label>(10, 8, "页 2 内层 Canvas");
|
||
page2InnerLabel->setTextdisap(true);
|
||
auto page2InnerBtn = makeTestButton(286, 42, 126, 28, "右侧 Tooltip");
|
||
page2InnerBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
page2InnerBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(page2InnerBtn.get(), "页 2 内层按钮 Tooltip");
|
||
|
||
page2InnerCanvasPtr->addControl(std::move(page2InnerLabel));
|
||
page2InnerCanvasPtr->addControl(std::move(page2InnerBtn));
|
||
tabPage2Ptr->addControl(std::move(page2Label));
|
||
tabPage2Ptr->addControl(std::move(page2Btn));
|
||
tabPage2Ptr->addControl(std::move(page2InnerCanvas));
|
||
|
||
auto tabBtn1 = std::make_unique<Button>(0, 0, 108, 30, "布局页");
|
||
auto tabBtn2 = std::make_unique<Button>(0, 0, 108, 30, "交互页");
|
||
configureTooltip(tabBtn1.get(), "布局页页签按钮");
|
||
configureTooltip(tabBtn2.get(), "交互页页签按钮");
|
||
tabControlPtr->add(std::make_pair(std::move(tabBtn1), std::move(tabPage1)));
|
||
tabControlPtr->add(std::make_pair(std::move(tabBtn2), std::move(tabPage2)));
|
||
tabControlPtr->setActiveIndex(0);
|
||
|
||
tabZonePtr->addControl(std::move(tabTitle));
|
||
tabZonePtr->addControl(std::move(tabHint));
|
||
tabZonePtr->addControl(std::move(tabControl));
|
||
|
||
auto behaviorZone = std::make_unique<Canvas>(20, 430, 650, 190);
|
||
auto behaviorZonePtr = behaviorZone.get();
|
||
behaviorZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
behaviorZonePtr->setCanvasBkColor(behaviorZoneColor);
|
||
|
||
auto behaviorTitle = std::make_unique<Label>(16, 16, "C 米:Label 内容驱动 + 跨容器 hover");
|
||
behaviorTitle->setTextdisap(true);
|
||
|
||
auto dynamicLabel = std::make_unique<Label>(20, 52, "动态标签:默认短文本");
|
||
auto dynamicLabelPtr = dynamicLabel.get();
|
||
dynamicLabelPtr->textStyle.nHeight = 22;
|
||
dynamicLabelPtr->setDirty(true);
|
||
dynamicLabelPtr->setTextdisap(true);
|
||
|
||
auto behaviorHint = std::make_unique<Label>(20, 82, "改样式后会手动 setDirty(true)。");
|
||
behaviorHint->setTextdisap(true);
|
||
|
||
std::vector<std::string> labelTexts =
|
||
{
|
||
"动态标签:默认短文本",
|
||
"动态标签:切到更长一点的文本",
|
||
"动态标签:短"
|
||
};
|
||
int labelIndex = 0;
|
||
bool styleToggle = false;
|
||
|
||
auto changeTextBtn = makeTestButton(20, 120, 120, 34, "改文本");
|
||
auto changeStyleBtn = makeTestButton(156, 120, 150, 34, "改样式");
|
||
changeTextBtn->setOnClickListener([&]()
|
||
{
|
||
labelIndex = (labelIndex + 1) % static_cast<int>(labelTexts.size());
|
||
dynamicLabelPtr->setText(labelTexts[labelIndex]);
|
||
});
|
||
changeStyleBtn->setOnClickListener([&]()
|
||
{
|
||
styleToggle = !styleToggle;
|
||
dynamicLabelPtr->textStyle.nHeight = styleToggle ? 30 : 22;
|
||
dynamicLabelPtr->textStyle.color = styleToggle ? RGB(184, 87, 44) : RGB(0, 0, 0);
|
||
dynamicLabelPtr->setDirty(true);
|
||
});
|
||
|
||
auto innerHoverBtn = makeTestButton(506, 120, 118, 34, "容器内按钮");
|
||
innerHoverBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
innerHoverBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(innerHoverBtn.get(), "Canvas 内按钮 Tooltip");
|
||
|
||
behaviorZonePtr->addControl(std::move(behaviorTitle));
|
||
behaviorZonePtr->addControl(std::move(dynamicLabel));
|
||
behaviorZonePtr->addControl(std::move(behaviorHint));
|
||
behaviorZonePtr->addControl(std::move(changeTextBtn));
|
||
behaviorZonePtr->addControl(std::move(changeStyleBtn));
|
||
behaviorZonePtr->addControl(std::move(innerHoverBtn));
|
||
|
||
auto overlayZone = std::make_unique<Canvas>(690, 430, 670, 190);
|
||
auto overlayZonePtr = overlayZone.get();
|
||
overlayZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
overlayZonePtr->setCanvasBkColor(overlayZoneColor);
|
||
overlayZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
overlayZonePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto overlayTitle = std::make_unique<Label>(16, 16, "D 橙:Top+Bottom + 同父 overlay");
|
||
overlayTitle->setTextdisap(true);
|
||
|
||
auto lowerLayer = std::make_unique<Canvas>(20, 56, 356, 104);
|
||
auto lowerLayerPtr = lowerLayer.get();
|
||
lowerLayerPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
lowerLayerPtr->setCanvasBkColor(RGB(255, 245, 231));
|
||
lowerLayerPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
lowerLayerPtr->setAnchor(StellarX::Anchor::Top, StellarX::Anchor::Bottom);
|
||
|
||
auto lowerTitle = std::make_unique<Label>(12, 8, "D-1 下层区");
|
||
lowerTitle->setTextdisap(true);
|
||
auto lowerBox = std::make_unique<TextBox>(12, 34, 222, 30, "下层区输入框");
|
||
lowerBox->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
lowerBox->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
auto lowerBtn = makeTestButton(248, 34, 92, 30, "下层按钮");
|
||
lowerBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
lowerBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(lowerBtn.get(), "下层 Canvas 按钮");
|
||
|
||
lowerLayerPtr->addControl(std::move(lowerTitle));
|
||
lowerLayerPtr->addControl(std::move(lowerBox));
|
||
lowerLayerPtr->addControl(std::move(lowerBtn));
|
||
|
||
auto upperLayer = std::make_unique<Canvas>(262, 94, 382, 78);
|
||
auto upperLayerPtr = upperLayer.get();
|
||
upperLayerPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
upperLayerPtr->setCanvasBkColor(RGB(255, 224, 206));
|
||
upperLayerPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
upperLayerPtr->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
|
||
auto upperTitle = std::make_unique<Label>(12, 8, "D-2 上层区");
|
||
upperTitle->setTextdisap(true);
|
||
auto upperBtn = makeTestButton(244, 38, 122, 28, "上层 Tooltip");
|
||
upperBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
upperBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(upperBtn.get(), "上层 Canvas 按钮");
|
||
|
||
upperLayerPtr->addControl(std::move(upperTitle));
|
||
upperLayerPtr->addControl(std::move(upperBtn));
|
||
|
||
auto overlayBottomBtn = makeTestButton(526, 148, 118, 30, "底边固定");
|
||
overlayBottomBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
overlayBottomBtn->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||
|
||
overlayZonePtr->addControl(std::move(overlayTitle));
|
||
overlayZonePtr->addControl(std::move(lowerLayer));
|
||
overlayZonePtr->addControl(std::move(upperLayer));
|
||
overlayZonePtr->addControl(std::move(overlayBottomBtn));
|
||
|
||
auto tableZone = std::make_unique<Canvas>(20, 640, 980, 200);
|
||
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, 12, "E 紫:Table 仅 X Stretch");
|
||
tableTitle->setTextdisap(true);
|
||
auto tableHint = std::make_unique<Label>(16, 34, "看翻页按钮、页码和顶层浮层补画。");
|
||
tableHint->setTextdisap(true);
|
||
|
||
auto table = std::make_unique<Table>(20, 62);
|
||
auto tablePtr = table.get();
|
||
tablePtr->setHeaders({ "编号", "回归点", "预期" });
|
||
tablePtr->setData({
|
||
{"01", "左右拉伸", "窗口变宽后列宽一起增大"},
|
||
{"02", "分页按钮", "hover / click / leave 都能及时刷新"},
|
||
{"03", "页码标签", "整表重绘后不会消失"},
|
||
{"04", "顶层浮层", "下层重绘后上层还能补回来"}
|
||
});
|
||
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(tableHint));
|
||
tableZonePtr->addControl(std::move(table));
|
||
|
||
auto topHoverBtn = makeTestButton(646, 550, 118, 34, "顶层按钮");
|
||
configureTooltip(topHoverBtn.get(), "顶层按钮 Tooltip");
|
||
|
||
auto floatingZone = std::make_unique<Canvas>(900, 702, 460, 138);
|
||
auto floatingZonePtr = floatingZone.get();
|
||
floatingZonePtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
floatingZonePtr->setCanvasBkColor(floatingColor);
|
||
floatingZonePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
floatingZonePtr->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||
|
||
auto floatingTitle = std::make_unique<Label>(16, 12, "F 粉:Bottom only 浮层");
|
||
floatingTitle->setTextdisap(true);
|
||
auto floatingHint = std::make_unique<Label>(16, 36, "看 Table 下层重绘后的补画。");
|
||
floatingHint->setTextdisap(true);
|
||
auto floatingBtn = makeTestButton(322, 88, 118, 30, "右固定");
|
||
floatingBtn->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
floatingBtn->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::NoAnchor);
|
||
configureTooltip(floatingBtn.get(), "粉色浮层里的按钮");
|
||
|
||
floatingZonePtr->addControl(std::move(floatingTitle));
|
||
floatingZonePtr->addControl(std::move(floatingHint));
|
||
floatingZonePtr->addControl(std::move(floatingBtn));
|
||
|
||
win.addControl(std::move(header));
|
||
win.addControl(std::move(nestedZone));
|
||
win.addControl(std::move(tabZone));
|
||
win.addControl(std::move(behaviorZone));
|
||
win.addControl(std::move(topHoverBtn));
|
||
win.addControl(std::move(overlayZone));
|
||
win.addControl(std::move(tableZone));
|
||
win.addControl(std::move(floatingZone));
|
||
|
||
win.draw();
|
||
return win.runEventLoop();
|
||
}
|
||
|
||
#endif
|
||
|
||
#if 1 == KEY
|
||
int main()
|
||
{
|
||
//StellarX::SxLogger::setGBK();
|
||
//StellarX::SxLogger::Get().enableFile("stellarx.log", false, 1024);
|
||
StellarX::SxLogger::Get().enableConsole(true);
|
||
StellarX::SxLogger::Get().setMinLevel(StellarX::SxLogLevel::Debug); // Info/Debug/Trace 自己切
|
||
StellarX::SxLogger::Get().setLanguage(StellarX::SxLogLanguage::ZhCN); // ZhCN / EnUS
|
||
|
||
Window mainWindow(1200, 400, 1, RGB(255, 0, 0), "StellarX Hello");
|
||
auto table = std::make_unique<Table>(200, 50);
|
||
Table* table_ptr = table.get();
|
||
table->setHeaders({ "name","age","seorc","home" });
|
||
table->setData({
|
||
{"zhangsan","20","99.99","wadsacafadsawd"},
|
||
{"lisi","20","99.99","wadsacafadssssssssssssssssssssssssssssssssssssssssssssssssssawd"},
|
||
{"wangwu","20","99.99","wadsacafadsawd"},
|
||
{"zhaoliu","20","99.99","wadsacafadsawd"},
|
||
{"1","20","99.99","wadsacafadsawd" },
|
||
{"2","20","99.99","wadsacafadsawd" } ,
|
||
{"3","20","99.99","wadsacafadsawd" } ,
|
||
{"4","20","99.99","wadsacafadsawd" },
|
||
{"5","20","99.99","wadsacafadsawd" } ,
|
||
{"6","20","99.99","wadsacafadsawd" } ,
|
||
{"7","20","99.99","wadsacvvvvvvv我afads" } ,
|
||
{"8","2000000000000000000","99.999999999999","wadsacafa0000000d0000000sawd" } ,
|
||
{"9555555555","2000","99.9999999","wadsacafadsawd" } });
|
||
table->setRowsPerPage(4);
|
||
table->setTableBorderWidth(1);
|
||
table->textStyle.color = RGB(255, 0, 0);
|
||
table->setTableBorder(RGB(255, 0, 0));
|
||
table->setTableFillMode(StellarX::FillMode::Null);
|
||
|
||
auto but = std::make_unique<Button>(0, 0, 100, 15, "按钮1");
|
||
auto ta = std::make_unique<TabControl>(10, 10, 1100, 300);
|
||
ta->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
ta->setActiveIndex(2);
|
||
|
||
std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>> p;
|
||
std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>> p1;
|
||
std::pair<std::unique_ptr<Button>, std::unique_ptr<Canvas>> p2;
|
||
p2.first = std::make_unique<Button>(0, 0, 100, 15, "按钮3");
|
||
p2.second = std::make_unique<Canvas>(200, 200, 1100, 280);
|
||
p2.second->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
|
||
p1.first = std::make_unique<Button>(0, 0, 100, 15, "按钮2");
|
||
p1.second = std::make_unique<Canvas>(200, 200, 1100, 280);
|
||
p1.second->setCanvasBkColor(RGB(255, 200, 0));
|
||
p.first = std::move(but);
|
||
p.second = std::make_unique<Canvas>(100, 100, 1100, 280);
|
||
p.second->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
p.second->setCanvasBkColor(RGB(0, 255, 0));
|
||
p.second->setCanvasfillMode(StellarX::FillMode::Null);
|
||
auto table_get = table.get();
|
||
p.second->addControl(std::move(table));
|
||
ta->setTabPlacement(StellarX::TabPlacement::Bottom);
|
||
|
||
auto b = std::make_unique<Button>(0, 0, 100, 35, "按钮");
|
||
b->setOnClickListener([&]()
|
||
{
|
||
/* StellarX::MessageBox::showAsync(mainWindow, "韦世豪大傻逼", "笑话", StellarX::MessageBoxType::AbortRetryIgnore,
|
||
[](StellarX::MessageBoxResult result) { if (StellarX::MessageBoxResult::Retry == result)std::cout << "\a"; });
|
||
*/
|
||
table_ptr->clearHeaders();
|
||
table_ptr->clearData();
|
||
table_ptr->setHeaders({ "new_name","new_age","new_seorc","new""_home","new_test"});
|
||
table_ptr->setData({
|
||
{"new_zhangsan","30","88.88","new_wadsacafadsawd","123"},
|
||
{"new_lisi","30","88.88","new_wadsacafadsawd","456"},
|
||
{"new_wangwu","30","88.88","new_wadsacafadsawd","789"},
|
||
{"new_zhaoliu","30","88.88","new_wadsacafadsawd","101"} });
|
||
table_ptr->setData({"test_zhaoliu","test_30","88.88","test_wadsacafadsawd","test_101"});
|
||
|
||
|
||
});
|
||
p.second->addControl(std::move(b));
|
||
ta->add(std::move(p));
|
||
ta->add(std::move(p1));
|
||
ta->add(std::move(p2));
|
||
ta->setTabBarHeight(20);
|
||
ta->setCanvasfillMode(StellarX::FillMode::Null);
|
||
auto ta_ptr = ta.get();
|
||
auto test = std::make_unique<Button>(1100, 350, 40, 40, "test");
|
||
auto test_ptr = test.get();
|
||
test->setOnClickListener([&]()
|
||
{
|
||
ta_ptr->setActiveIndex(0);
|
||
});
|
||
//auto testTextBox = std::make_unique<TextBox>(100, 350, 80, 30);
|
||
auto testTextBox = std::make_unique<TextBox>(0, 0, 80, 30);
|
||
testTextBox->setText("hello");
|
||
auto _123 = std::make_unique<Canvas>(100, 340, 180, 130);
|
||
_123->addControl(std::move(testTextBox));
|
||
_123->setCanvasfillMode(StellarX::FillMode::Null);
|
||
|
||
mainWindow.addControl(std::move(ta));
|
||
mainWindow.addControl(std::move(test));
|
||
mainWindow.addControl(std::move(_123));
|
||
|
||
mainWindow.draw("D:\\编程相关\\素材\\星垣logo.png");
|
||
mainWindow.runEventLoop();
|
||
}
|
||
#endif
|
||
|
||
#if 4 == KEY
|
||
|
||
#include"StellarX.h"
|
||
#include <vector>
|
||
|
||
int main()
|
||
{
|
||
StellarX::SxLogger::setGBK();
|
||
StellarX::SxLogger::Get().enableConsole(true);
|
||
StellarX::SxLogger::Get().setMinLevel(StellarX::SxLogLevel::Debug);
|
||
StellarX::SxLogger::Get().setLanguage(StellarX::SxLogLanguage::ZhCN);
|
||
|
||
Window win(1280, 780, 1, RGB(242, 246, 250), "StellarX 综合回归测试用例 4");
|
||
|
||
auto infoPanel = std::make_unique<Canvas>(20, 20, 1240, 90);
|
||
auto infoPanelPtr = infoPanel.get();
|
||
infoPanelPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
infoPanelPtr->setCanvasBkColor(RGB(225, 234, 244));
|
||
infoPanelPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
infoPanelPtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto infoTitle = std::make_unique<Label>(20, 10, "综合回归测试 4:对话框遮挡、快速 Hover、分页按钮、模态 Resize");
|
||
infoTitle->textStyle.nHeight = 26;
|
||
infoTitle->setTextdisap(true);
|
||
auto infoLine1 = std::make_unique<Label>(20, 42, "1. 点击右侧按钮打开非模态/模态对话框;2. 在顶部按钮、页签、分页按钮附近快速划动光标。");
|
||
infoLine1->setTextdisap(true);
|
||
auto infoLine2 = std::make_unique<Label>(20, 62, "3. 模态对话框打开后拖动窗口大小;4. 关闭对话框后观察底层按钮 Hover 是否立即恢复。");
|
||
infoLine2->setTextdisap(true);
|
||
|
||
auto openAsyncButton = std::make_unique<Button>(930, 22, 130, 42, "打开非模态");
|
||
auto openAsyncButtonPtr = openAsyncButton.get();
|
||
openAsyncButtonPtr->enableTooltip(true);
|
||
openAsyncButtonPtr->setTooltipText("打开长文本非模态对话框,覆盖顶部按钮 / 页签 / 分页区");
|
||
|
||
auto openModalButton = std::make_unique<Button>(1080, 22, 130, 42, "打开模态");
|
||
auto openModalButtonPtr = openModalButton.get();
|
||
openModalButtonPtr->enableTooltip(true);
|
||
openModalButtonPtr->setTooltipText("打开模态对话框并测试拖拽窗口后的重绘与关闭");
|
||
|
||
infoPanelPtr->addControl(std::move(infoTitle));
|
||
infoPanelPtr->addControl(std::move(infoLine1));
|
||
infoPanelPtr->addControl(std::move(infoLine2));
|
||
infoPanelPtr->addControl(std::move(openAsyncButton));
|
||
infoPanelPtr->addControl(std::move(openModalButton));
|
||
|
||
auto hoverCanvas = std::make_unique<Canvas>(20, 140, 1240, 100);
|
||
auto hoverCanvasPtr = hoverCanvas.get();
|
||
hoverCanvasPtr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
hoverCanvasPtr->setCanvasBkColor(RGB(230, 238, 248));
|
||
hoverCanvasPtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
hoverCanvasPtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
auto hoverTitle = std::make_unique<Label>(20, 8, "区域 A:打开非模态对话框后,请在下面 8 个按钮之间快速来回划动鼠标。");
|
||
hoverTitle->setTextdisap(true);
|
||
hoverCanvasPtr->addControl(std::move(hoverTitle));
|
||
|
||
for (int i = 0; i < 8; ++i)
|
||
{
|
||
auto hoverButton = std::make_unique<Button>(250 + i * 92, 38, 72, 38, "B" + std::to_string(i + 1));
|
||
hoverButton->enableTooltip(true);
|
||
hoverButton->setTooltipText("顶部 Hover 按钮 " + std::to_string(i + 1));
|
||
hoverButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
hoverCanvasPtr->addControl(std::move(hoverButton));
|
||
}
|
||
|
||
auto tabControl = std::make_unique<TabControl>(120, 260, 1040, 180);
|
||
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 page1 = std::make_unique<Canvas>(0, 0, 1040, 152);
|
||
page1->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
page1->setCanvasBkColor(RGB(246, 250, 255));
|
||
auto page2 = std::make_unique<Canvas>(0, 0, 1040, 152);
|
||
page2->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
page2->setCanvasBkColor(RGB(250, 248, 242));
|
||
auto page3 = std::make_unique<Canvas>(0, 0, 1040, 152);
|
||
page3->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
page3->setCanvasBkColor(RGB(243, 250, 244));
|
||
|
||
auto tabPage1Ptr = page1.get();
|
||
auto tabPage2Ptr = page2.get();
|
||
auto tabPage3Ptr = page3.get();
|
||
|
||
tabControlPtr->add(std::make_pair(std::make_unique<Button>(0, 0, 120, 28, "页签-事件区"), std::move(page1)));
|
||
tabControlPtr->add(std::make_pair(std::make_unique<Button>(0, 0, 120, 28, "页签-空白区"), std::move(page2)));
|
||
tabControlPtr->add(std::make_pair(std::make_unique<Button>(0, 0, 120, 28, "页签-辅助区"), std::move(page3)));
|
||
tabControlPtr->setActiveIndex(0);
|
||
|
||
auto page1Label = std::make_unique<Label>(20, 10, "区域 B:打开非模态对话框后,切换页签并在页内按钮上快速 Hover。");
|
||
page1Label->setTextdisap(true);
|
||
tabPage1Ptr->addControl(std::move(page1Label));
|
||
for (int i = 0; i < 4; ++i)
|
||
{
|
||
auto pageButton = std::make_unique<Button>(190 + i * 150, 55, 110, 38, "页内按钮" + std::to_string(i + 1));
|
||
pageButton->enableTooltip(true);
|
||
pageButton->setTooltipText("页签区按钮 " + std::to_string(i + 1));
|
||
tabPage1Ptr->addControl(std::move(pageButton));
|
||
}
|
||
|
||
auto page2Label = std::make_unique<Label>(30, 55, "区域 B-2:此页保留较大空白区,用来观察 Hover 离开空白区域时的恢复。");
|
||
page2Label->setTextdisap(true);
|
||
tabPage2Ptr->addControl(std::move(page2Label));
|
||
|
||
auto page3Label = std::make_unique<Label>(20, 18, "区域 B-3:辅助页,用来测试页签切换本身的重绘是否稳定。");
|
||
page3Label->setTextdisap(true);
|
||
auto page3Button = std::make_unique<Button>(420, 65, 180, 40, "辅助按钮");
|
||
page3Button->enableTooltip(true);
|
||
page3Button->setTooltipText("辅助页按钮 Tooltip");
|
||
tabPage3Ptr->addControl(std::move(page3Label));
|
||
tabPage3Ptr->addControl(std::move(page3Button));
|
||
|
||
auto table = std::make_unique<Table>(240, 470);
|
||
auto tablePtr = table.get();
|
||
tablePtr->setHeaders({ "编号", "名称", "状态", "备注" });
|
||
tablePtr->setData({
|
||
{"01", "顶部按钮覆盖测试", "待验证", "快速 Hover 后不能残留高亮"},
|
||
{"02", "页签切换测试", "待验证", "页签按钮与页内容不应穿透"},
|
||
{"03", "分页按钮测试", "待验证", "被非模态部分覆盖时仍应稳定"},
|
||
{"04", "模态 Resize 测试", "待验证", "拖窗后标题、关闭按钮不应残影"},
|
||
{"05", "关闭后 Hover 恢复", "待验证", "模态关闭后底层按钮 Hover 应恢复"}
|
||
});
|
||
tablePtr->setRowsPerPage(2);
|
||
tablePtr->setTableBorderWidth(1);
|
||
tablePtr->setTableBorder(RGB(60, 90, 120));
|
||
tablePtr->setTableFillMode(StellarX::FillMode::Null);
|
||
tablePtr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
tablePtr->setAnchor(StellarX::Anchor::Left, StellarX::Anchor::Right);
|
||
|
||
const std::string asyncText =
|
||
"KEY4 非模态回归测试正在进行。\n"
|
||
"请依次检查以下场景:\n"
|
||
"1. 在顶部按钮之间快速来回移动鼠标。\n"
|
||
"2. 切换页签,并在页签按钮与页内按钮上快速 Hover。\n"
|
||
"3. 将鼠标移动到表格分页按钮附近,观察是否闪烁或穿透。\n"
|
||
"4. 将鼠标移出窗口后再移回窗口。\n"
|
||
"5. 保持本对话框打开,确认它始终位于最上层。\n"
|
||
"6. 若需要重复测试,可直接再次点击右上角按钮。\n"
|
||
"7. 本对话框故意较高,以覆盖顶部按钮、页签区与部分分页区。\n"
|
||
"8. 顶部按钮区域用于检测快速 Hover 残留。\n"
|
||
"9. 页签区域用于检测被遮挡时的切换与 Hover。\n"
|
||
"10. 表格分页区用于检测分页按钮被部分覆盖时的重绘。\n"
|
||
"11. 若关闭本对话框,请观察底层 Hover 是否立即恢复。\n"
|
||
"12. 本消息框保留较多行,是为了增大对遮挡场景的覆盖范围。";
|
||
|
||
const std::string modalText =
|
||
"KEY4 模态回归测试。\n"
|
||
"请在本对话框保持打开时执行:\n"
|
||
"1. 拖拽窗口大小,观察标题、关闭按钮与功能按钮是否残影。\n"
|
||
"2. 拖拽后点击关闭按钮。\n"
|
||
"3. 拖拽后点击功能按钮。\n"
|
||
"4. 对话框关闭后,将鼠标停在底层顶部按钮上,观察 Hover 是否恢复。";
|
||
|
||
openAsyncButtonPtr->setOnClickListener([&win, asyncText]()
|
||
{
|
||
StellarX::MessageBox::showAsync(
|
||
win,
|
||
asyncText,
|
||
"KEY4 非模态综合回归",
|
||
StellarX::MessageBoxType::YesNoCancel,
|
||
[](StellarX::MessageBoxResult result)
|
||
{
|
||
SX_LOGI("KEY4") << "非模态对话框结果=" << (int)result;
|
||
});
|
||
});
|
||
|
||
openModalButtonPtr->setOnClickListener([&win, modalText]()
|
||
{
|
||
auto result = StellarX::MessageBox::showModal(
|
||
win,
|
||
modalText,
|
||
"KEY4 模态综合回归",
|
||
StellarX::MessageBoxType::OKCancel);
|
||
SX_LOGI("KEY4") << "模态对话框结果=" << (int)result;
|
||
});
|
||
|
||
win.addControl(std::move(infoPanel));
|
||
win.addControl(std::move(hoverCanvas));
|
||
win.addControl(std::move(tabControl));
|
||
win.addControl(std::move(table));
|
||
|
||
win.draw();
|
||
return win.runEventLoop();
|
||
}
|
||
|
||
#endif
|
||
|
||
#if 2 == KEY
|
||
// 本工具基于 StellarX 构建,轻量级的 Windows GUI 框架。
|
||
#include"StellarX.h"
|
||
#include <sstream>
|
||
#include<iomanip>
|
||
#include<array>
|
||
|
||
auto blackColor = RGB(202, 255, 255);
|
||
char initData[33] = "00000000000000000000000000000000";//初始数据
|
||
bool gSigned = false; //是否为有符号数
|
||
int main()
|
||
{
|
||
StellarX::SxLogger::Get().enableConsole(true);
|
||
StellarX::SxLogger::Get().setMinLevel(StellarX::SxLogLevel::Debug); // Info/Debug/Trace 自己切
|
||
StellarX::SxLogger::Get().setLanguage(StellarX::SxLogLanguage::ZhCN); // ZhCN / EnUS
|
||
|
||
Window mainWindow(700, 510, 1, RGB(255, 255, 255), "寄存器查看工具 V1.0——我在人间做废物 (同类工具定制:3150131407(Q / V))");
|
||
|
||
//选择区控件
|
||
auto selectionAreaLabel = std::make_unique<Label>(18, 0, "32位选择区");
|
||
selectionAreaLabel->setTextdisap(true);
|
||
std::vector<std::unique_ptr<Label>>selectionAreaButtonLabel;
|
||
std::vector<std::unique_ptr<Button>>selectionAreaButton;
|
||
std::vector<Button*>selectionAreaButton_ptr;
|
||
auto selectionArea = std::make_unique <Canvas>(10, 10, 680, 150);
|
||
|
||
selectionArea->setCanvasBkColor(blackColor);
|
||
selectionArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
|
||
for (int y = 0; y < 2; y++)
|
||
{
|
||
std::ostringstream os;
|
||
for (int x = 0; x < 16; x++)
|
||
{
|
||
if (0 == y)
|
||
{
|
||
selectionAreaButtonLabel.push_back(std::make_unique<Label>(x * 35 + 25 + 28 * (x / 4), 26, "", RGB(208, 208, 208)));
|
||
os << std::setw(2) << std::setfill('0') << 31 - x;
|
||
selectionAreaButtonLabel.back()->setText(os.str());
|
||
selectionAreaButtonLabel.back()->setTextdisap(true);
|
||
|
||
selectionAreaButton.push_back(
|
||
std::make_unique<Button>(x * 35 + 27 + 28 * (x / 4), 58, 25, 30, "0",
|
||
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE));
|
||
selectionAreaButton.back()->textStyle.color = RGB(226, 116, 152);
|
||
selectionAreaButton.back()->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
selectionAreaButton_ptr.push_back(selectionAreaButton.back().get());
|
||
int k = 32 - x - 1;
|
||
//选择区按钮被点击后在二进制0和1之间切换,并更新initData
|
||
selectionAreaButton_ptr.back()->setOnToggleOnListener([k, btn = selectionAreaButton_ptr.back()]()
|
||
{
|
||
btn->setButtonText("1");
|
||
initData[k] = '1';
|
||
});
|
||
selectionAreaButton_ptr.back()->setOnToggleOffListener([k, btn = selectionAreaButton_ptr.back()]()
|
||
{
|
||
btn->setButtonText("0");
|
||
initData[k] = '0';
|
||
});
|
||
}
|
||
else
|
||
{
|
||
selectionAreaButtonLabel.push_back(std::make_unique<Label>(x * 35 + 25 + 28 * (x / 4), 90, "", RGB(208, 208, 208)));
|
||
os << std::setw(2) << std::setfill('0') << 15 - x;
|
||
selectionAreaButtonLabel.back()->setText(os.str());
|
||
selectionAreaButtonLabel.back()->setTextdisap(true);
|
||
|
||
selectionAreaButton.push_back(
|
||
std::make_unique<Button>(x * 35 + 27 + 28 * (x / 4), 120, 25, 30, "0",
|
||
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE));
|
||
selectionAreaButton.back()->textStyle.color = RGB(226, 116, 152);
|
||
selectionAreaButton.back()->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
selectionAreaButton_ptr.push_back(selectionAreaButton.back().get());
|
||
int k = 15 - x;
|
||
selectionAreaButton.back()->setOnToggleOnListener([k, btn = selectionAreaButton_ptr.back()]()
|
||
{
|
||
btn->setButtonText("1");
|
||
initData[k] = '1';
|
||
});
|
||
selectionAreaButton.back()->setOnToggleOffListener([k, btn = selectionAreaButton_ptr.back()]()
|
||
{
|
||
btn->setButtonText("0");
|
||
initData[k] = '0';
|
||
});
|
||
}
|
||
os.str("");
|
||
os.clear();
|
||
}
|
||
}
|
||
selectionAreaLabel->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::Left);
|
||
selectionAreaLabel->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
|
||
selectionArea->addControl(std::move(selectionAreaLabel));
|
||
for (auto& s : selectionAreaButton)
|
||
{
|
||
s->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::Left);
|
||
s->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
selectionArea->addControl(std::move(s));
|
||
}
|
||
for (auto& s : selectionAreaButtonLabel)
|
||
{
|
||
s->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::Left);
|
||
s->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
selectionArea->addControl(std::move(s));
|
||
}
|
||
//功能区控件
|
||
//功能区总容器
|
||
auto function = std::make_unique<Canvas>(10, 170, 680, 70);
|
||
function->setCanvasfillMode(StellarX::FillMode::Null);
|
||
function->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
function->setCanvasBkColor(blackColor);
|
||
auto bitInvert_que = std::make_unique<Canvas>(0, 0, 220, 70);
|
||
auto leftShift_que = std::make_unique<Canvas>(230, 0, 220, 70);
|
||
auto rightShift_que = std::make_unique<Canvas>(460, 0, 220, 70);
|
||
|
||
auto bitInvert = bitInvert_que.get();
|
||
auto leftShift = leftShift_que.get();
|
||
auto rightShift = rightShift_que.get();
|
||
|
||
bitInvert->setCanvasBkColor(blackColor);
|
||
bitInvert->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
leftShift->setCanvasBkColor(blackColor);
|
||
leftShift->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
rightShift->setCanvasBkColor(blackColor);
|
||
rightShift->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
|
||
function->addControl(std::move(bitInvert_que));
|
||
function->addControl(std::move(leftShift_que));
|
||
function->addControl(std::move(rightShift_que));
|
||
|
||
auto bitInvertLabel = std::make_unique<Label>(13, -10, "位取反");
|
||
bitInvertLabel->setTextdisap(true);
|
||
auto leftShiftLabel = std::make_unique<Label>(13, -10, "左移位");
|
||
leftShiftLabel->setTextdisap(true);
|
||
auto rightShiftLabel = std::make_unique<Label>(13, -10, "右移位");
|
||
rightShiftLabel->setTextdisap(true);
|
||
|
||
// ====== 公用小工具======
|
||
auto clamp = [](int v, int lo, int hi) { return v < lo ? lo : (v > hi ? hi : v); };
|
||
auto toInt = [](const std::string& s, int def = 0) {
|
||
try { return std::stoi(s); }
|
||
catch (...) { return def; }
|
||
};
|
||
// bit号(31..0) -> selectionAreaButton下标(0..31)
|
||
auto vecIndexFromBit = [](int bit) { return 31 - bit; };
|
||
|
||
// 读取当前32位点击态
|
||
auto snapshotBits = [&]() {
|
||
std::array<bool, 32> a{};
|
||
for (int b = 0; b < 32; ++b)
|
||
a[b] = selectionAreaButton_ptr[vecIndexFromBit(b)]->isClicked();
|
||
return a;
|
||
};
|
||
|
||
// 应用目标态:仅当不同才 setButtonClick
|
||
auto applyBits = [&](const std::array<bool, 32>& a) {
|
||
for (int b = 0; b < 32; ++b) {
|
||
auto btn = selectionAreaButton_ptr[vecIndexFromBit(b)];
|
||
if (btn->isClicked() != a[b]) btn->setButtonClick(a[b]);
|
||
}
|
||
};
|
||
|
||
//取反区控件
|
||
std::array<std::unique_ptr<Label>, 4> bitInvertFunctionLabel;
|
||
bitInvertFunctionLabel[0] = std::make_unique<Label>(30, 10, "低位");
|
||
bitInvertFunctionLabel[1] = std::make_unique<Label>(90, 10, "高位");
|
||
bitInvertFunctionLabel[2] = std::make_unique<Label>(15, 38, "从");
|
||
bitInvertFunctionLabel[3] = std::make_unique<Label>(75, 38, "到");
|
||
|
||
std::array<std::unique_ptr<TextBox>, 2> bitInvertFunctionTextBox;
|
||
bitInvertFunctionTextBox[0] = std::make_unique<TextBox>(35, 35, 35, 30, "0");
|
||
bitInvertFunctionTextBox[1] = std::make_unique<TextBox>(95, 35, 35, 30, "0");
|
||
auto invL = bitInvertFunctionTextBox[0].get();
|
||
auto invH = bitInvertFunctionTextBox[1].get();
|
||
auto bitInvertFunctionButton = std::make_unique<Button>(135, 35, 80, 30, "位取反",
|
||
blackColor, RGB(171, 196, 220));
|
||
bitInvertFunctionButton->textStyle.color = RGB(226, 116, 152);
|
||
bitInvertFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
auto bitInvertFunctionButton_ptr = bitInvertFunctionButton.get();
|
||
|
||
bitInvert->addControl(std::move(bitInvertFunctionButton));
|
||
bitInvert->addControl(std::move(bitInvertLabel));
|
||
for (auto& b : bitInvertFunctionTextBox)
|
||
{
|
||
b->setMaxCharLen(3);
|
||
b->textStyle.color = RGB(226, 116, 152);
|
||
b->setTextBoxBk(RGB(244, 234, 142));
|
||
b->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||
bitInvert->addControl(std::move(b));
|
||
}
|
||
for (auto& b : bitInvertFunctionLabel)
|
||
{
|
||
b->setTextdisap(true);
|
||
bitInvert->addControl(std::move(b));
|
||
}
|
||
//左移控件
|
||
auto leftShiftFunctionLabel = std::make_unique<Label>(198, 30, "位");
|
||
leftShiftFunctionLabel->setTextdisap(true);
|
||
|
||
auto leftShiftFunctionTextBox = std::make_unique<TextBox>(90, 30, 100, 30, "0");
|
||
leftShiftFunctionTextBox->setMaxCharLen(3);
|
||
leftShiftFunctionTextBox->textStyle.color = RGB(226, 116, 152);
|
||
leftShiftFunctionTextBox->setTextBoxBk(RGB(244, 234, 142));
|
||
leftShiftFunctionTextBox->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||
auto shlBox = leftShiftFunctionTextBox.get();
|
||
auto leftShiftFunctionButton = std::make_unique<Button>(15, 30, 60, 30, "左移",
|
||
blackColor, RGB(171, 196, 220));
|
||
leftShiftFunctionButton->textStyle.color = RGB(226, 116, 152);
|
||
leftShiftFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
auto leftShiftFunctionButton_ptr = leftShiftFunctionButton.get();
|
||
|
||
leftShift->addControl(std::move(leftShiftFunctionButton));
|
||
leftShift->addControl(std::move(leftShiftFunctionTextBox));
|
||
|
||
leftShift->addControl(std::move(leftShiftLabel));
|
||
leftShift->addControl(std::move(leftShiftFunctionLabel));
|
||
|
||
//右移控件
|
||
auto rightShiftFunctionLabel = std::make_unique<Label>(198, 30, "位");
|
||
rightShiftFunctionLabel->setTextdisap(true);
|
||
auto rightShiftFunctionTextBox = std::make_unique<TextBox>(90, 30, 100, 30, "0");
|
||
rightShiftFunctionTextBox->setMaxCharLen(3);
|
||
rightShiftFunctionTextBox->textStyle.color = RGB(226, 116, 152);
|
||
rightShiftFunctionTextBox->setTextBoxBk(RGB(244, 234, 142));
|
||
rightShiftFunctionTextBox->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||
auto shrBox = rightShiftFunctionTextBox.get();
|
||
|
||
auto rightShiftFunctionButton = std::make_unique<Button>(15, 30, 60, 30, "右移",
|
||
blackColor, RGB(171, 196, 220));
|
||
rightShiftFunctionButton->textStyle.color = RGB(226, 116, 152);
|
||
rightShiftFunctionButton->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
auto rightShiftFunctionButton_ptr = rightShiftFunctionButton.get();
|
||
|
||
rightShift->addControl(std::move(rightShiftFunctionButton));
|
||
|
||
rightShift->addControl(std::move(rightShiftFunctionTextBox));
|
||
rightShift->addControl(std::move(rightShiftLabel));
|
||
rightShift->addControl(std::move(rightShiftFunctionLabel));
|
||
|
||
//显示区控件
|
||
//数值显示
|
||
auto NumericalDisplayArea = std::make_unique<Canvas>(10, 255, 680, 70);
|
||
NumericalDisplayArea->setCanvasBkColor(blackColor);
|
||
NumericalDisplayArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
|
||
std::array<std::unique_ptr<Label>, 3> NumericalDisplayAreaLabel;
|
||
NumericalDisplayAreaLabel[0] = std::make_unique<Label>(18, -10, "数值显示区");
|
||
NumericalDisplayAreaLabel[1] = std::make_unique<Label>(20, 25, "十六进制");
|
||
NumericalDisplayAreaLabel[2] = std::make_unique<Label>(330, 25, "十进制");
|
||
|
||
std::array<std::unique_ptr<TextBox>, 2> NumericalDisplayAreaTextBox;
|
||
NumericalDisplayAreaTextBox[0] = std::make_unique<TextBox>(110, 25, 200, 30, "0");
|
||
NumericalDisplayAreaTextBox[1] = std::make_unique<TextBox>(400, 25, 200, 30, "0");
|
||
auto hex = NumericalDisplayAreaTextBox[0].get();
|
||
auto dec = NumericalDisplayAreaTextBox[1].get();
|
||
|
||
for (auto& b : NumericalDisplayAreaLabel)
|
||
{
|
||
b->setTextdisap(true);
|
||
NumericalDisplayArea->addControl(std::move(b));
|
||
}
|
||
for (auto& b : NumericalDisplayAreaTextBox)
|
||
{
|
||
b->setMaxCharLen(11);
|
||
b->textStyle.color = RGB(255, 69, 0);
|
||
b->setTextBoxBk(RGB(141, 141, 141));
|
||
b->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||
b->setMode(StellarX::TextBoxmode::READONLY_MODE);
|
||
NumericalDisplayArea->addControl(std::move(b));
|
||
}
|
||
//二进制显示
|
||
auto BinaryDisplayArea = std::make_unique<Canvas>(10, 335, 680, 110);
|
||
BinaryDisplayArea->setCanvasBkColor(blackColor);
|
||
BinaryDisplayArea->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
|
||
std::array<std::unique_ptr<Label>, 3> BinaryDisplayAreaLabel;
|
||
BinaryDisplayAreaLabel[0] = std::make_unique<Label>(18, -10, "二进制显示区");
|
||
BinaryDisplayAreaLabel[1] = std::make_unique<Label>(35, 20, "上次值");
|
||
BinaryDisplayAreaLabel[2] = std::make_unique<Label>(35, 67, "本次值");
|
||
|
||
std::array<std::unique_ptr<TextBox>, 2> BinaryDisplayAreaTextBox;
|
||
BinaryDisplayAreaTextBox[0] = std::make_unique<TextBox>(110, 20, 520, 30, "0000_0000_0000_0000_0000_0000_0000_0000");
|
||
BinaryDisplayAreaTextBox[1] = std::make_unique<TextBox>(110, 67, 520, 30, "0000_0000_0000_0000_0000_0000_0000_0000");
|
||
auto Last = BinaryDisplayAreaTextBox[0].get();
|
||
auto This = BinaryDisplayAreaTextBox[1].get();
|
||
|
||
for (auto& b : BinaryDisplayAreaLabel)
|
||
{
|
||
b->setTextdisap(true);
|
||
BinaryDisplayArea->addControl(std::move(b));
|
||
}
|
||
for (auto& b : BinaryDisplayAreaTextBox)
|
||
{
|
||
b->setMaxCharLen(40);
|
||
b->textStyle.color = RGB(255, 69, 0);
|
||
b->setTextBoxBk(RGB(141, 141, 141));
|
||
b->setTextBoxshape(StellarX::ControlShape::B_RECTANGLE);
|
||
b->setMode(StellarX::TextBoxmode::READONLY_MODE);
|
||
BinaryDisplayArea->addControl(std::move(b));
|
||
}
|
||
|
||
// 由位图 bits 生成数值
|
||
auto valueFromBits = [](const std::array<bool, 32>& bits) -> uint32_t {
|
||
uint32_t v = 0;
|
||
for (int b = 0; b < 32; ++b) if (bits[b]) v |= (1u << b);
|
||
return v;
|
||
};
|
||
|
||
// 由位图 bits 生成 "0000_0000_..._0000"(MSB→LSB:31..0)
|
||
auto binaryGroupedFromBits = [](const std::array<bool, 32>& bits) -> std::string {
|
||
std::string s; s.reserve(39);
|
||
for (int b = 31; b >= 0; --b) {
|
||
s.push_back(bits[b] ? '1' : '0');
|
||
if (b % 4 == 0 && b != 0) s.push_back('_');
|
||
}
|
||
return s;
|
||
};
|
||
|
||
// 用“目标位图 bits”刷新显示区
|
||
auto refreshDisplaysWithBits = [&](const std::string& prevThis,
|
||
const std::array<bool, 32>& bits,
|
||
TextBox* hex, TextBox* dec, TextBox* Last, TextBox* This)
|
||
{
|
||
const uint32_t val = valueFromBits(bits);
|
||
const int32_t s = static_cast<int32_t>(val);
|
||
char hexbuf[16];
|
||
std::snprintf(hexbuf, sizeof(hexbuf), "%08X", val);
|
||
|
||
hex->setText(hexbuf); // HEX(大写8位)
|
||
dec->setText(gSigned ? std::to_string(s) : std::to_string(val)); // DEC
|
||
Last->setText(prevThis); // 上次值 ← 刷新前的本次值
|
||
This->setText(binaryGroupedFromBits(bits)); // 本次值 ← 由“目标位图”生成
|
||
};
|
||
|
||
bitInvertFunctionButton_ptr->setOnClickListener([=, &snapshotBits, &applyBits, &refreshDisplaysWithBits]() {
|
||
const std::string prevThis = This->getText();
|
||
|
||
int L = clamp(toInt(invL->getText(), 0), 0, 31);
|
||
int H = clamp(toInt(invH->getText(), 0), 0, 31);
|
||
if (L > H) std::swap(L, H);
|
||
|
||
auto cur = snapshotBits();
|
||
for (int b = L; b <= H; ++b) cur[b] = !cur[b];
|
||
|
||
applyBits(cur); // 只改按钮点击态(触发位按钮自回调)
|
||
refreshDisplaysWithBits(prevThis, cur, hex, dec, Last, This);
|
||
});
|
||
|
||
leftShiftFunctionButton_ptr->setOnClickListener([=, &snapshotBits, &applyBits, &refreshDisplaysWithBits]() {
|
||
const std::string prevThis = This->getText();
|
||
|
||
int n = clamp(toInt(shlBox->getText(), 0), 0, 31);
|
||
auto cur = snapshotBits();
|
||
std::array<bool, 32> nxt{}; // 默认全 0
|
||
|
||
// 逻辑左移:高位丢弃、低位补 0
|
||
for (int b = 31; b >= 0; --b) nxt[b] = (b >= n) ? cur[b - n] : false;
|
||
|
||
applyBits(nxt);
|
||
refreshDisplaysWithBits(prevThis, nxt, hex, dec, Last, This);
|
||
});
|
||
|
||
rightShiftFunctionButton_ptr->setOnClickListener([=, &snapshotBits, &applyBits, &refreshDisplaysWithBits]() {
|
||
const std::string prevThis = This->getText();
|
||
|
||
int n = clamp(toInt(shrBox->getText(), 0), 0, 31);
|
||
auto cur = snapshotBits();
|
||
std::array<bool, 32> nxt{};
|
||
|
||
// 逻辑右移:低位丢弃、高位补 0
|
||
for (int b = 0; b < 32; ++b) nxt[b] = (b + n <= 31) ? cur[b + n] : false;
|
||
|
||
applyBits(nxt);
|
||
refreshDisplaysWithBits(prevThis, nxt, hex, dec, Last, This);
|
||
});
|
||
|
||
//配置区控件clearrectangle(10, 440, 690, 490);
|
||
auto configuration = std::make_unique<Canvas>(10, 455, 680, 40);
|
||
configuration->setCanvasBkColor(blackColor);
|
||
configuration->setShape(StellarX::ControlShape::B_ROUND_RECTANGLE);
|
||
|
||
auto configurationLabel = std::make_unique<Label>(20, -10, "配置区");
|
||
configurationLabel->setTextdisap(true);
|
||
|
||
std::array<std::unique_ptr<Button>, 2> configurationButton;
|
||
configurationButton[0] = std::make_unique<Button>(420, 10, 90, 20, "一键置0",
|
||
blackColor, RGB(171, 196, 220));
|
||
configurationButton[0]->textStyle.color = RGB(226, 116, 152);
|
||
configurationButton[0]->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
|
||
configurationButton[1] = std::make_unique<Button>(530, 10, 90, 20, "一键置1",
|
||
blackColor, RGB(171, 196, 220));
|
||
configurationButton[1]->textStyle.color = RGB(226, 116, 152);
|
||
configurationButton[1]->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
configurationButton[0]->setOnClickListener(
|
||
[&]() {
|
||
for (auto& s : selectionAreaButton_ptr)
|
||
if (s->isClicked()) s->setButtonClick(false);
|
||
|
||
// 刷新显示:prevThis 用当前 This 文本
|
||
const std::string prevThis = This->getText();
|
||
auto cur = snapshotBits();
|
||
{
|
||
char hexbuf[16];
|
||
uint32_t u = 0; for (int b = 0; b < 32; ++b) if (cur[b]) u |= (1u << b);
|
||
int32_t s = static_cast<int32_t>(u);
|
||
std::snprintf(hexbuf, sizeof(hexbuf), "%08X", u);
|
||
hex->setText(hexbuf);
|
||
dec->setText(gSigned ? std::to_string(s) : std::to_string(u));
|
||
Last->setText(prevThis);
|
||
This->setText(binaryGroupedFromBits(cur));
|
||
}
|
||
});
|
||
|
||
configurationButton[1]->setOnClickListener(
|
||
[&]() {
|
||
for (auto& s : selectionAreaButton_ptr)
|
||
if (!s->isClicked()) s->setButtonClick(true);
|
||
|
||
const std::string prevThis = This->getText();
|
||
auto cur = snapshotBits();
|
||
char hexbuf[16];
|
||
uint32_t u = 0; for (int b = 0; b < 32; ++b) if (cur[b]) u |= (1u << b);
|
||
int32_t s = static_cast<int32_t>(u);
|
||
std::snprintf(hexbuf, sizeof(hexbuf), "%08X", u);
|
||
hex->setText(hexbuf);
|
||
dec->setText(gSigned ? std::to_string(s) : std::to_string(u));
|
||
Last->setText(prevThis);
|
||
This->setText(binaryGroupedFromBits(cur));
|
||
});
|
||
|
||
auto signedToggle = std::make_unique<Button>(
|
||
330, 10, 80, 20, "无符号",
|
||
blackColor, RGB(171, 196, 220), StellarX::ButtonMode::TOGGLE);
|
||
signedToggle->textStyle.color = RGB(226, 116, 152);
|
||
signedToggle->setButtonShape(StellarX::ControlShape::B_RECTANGLE);
|
||
auto* signedTogglePtr = signedToggle.get();
|
||
|
||
signedTogglePtr->setOnToggleOnListener([&]() {
|
||
gSigned = true;
|
||
signedTogglePtr->setButtonText("有符号");
|
||
StellarX::MessageBox::showModal(mainWindow, "有符号模式下,\n最高位为符号位,\n其余位为数值位。", "有符号模式");
|
||
// 立即刷新十进制显示:用当前位图算出新值,仅改 dec
|
||
auto cur = snapshotBits();
|
||
const uint32_t u = [&] { uint32_t v = 0; for (int b = 0; b < 32; ++b) if (cur[b]) v |= (1u << b); return v; }();
|
||
const int32_t s = static_cast<int32_t>(u);
|
||
dec->setText(std::to_string(s));
|
||
});
|
||
signedTogglePtr->setOnToggleOffListener([&]() {
|
||
gSigned = false;
|
||
signedTogglePtr->setButtonText("无符号");
|
||
StellarX::MessageBox::showAsync(mainWindow, "无符号模式下,\n所有位均为数值位。", "无符号模式");
|
||
auto cur = snapshotBits();
|
||
const uint32_t u = [&] { uint32_t v = 0; for (int b = 0; b < 32; ++b) if (cur[b]) v |= (1u << b); return v; }();
|
||
dec->setText(std::to_string(u));
|
||
});
|
||
|
||
signedTogglePtr->enableTooltip(true);
|
||
signedTogglePtr->setTooltipTextsForToggle("切换无符号模式", "切换有符号模式");
|
||
|
||
configuration->addControl(std::move(configurationButton[0]));
|
||
configuration->addControl(std::move(configurationButton[1]));
|
||
configuration->addControl(std::move(signedToggle));
|
||
configuration->addControl(std::move(configurationLabel));
|
||
|
||
selectionArea->setAnchor(StellarX::Anchor::Right, StellarX::Anchor::Left);
|
||
selectionArea->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
|
||
mainWindow.addControl(std::move(selectionArea));
|
||
mainWindow.addControl(std::move(function));
|
||
mainWindow.addControl(std::move(NumericalDisplayArea));
|
||
mainWindow.addControl(std::move(BinaryDisplayArea));
|
||
mainWindow.addControl(std::move(configuration));
|
||
|
||
mainWindow.draw();
|
||
return mainWindow.runEventLoop();
|
||
}
|
||
#endif
|
||
|
||
#if 3 == KEY
|
||
|
||
// 本Demo基于 StellarX 构建,轻量级的 Windows GUI 框架。
|
||
#include"StellarX.h"
|
||
|
||
int main()
|
||
{
|
||
StellarX::SxLogger::setGBK();
|
||
StellarX::SxLogger::Get().enableConsole(true);
|
||
StellarX::SxLogger::Get().setMinLevel(StellarX::SxLogLevel::Debug); // Info/Debug/Trace 自己切
|
||
StellarX::SxLogger::Get().setLanguage(StellarX::SxLogLanguage::ZhCN); // ZhCN / EnUS
|
||
|
||
Window win(1300, 800, 1, RGB(255, 255, 0), "记账管理系统");
|
||
|
||
/*********登录界面***********/
|
||
//标签
|
||
std::unique_ptr<Label> logIn_label[3];
|
||
logIn_label[0] = std::make_unique<Label>(90, 150, "欢迎使用餐馆记账管理系统");
|
||
logIn_label[1] = std::make_unique<Label>(400, 300, "账号");
|
||
logIn_label[2] = std::make_unique<Label>(400, 400, "密码");
|
||
for (auto& log : logIn_label)
|
||
{
|
||
log->setTextdisap(true);
|
||
log->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
log->textStyle.lpszFace = "华文行楷";
|
||
}
|
||
logIn_label[0]->textStyle.nHeight = 100;
|
||
logIn_label[0]->setAnchor(StellarX::Anchor::Top, StellarX::Anchor::NoAnchor);
|
||
logIn_label[1]->textStyle.nHeight = 50;
|
||
logIn_label[1]->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||
logIn_label[2]->textStyle.nHeight = 50;
|
||
logIn_label[2]->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||
|
||
//输入框
|
||
std::unique_ptr<TextBox> logIn_textBox[2];
|
||
TextBox* logIn_textBox_ptr[2];
|
||
logIn_textBox[0] = std::make_unique<TextBox>(500, 295, 450, 50);
|
||
logIn_textBox[1] = std::make_unique<TextBox>(500, 395, 450, 50);
|
||
logIn_textBox[1]->setMode(StellarX::TextBoxmode::PASSWORD_MODE);
|
||
logIn_textBox_ptr[0] = logIn_textBox[0].get();
|
||
logIn_textBox_ptr[1] = logIn_textBox[1].get();
|
||
for (auto& tb : logIn_textBox)
|
||
{
|
||
tb->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
tb->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||
tb->setMaxCharLen(15);
|
||
}
|
||
//按钮
|
||
std::unique_ptr<Button> logIn_Button[2];
|
||
Button* logIn_Button_ptr[2];
|
||
logIn_Button[0] = std::make_unique<Button>(350, 500, 300, 50, "管理员登录");
|
||
logIn_Button[1] = std::make_unique<Button>(750, 500, 300, 50, "操作员登录");
|
||
logIn_Button_ptr[0] = logIn_Button[0].get();
|
||
logIn_Button_ptr[1] = logIn_Button[1].get();
|
||
for (auto& b : logIn_Button)
|
||
{
|
||
b->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
b->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::NoAnchor);
|
||
}
|
||
//log画布
|
||
auto log_Canvas = std::make_unique<Canvas>(0, 0, 1300, 800);
|
||
Canvas* log_Canvas_ptr = log_Canvas.get();
|
||
log_Canvas_ptr->setCanvasfillMode(StellarX::FillMode::Null);
|
||
log_Canvas_ptr->setShape(StellarX::ControlShape::B_RECTANGLE);
|
||
log_Canvas_ptr->setLayoutMode(StellarX::LayoutMode::AnchorToEdges);
|
||
log_Canvas_ptr->setAnchor(StellarX::Anchor::Bottom, StellarX::Anchor::Top);
|
||
|
||
//将log界面控价加入logCanvas统一管理
|
||
for (auto& b : logIn_Button)
|
||
log_Canvas_ptr->addControl(std::move(b));
|
||
for (auto& tb : logIn_textBox)
|
||
log_Canvas_ptr->addControl(std::move(tb));
|
||
for (auto& la : logIn_label)
|
||
log_Canvas_ptr->addControl(std::move(la));
|
||
|
||
/**************业务UI****************/
|
||
|
||
auto tabControl = std::make_unique<TabControl>(10, 10, 1280, 780);
|
||
auto tabControl_ptr = tabControl.get();
|
||
tabControl_ptr->setIsVisible(false);
|
||
tabControl_ptr->setCanvasfillMode(StellarX::FillMode::Null);
|
||
tabControl_ptr->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
tabControl_ptr->setTabPlacement(StellarX::TabPlacement::Left);
|
||
tabControl_ptr->setTabBarHeight(60);
|
||
//添加页签及页
|
||
auto tabP = std::make_pair(std::make_unique<Button>(0, 0, 100, 100, "点餐"), std::make_unique<Canvas>(0, 0, 1290, 790));
|
||
tabP.second->setShape(StellarX::ControlShape::ROUND_RECTANGLE);
|
||
tabControl_ptr->add(std::move(tabP));
|
||
|
||
/*------------login事件-------------*/
|
||
//管理员登录按钮事件
|
||
logIn_Button_ptr[0]->setOnClickListener([&tabControl_ptr, &log_Canvas_ptr, &logIn_textBox_ptr, &win]()
|
||
{
|
||
if ("\0" == logIn_textBox_ptr[0]->getText() || "\0" == logIn_textBox_ptr[1]->getText())
|
||
{
|
||
if ("\0" == logIn_textBox_ptr[0]->getText())logIn_textBox_ptr[0]->setTextBoxBk(RGB(255, 0, 0));
|
||
if ("\0" == logIn_textBox_ptr[1]->getText())logIn_textBox_ptr[1]->setTextBoxBk(RGB(255, 0, 0));
|
||
std::cout << "\a";
|
||
StellarX::MessageBox::showAsync(win, "账号或密码不能为空!", "提示");
|
||
}
|
||
else if("admin" == logIn_textBox_ptr[0]->getText() && "123" == logIn_textBox_ptr[1]->getText())
|
||
{
|
||
log_Canvas_ptr->setIsVisible(false);
|
||
tabControl_ptr->setIsVisible(true);
|
||
win.draw("image\\bk1.jpg");
|
||
}
|
||
else
|
||
{
|
||
std::cout << "\a";
|
||
StellarX::MessageBox::showModal(win, "账号或密码错误!", "提示");
|
||
}
|
||
});
|
||
//操作员登录按钮事件
|
||
logIn_Button_ptr[1]->setOnClickListener([&tabControl_ptr, &log_Canvas_ptr, &logIn_textBox_ptr, &win]()
|
||
{
|
||
if ("\0" == logIn_textBox_ptr[0]->getText() || "\0" == logIn_textBox_ptr[1]->getText())
|
||
{
|
||
if ("\0" == logIn_textBox_ptr[0]->getText())logIn_textBox_ptr[0]->setTextBoxBk(RGB(255, 0, 0));
|
||
if ("\0" == logIn_textBox_ptr[1]->getText())logIn_textBox_ptr[1]->setTextBoxBk(RGB(255, 0, 0));
|
||
std::cout << "\a";
|
||
StellarX::MessageBox::showModal(win, "账号或密码不能为空!", "提示");
|
||
}
|
||
else
|
||
{
|
||
log_Canvas_ptr->setIsVisible(false);
|
||
tabControl_ptr->setIsVisible(true);
|
||
win.draw("image\\bk1.jpg");
|
||
}
|
||
});
|
||
|
||
win.addControl(std::move(log_Canvas));
|
||
win.addControl(std::move(tabControl));
|
||
win.draw("image\\bk1.jpg");
|
||
|
||
return win.runEventLoop();
|
||
}
|
||
|
||
#endif
|