diff --git a/CHANGELOG.en.md b/CHANGELOG.en.md index 2dbf125..799f43b 100644 --- a/CHANGELOG.en.md +++ b/CHANGELOG.en.md @@ -7,9 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [中文文档](CHANGELOG.md) +## [v2.3.2] - 2025 - 12 - 20 + +### ✨ Added + +- **Table: runtime reset for headers and data:** added `Table::clearHeaders()`, `Table::clearData()`, and `Table::resetTable()`. This allows a single `Table` instance to dynamically update its headers/data at runtime, and triggers the required recalculation (cell sizing / pagination info) and redraw. +- **TextBox: password mode:** added `PASSWORD_MODE` to `TextBoxmode`. User input is stored internally, while the render layer displays masked characters (e.g., `*`). The real text can be retrieved via `TextBox::getText()`. + +### ⚙️ Changed + +- **TabControl: clarified default active page semantics:** + - Calling `TabControl::setActiveIndex()` **before the first draw** now only records the default active index; it no longer immediately triggers the tab button click callback. + - **After the first draw completes**, if a default active index was set, the active state is applied and the active page is drawn (if the index is out of range, the last page is activated by default). + - Calling `TabControl::setActiveIndex()` **during runtime (non-first draw)** switches the active page immediately when the index is valid; out-of-range indices are ignored. + +### ✅ Fixed + +- **TabControl::setActiveIndex crash when called before drawing:** fixed a null-pointer access caused by triggering the tab button click callback before initialization. The default activation is now applied after the first draw completes, preventing crashes and ensuring the active page is rendered on first draw. +- **TabControl rendering glitches when toggling visibility (hidden -> visible):** fixed multi-page overlap/ghosting caused by non-active pages being incorrectly drawn after `setIsVisible(false) -> setIsVisible(true)`. Now, when TabControl is visible, only the active page is visible/drawable; if there is no active page, nothing is drawn. + ## [v2.3.1] - 2025-11-30 -## 🙏 Acknowledgements +### 🙏 Acknowledgements - Special thanks to user [@To-KongBai](https://github.com/To-KongBai) for providing stable reproduction steps and key phenomenon comparisons (container nested child control coordinate transformation issue), which helped us quickly identify and fix the control coordinate transformation problem in deeply nested containers. ([Issues#6](https://github.com/Ysm-04/StellarX/issues/6)) - In the upcoming website (currently undergoing ICP filing), we plan to add a contributors' wall to acknowledge users. We welcome everyone to report bugs or share interfaces created with StellarX, and we will carefully read and include acknowledgements. diff --git a/CHANGELOG.md b/CHANGELOG.md index 6170540..b56e198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,28 @@ StellarX 项目所有显著的变化都将被记录在这个文件中。 [English document](CHANGELOG.en.md) +## [v2.3.2] - 2025 - 12 - 20 + +### ✨ 新增 + +- **Table 支持运行期重置表头与数据:**新增 `Table::clearHeaders()`、`Table::clearData()`、`Table::resetTable()`,允许同一 `Table` 在运行过程中动态切换表头与数据,并触发必要的单元格尺寸/分页信息重算与重绘。 +- **TextBox 新增密码模式:**`TextBoxmode` 新增 `PASSWORD_MODE`;输入内容内部保存,绘制层面使用掩码字符(如 `*`)替代显示,真实文本可通过 `TextBox::getText()` 获取。 + +### ⚙️ 变更 + +- **TabControl 默认激活页语义明确化:** + - 首次绘制前调用 `TabControl::setActiveIndex()`:仅记录默认激活索引,不再立即触发页签按钮点击回调; + - 首次绘制完成后:若设置了默认激活索引则应用激活状态并绘制激活页(索引越界时默认激活最后一个页); + - 程序运行过程中调用 `TabControl::setActiveIndex()`:索引合法则立即切换激活页并绘制;索引越界则不做处理。 + +### ✅ 修复 + +- **TabControl::setActiveIndex 绘制前调用导致程序中断:**修复绘制前设置默认激活索引时触发空指针访问的问题;现在默认激活逻辑延后到首次绘制完成后再生效,避免崩溃并保证首次绘制即可绘制激活页。 +- **TabControl 由不可见设置为可见时绘制错乱:**修复 `setIsVisible(false) -> setIsVisible(true)` 后非激活页被错误绘制导致的多页重叠/残影;现在 TabControl 可见时仅激活页可见/可绘制,无激活页则不绘制任何页。 + ## [v2.3.1] - 2025 - 11 - 30 -## 🙏 鸣谢 +### 🙏 鸣谢 - 感谢用户 [@To-KongBai](https://github.com/To-KongBai) 提供稳定复现步骤与关键现象对比(容器嵌套孙控件坐标转换问题),帮助我们快速确认多容器嵌套时的控件坐标转换问题并修复。([Issues#6](https://github.com/Ysm-04/StellarX/issues/6)) - 在即将上线的官网中(ICP备案中)我们计划加入一个贡献者鸣谢墙,欢迎各位用户反馈BUG或者分享自己用星垣做的界面,我们将认真阅读并收录鸣谢 diff --git a/README.en.md b/README.en.md index 4d4ae44..776c361 100644 --- a/README.en.md +++ b/README.en.md @@ -7,8 +7,8 @@ ![GitHub all releases](https://img.shields.io/github/downloads/Ysm-04/StellarX/total) [![Star GitHub Repo](https://img.shields.io/github/stars/Ysm-04/StellarX.svg?style=social&label=Star%20This%20Repo)](https://github.com/Ysm-04/StellarX) -![Version](https://img.shields.io/badge/Version-2.3.0-brightgreen.svg) - ![Download](https://img.shields.io/badge/Download-2.3.0_Release-blue.svg) +![Version](https://img.shields.io/badge/Version-2.3.2-brightgreen.svg) + ![Download](https://img.shields.io/badge/Download-2.3.2_Release-blue.svg) ![C++](https://img.shields.io/badge/C++-17+-00599C?logo=cplusplus&logoColor=white) ![Windows](https://img.shields.io/badge/Platform-Windows-0078D6?logo=windows) @@ -25,30 +25,6 @@ This is a **teaching-grade and tooling-grade** framework that helps developers u ------ -## 🆕 V2.3.0 - Major Update - -**This version represents a significant milestone, introducing a responsive layout system that transitions from static to dynamic layout management, and comprehensively resolves the previously encountered random rendering corruption issues caused by reentrant drawing operations.** - -- **Optimized Window Resizing Mechanism**: Refactored `WndProcThunk`, `runEventLoop`, and `pumpResizeIfNeeded` to uniformly record size changes and perform centralized repainting at the end of the event loop, eliminating jitter and sequencing confusion caused by repeated redraws. - -- **New Dialog Size Scheduling Interface**: Introduced the combination of `Window::scheduleResizeFromModal()` and `pumpResizeIfNeeded()`, enabling modal dialogs to notify the parent window of size updates even during resizing operations. Underlying controls are relayout during unified finalization while dialogs maintain their original dimensions. - -- **Enhanced Adaptive Layout System**: Internally added the `adaptiveLayout()` function to recalculate control positions and sizes based on anchor points, allowing dual-anchored controls (left-right or top-bottom) to adaptively stretch with window resizing. - -- **Fixed Modal Dialog Resizing Issues**: Resolved the problem where window resizing while modal dialogs were open prevented underlying controls from updating their positions and sizes according to anchor points; simultaneously eliminated ghosting artifacts caused by repeated dialog redraws. - -- **Further Resolved Drawing Sequence Confusion**: Replaced `InvalidateRect` with `ValidateRect` during resizing operations, ensuring the window is marked as valid only after a single unified drawing pass, preventing system-triggered `WM_PAINT` messages from causing reentrancy. - -- **Additional Fixes**: Corrected delayed background snapshot updates in tables and dialogs under certain edge cases. - -![](image/1.png) - -![](image/2.png) - -For details, please refer to the [CHANGELOG.en](CHANGELOG.en.md). - ------- - ## 📦 Project Structure & Design Philosophy StellarX adopts classic **OOP** and **modular** design with a clear structure: diff --git a/README.md b/README.md index e3d1c1b..82438b9 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ ![GitHub all releases](https://img.shields.io/github/downloads/Ysm-04/StellarX/total) [![Star GitHub Repo](https://img.shields.io/github/stars/Ysm-04/StellarX.svg?style=social&label=Star%20This%20Repo)](https://github.com/Ysm-04/StellarX) -![Version](https://img.shields.io/badge/Version-2.3.1-brightgreen.svg) -![Download](https://img.shields.io/badge/Download-2.3.1_Release-blue.svg) +![Version](https://img.shields.io/badge/Version-2.3.2-brightgreen.svg) +![Download](https://img.shields.io/badge/Download-2.3.2_Release-blue.svg) ![C++](https://img.shields.io/badge/C++-17+-00599C?logo=cplusplus&logoColor=white) ![Windows](https://img.shields.io/badge/Platform-Windows-0078D6?logo=windows) @@ -32,30 +32,26 @@ --- -## ==公告== -## 🙏 鸣谢 -- 感谢用户 [@To-KongBai](https://github.com/To-KongBai) 提供稳定复现步骤与关键现象对比(容器嵌套孙控件坐标转换问题),帮助我们快速确认多容器嵌套时的控件坐标转换问题并修复。([Issues#6](https://github.com/Ysm-04/StellarX/issues/6)) -- 在即将上线的官网中(ICP备案中)我们计划加入一个贡献者鸣谢墙,欢迎各位用户反馈BUG或者分享自己用星垣做的界面,我们将认真阅读并收录鸣谢 -- 真诚的感谢每一位反馈BUG的用户,你们的反馈将使星垣更加稳定和健壮 +## 🆕V2.3.2——重要更新 ---- +### 新增 -## 🆕V2.3.1——重要更新 - -### ✨ 新增 - -新增一个登录界面Demo在主仓库**examples/**目录下 +- **Table 支持运行期重置表头与数据:**新增 `Table::clearHeaders()`、`Table::clearData()`、`Table::resetTable()`,允许同一 `Table` 在运行过程中动态切换表头与数据,并触发必要的单元格尺寸/分页信息重算与重绘。 +- **TextBox 新增密码模式:**`TextBoxmode` 新增 `PASSWORD_MODE`;输入内容内部保存,绘制层面使用掩码字符(如 `*`)替代显示,真实文本可通过 `TextBox::getText()` 获取。 ### ⚙️ 变更 -- **Dialog背景快照机制:**`Dialog`不在自己抓取和销毁快照,**删除**重载的抓取和恢复快照的方法,完全交由基类`Canvas`处理,`Dialog`的`draw`方法中不在处理快照 -- **窗口变化重绘时控件和窗口重绘的时机调整:**主事件循环中窗口大小发生变化时先处理控件尺寸,并回贴和释放旧快照,然后再重绘新尺寸窗口,最后绘制控件 +- **TabControl 默认激活页语义明确化:** + - 首次绘制前调用 `TabControl::setActiveIndex()`:仅记录默认激活索引,不再立即触发页签按钮点击回调; + - 首次绘制完成后:若设置了默认激活索引则应用激活状态并绘制激活页(索引越界时默认激活最后一个页); + - 程序运行过程中调用 `TabControl::setActiveIndex()`:索引合法则立即切换激活页并绘制;索引越界则不做处理。 -本次针对用户反馈和已知内容进行了一些修复…… +### ✅ 修复 -详细变更请参阅[更新日志](CHANGELOG.md) +- **TabControl::setActiveIndex 绘制前调用导致程序中断:**修复绘制前设置默认激活索引时触发空指针访问的问题;现在默认激活逻辑延后到首次绘制完成后再生效,避免崩溃并保证首次绘制即可绘制激活页。 +- **TabControl 由不可见设置为可见时绘制错乱:**修复 `setIsVisible(false) -> setIsVisible(true)` 后非激活页被错误绘制导致的多页重叠/残影;现在 TabControl 可见时仅激活页可见/可绘制,无激活页则不绘制任何页。 --- diff --git a/include/StellarX/Button.h b/include/StellarX/Button.h index 3f17249..649e385 100644 --- a/include/StellarX/Button.h +++ b/include/StellarX/Button.h @@ -21,177 +21,170 @@ #include "Control.h" #include"label.h" - #define DISABLEDCOLOUR RGB(96, 96, 96) //禁用状态颜色 #define TEXTMARGINS_X 6 #define TEXTMARGINS_Y 4 constexpr int bordWith = 1; //边框宽度,用于快照恢复时的偏移计算 constexpr int bordHeight = 1; //边框高度,用于快照恢复时的偏移计算 - class Button : public Control { - - std::string text; // 按钮上的文字 - bool click; // 是否被点击 - bool hover; // 是否被悬停 + std::string text; // 按钮上的文字 + bool click; // 是否被点击 + bool hover; // 是否被悬停 - std::string cutText; // 切割后的文本 - bool needCutText = true; // 是否需要切割文本 - bool isUseCutText = false; // 是否使用切割文本 - int padX = TEXTMARGINS_X; // 文本最小左右内边距 - int padY = TEXTMARGINS_Y; // 文本最小上下内边距 + std::string cutText; // 切割后的文本 + bool needCutText = true; // 是否需要切割文本 + bool isUseCutText = false; // 是否使用切割文本 + int padX = TEXTMARGINS_X; // 文本最小左右内边距 + int padY = TEXTMARGINS_Y; // 文本最小上下内边距 - COLORREF buttonTrueColor; // 按钮被点击后的颜色 - COLORREF buttonFalseColor; // 按钮未被点击的颜色 - COLORREF buttonHoverColor; // 按钮被鼠标悬停的颜色 - COLORREF buttonBorderColor = RGB(0,0,0);// 按钮边框颜色 + COLORREF buttonTrueColor; // 按钮被点击后的颜色 + COLORREF buttonFalseColor; // 按钮未被点击的颜色 + COLORREF buttonHoverColor; // 按钮被鼠标悬停的颜色 + COLORREF buttonBorderColor = RGB(0, 0, 0);// 按钮边框颜色 - StellarX::ButtonMode mode; // 按钮模式 - StellarX::ControlShape shape; // 按钮形状 + StellarX::ButtonMode mode; // 按钮模式 + StellarX::ControlShape shape; // 按钮形状 - StellarX::FillMode buttonFillMode = StellarX::FillMode::Solid; //按钮填充模式 - StellarX::FillStyle buttonFillIma = StellarX::FillStyle::BDiagonal; //按钮填充图案 - IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像 + StellarX::FillMode buttonFillMode = StellarX::FillMode::Solid; //按钮填充模式 + StellarX::FillStyle buttonFillIma = StellarX::FillStyle::BDiagonal; //按钮填充图案 + IMAGE* buttonFileIMAGE = nullptr; //按钮填充图像 - - - std::function onClickCallback; //回调函数 - std::function onToggleOnCallback; //TOGGLE模式下的回调函数 - std::function onToggleOffCallback; //TOGGLE模式下的回调函数 + std::function onClickCallback; //回调函数 + std::function onToggleOnCallback; //TOGGLE模式下的回调函数 + std::function onToggleOffCallback; //TOGGLE模式下的回调函数 - StellarX::ControlText oldStyle = textStyle; // 按钮文字样式 - int oldtext_width = -1; - int oldtext_height = -1; - int text_width = 0; - int text_height = 0; + StellarX::ControlText oldStyle = textStyle; // 按钮文字样式 + int oldtext_width = -1; + int oldtext_height = -1; + int text_width = 0; + int text_height = 0; - // === Tooltip === - bool tipEnabled = false; // 是否启用 - bool tipVisible = false; // 当前是否显示 - bool tipFollowCursor = false; // 是否跟随鼠标 - bool tipUserOverride = false; // 是否用户自定义了tip文本 - int tipDelayMs = 1000; // 延时(毫秒) - int tipOffsetX = 12; // 相对鼠标偏移 - int tipOffsetY = 18; - ULONGLONG tipHoverTick = 0; // 开始悬停的时间戳 - int lastMouseX = 0; // 最新鼠标位置(用于定位) - int lastMouseY = 0; + // === Tooltip === + bool tipEnabled = false; // 是否启用 + bool tipVisible = false; // 当前是否显示 + bool tipFollowCursor = false; // 是否跟随鼠标 + bool tipUserOverride = false; // 是否用户自定义了tip文本 + int tipDelayMs = 1000; // 延时(毫秒) + int tipOffsetX = 12; // 相对鼠标偏移 + int tipOffsetY = 18; + ULONGLONG tipHoverTick = 0; // 开始悬停的时间戳 + int lastMouseX = 0; // 最新鼠标位置(用于定位) + int lastMouseY = 0; - std::string tipTextClick; //NORMAL 模式下用 - std::string tipTextOn; // click==true 时用 - std::string tipTextOff; // click==false 时用 - Label tipLabel; // 直接复用Label作为提示 - -public: - StellarX::ControlText textStyle; // 按钮文字样式 + std::string tipTextClick; //NORMAL 模式下用 + std::string tipTextOn; // click==true 时用 + std::string tipTextOff; // click==false 时用 + Label tipLabel; // 直接复用Label作为提示 public: - - //默认按钮颜色 - Button(int x, int y, int width, int height, const std::string text, - StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE); - //自定义按钮未被点击和被点击颜色 - Button(int x, int y, int width, int height, const std::string text, - COLORREF ct, COLORREF cf, StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, - StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE); - //自定义按钮颜色和悬停颜色 - Button(int x, int y, int width, int height, const std::string text, - COLORREF ct, COLORREF cf,COLORREF ch, - StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE); - //析构函数 释放图形指针内存 - ~Button(); + StellarX::ControlText textStyle; // 按钮文字样式 - //绘制按钮 - void draw() override; - //按钮事件处理 - bool handleEvent(const ExMessage& msg) override; - - //设置回调函数 - void setOnClickListener(const std::function&& callback); - //设置TOGGLE模式下被点击的回调函数 - void setOnToggleOnListener(const std::function&& callback); - //设置TOGGLE模式下取消点击的回调函数 - void setOnToggleOffListener(const std::function&& callback); - //设置按钮模式 - void setbuttonMode(StellarX::ButtonMode mode); - //设置圆角矩形椭圆宽度 - void setROUND_RECTANGLEwidth(int width); - //设置圆角矩形椭圆高度 - void setROUND_RECTANGLEheight(int height); - //设置按钮填充模式 - void setFillMode(StellarX::FillMode mode); - //设置按钮填充图案 - void setFillIma(StellarX::FillStyle ima); - //设置按钮填充图像 - void setFillIma(std::string imaName); - //设置按钮边框颜色 - void setButtonBorder(COLORREF Border); - //设置按钮未被点击颜色 - void setButtonFalseColor(COLORREF color); - //设置按钮文本 - void setButtonText(const char* text); - void setButtonText(std::string text); - //设置按钮形状 - void setButtonShape(StellarX::ControlShape shape); - //设置按钮点击状态 - void setButtonClick(BOOL click); +public: - //判断按钮是否被点击 - bool isClicked() const; - - //获取按钮文字 - std::string getButtonText() const; - const char* getButtonText_c() const; - //获取按钮模式 - StellarX::ButtonMode getButtonMode() const; - //获取按钮形状 - StellarX::ControlShape getButtonShape() const; - //获取按钮填充模式 - StellarX::FillMode getFillMode() const; + //默认按钮颜色 + Button(int x, int y, int width, int height, const std::string text, + StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE); + //自定义按钮未被点击和被点击颜色 + Button(int x, int y, int width, int height, const std::string text, + COLORREF ct, COLORREF cf, StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, + StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE); + //自定义按钮颜色和悬停颜色 + Button(int x, int y, int width, int height, const std::string text, + COLORREF ct, COLORREF cf, COLORREF ch, + StellarX::ButtonMode mode = StellarX::ButtonMode::NORMAL, StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE); + //析构函数 释放图形指针内存 + ~Button(); + + //绘制按钮 + void draw() override; + //按钮事件处理 + bool handleEvent(const ExMessage& msg) override; + + //设置回调函数 + void setOnClickListener(const std::function&& callback); + //设置TOGGLE模式下被点击的回调函数 + void setOnToggleOnListener(const std::function&& callback); + //设置TOGGLE模式下取消点击的回调函数 + void setOnToggleOffListener(const std::function&& callback); + //设置按钮模式 + void setbuttonMode(StellarX::ButtonMode mode); + //设置圆角矩形椭圆宽度 + void setROUND_RECTANGLEwidth(int width); + //设置圆角矩形椭圆高度 + void setROUND_RECTANGLEheight(int height); + //设置按钮填充模式 + void setFillMode(StellarX::FillMode mode); + //设置按钮填充图案 + void setFillIma(StellarX::FillStyle ima); + //设置按钮填充图像 + void setFillIma(std::string imaName); + //设置按钮边框颜色 + void setButtonBorder(COLORREF Border); + //设置按钮未被点击颜色 + void setButtonFalseColor(COLORREF color); + //设置按钮文本 + void setButtonText(const char* text); + void setButtonText(std::string text); + //设置按钮形状 + void setButtonShape(StellarX::ControlShape shape); + //设置按钮点击状态 + void setButtonClick(BOOL click); + + //判断按钮是否被点击 + bool isClicked() const; + + //获取按钮文字 + std::string getButtonText() const; + const char* getButtonText_c() const; + //获取按钮模式 + StellarX::ButtonMode getButtonMode() const; + //获取按钮形状 + StellarX::ControlShape getButtonShape() const; + //获取按钮填充模式 + StellarX::FillMode getFillMode() const; //获取按钮填充图案 - StellarX::FillStyle getFillIma() const; + StellarX::FillStyle getFillIma() const; //获取按钮填充图像 IMAGE* getFillImaImage() const; //获取按钮边框颜色 - COLORREF getButtonBorder() const; + COLORREF getButtonBorder() const; //获取按钮文字颜色 - COLORREF getButtonTextColor() const; + COLORREF getButtonTextColor() const; //获取按钮文字样式 - StellarX::ControlText getButtonTextStyle() const; - //获取按钮宽度 - int getButtonWidth() const; - //获取按钮高度 - int getButtonHeight() const; + StellarX::ControlText getButtonTextStyle() const; + //获取按钮宽度 + int getButtonWidth() const; + //获取按钮高度 + int getButtonHeight() const; public: - // === Tooltip API=== - //设置是否启用提示框 - void enableTooltip(bool on) { tipEnabled = on; if (!on) tipVisible = false; } - //设置提示框延时 - void setTooltipDelay(int ms) { tipDelayMs = (ms < 0 ? 0 : ms); } - //设置提示框是否跟随鼠标 - void setTooltipFollowCursor(bool on) { tipFollowCursor = on; } - //设置提示框位置偏移 - void setTooltipOffset(int dx, int dy) { tipOffsetX = dx; tipOffsetY = dy; } - //设置提示框样式 - void setTooltipStyle(COLORREF text, COLORREF bk, bool transparent); - //设置提示框文本 - void setTooltipText(const std::string& s){ tipTextClick = s; tipUserOverride = true; } - void setTooltipTextsForToggle(const std::string& onText, const std::string& offText); + // === Tooltip API=== + //设置是否启用提示框 + void enableTooltip(bool on) { tipEnabled = on; if (!on) tipVisible = false; } + //设置提示框延时 + void setTooltipDelay(int ms) { tipDelayMs = (ms < 0 ? 0 : ms); } + //设置提示框是否跟随鼠标 + void setTooltipFollowCursor(bool on) { tipFollowCursor = on; } + //设置提示框位置偏移 + void setTooltipOffset(int dx, int dy) { tipOffsetX = dx; tipOffsetY = dy; } + //设置提示框样式 + void setTooltipStyle(COLORREF text, COLORREF bk, bool transparent); + //设置提示框文本 + void setTooltipText(const std::string& s) { tipTextClick = s; tipUserOverride = true; } + void setTooltipTextsForToggle(const std::string& onText, const std::string& offText); private: - //初始化按钮 - void initButton(const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape, COLORREF ct, COLORREF cf, COLORREF ch); - //判断鼠标是否在圆形按钮内 - bool isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius); - //判断鼠标是否在椭圆按钮内 - bool isMouseInEllipse(int mouseX, int mouseY, int x, int y, int width, int height); + //初始化按钮 + void initButton(const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape, COLORREF ct, COLORREF cf, COLORREF ch); + //判断鼠标是否在圆形按钮内 + bool isMouseInCircle(int mouseX, int mouseY, int x, int y, int radius); + //判断鼠标是否在椭圆按钮内 + bool isMouseInEllipse(int mouseX, int mouseY, int x, int y, int width, int height); //获取对话框类型 - bool model() const override { return false; } - void cutButtonText(); - // 统一隐藏&恢复背景 - void hideTooltip(); - // 根据当前 click 状态选择文案 - void refreshTooltipTextForState(); - + bool model() const override { return false; } + void cutButtonText(); + // 统一隐藏&恢复背景 + void hideTooltip(); + // 根据当前 click 状态选择文案 + void refreshTooltipTextForState(); }; - diff --git a/include/StellarX/Canvas.h b/include/StellarX/Canvas.h index ac5a26e..c1fa4b4 100644 --- a/include/StellarX/Canvas.h +++ b/include/StellarX/Canvas.h @@ -23,54 +23,51 @@ class Canvas : public Control { protected: - std::vector> controls; - - StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE; //容器形状 - StellarX::FillMode canvasFillMode = StellarX::FillMode::Solid; //容器填充模式 - StellarX::LineStyle canvasLineStyle = StellarX::LineStyle::Solid; //线型 - int canvaslinewidth = 1; //线宽 - - COLORREF canvasBorderClor = RGB(0, 0, 0); //边框颜色 - COLORREF canvasBkClor = RGB(255,255,255); //背景颜色 + std::vector> controls; + StellarX::ControlShape shape = StellarX::ControlShape::RECTANGLE; //容器形状 + StellarX::FillMode canvasFillMode = StellarX::FillMode::Solid; //容器填充模式 + StellarX::LineStyle canvasLineStyle = StellarX::LineStyle::Solid; //线型 + int canvaslinewidth = 1; //线宽 - // 清除所有子控件 + COLORREF canvasBorderClor = RGB(0, 0, 0); //边框颜色 + COLORREF canvasBkClor = RGB(255, 255, 255); //背景颜色 + + // 清除所有子控件 void clearAllControls(); public: - Canvas(); - Canvas(int x, int y, int width, int height); - ~Canvas() {} + Canvas(); + Canvas(int x, int y, int width, int height); + ~Canvas() {} - void setX(int x)override; + void setX(int x)override; void setY(int y)override; - //绘制容器及其子控件 - void draw() override; - bool handleEvent(const ExMessage& msg) override; - //添加控件 - void addControl(std::unique_ptr control); - //设置容器样式 - void setShape(StellarX::ControlShape shape); - //设置容器填充模式 - void setCanvasfillMode(StellarX::FillMode mode); - //设置容器边框颜色 - void setBorderColor(COLORREF color); - //设置填充颜色 - void setCanvasBkColor(COLORREF color); - //设置线形 - void setCanvasLineStyle(StellarX::LineStyle style); - //设置线段宽度 - void setLinewidth(int width); - //设置不可见后传递给子控件重写 - void setIsVisible(bool visible) override; - void setDirty(bool dirty) override; - void onWindowResize() override; - void requestRepaint(Control* parent)override; - //获取子控件列表 - std::vector>& getControls() { return controls; } + //绘制容器及其子控件 + void draw() override; + bool handleEvent(const ExMessage& msg) override; + //添加控件 + void addControl(std::unique_ptr control); + //设置容器样式 + void setShape(StellarX::ControlShape shape); + //设置容器填充模式 + void setCanvasfillMode(StellarX::FillMode mode); + //设置容器边框颜色 + void setBorderColor(COLORREF color); + //设置填充颜色 + void setCanvasBkColor(COLORREF color); + //设置线形 + void setCanvasLineStyle(StellarX::LineStyle style); + //设置线段宽度 + void setLinewidth(int width); + //设置不可见后传递给子控件重写 + void setIsVisible(bool visible) override; + void setDirty(bool dirty) override; + void onWindowResize() override; + void requestRepaint(Control* parent)override; + //获取子控件列表 + std::vector>& getControls() { return controls; } private: - //用来检查对话框是否模态,此控件不做实现 - bool model() const override { return false; }; - + //用来检查对话框是否模态,此控件不做实现 + bool model() const override { return false; }; }; - diff --git a/include/StellarX/Control.h b/include/StellarX/Control.h index 1e58aff..c4cc2b7 100644 --- a/include/StellarX/Control.h +++ b/include/StellarX/Control.h @@ -17,7 +17,7 @@ ******************************************************************************/ #pragma once #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 +#define _WIN32_WINNT 0x0600 #endif #ifndef WINVER #define WINVER _WIN32_WINNT @@ -35,118 +35,119 @@ class Control { protected: - std::string id; // 控件ID - int localx,x, localy,y; // 左上角坐标 - int localWidth,width, localHeight,height; // 控件尺寸 - Control* parent = nullptr; // 父控件 - bool dirty = true; // 是否重绘 - bool show = true; // 是否显示 + std::string id; // 控件ID + int localx, x, localy, y; // 左上角坐标 + int localWidth, width, localHeight, height; // 控件尺寸 + Control* parent = nullptr; // 父控件 + bool dirty = true; // 是否重绘 + bool show = true; // 是否显示 - /* == 布局模式 == */ - StellarX::LayoutMode layoutMode = StellarX::LayoutMode::Fixed; // 布局模式 - StellarX::Anchor anchor_1 = StellarX::Anchor::Top; // 锚点 - StellarX::Anchor anchor_2 = StellarX::Anchor::Right; // 锚点 + /* == 布局模式 == */ + StellarX::LayoutMode layoutMode = StellarX::LayoutMode::Fixed; // 布局模式 + StellarX::Anchor anchor_1 = StellarX::Anchor::Top; // 锚点 + StellarX::Anchor anchor_2 = StellarX::Anchor::Right; // 锚点 - /* == 背景快照 == */ - IMAGE* saveBkImage = nullptr; - int saveBkX = 0, saveBkY = 0; // 快照保存起始坐标 - int saveWidth = 0, saveHeight = 0; // 快照保存尺寸 - bool hasSnap = false; // 当前是否持有有效快照 + /* == 背景快照 == */ + IMAGE* saveBkImage = nullptr; + int saveBkX = 0, saveBkY = 0; // 快照保存起始坐标 + int saveWidth = 0, saveHeight = 0; // 快照保存尺寸 + bool hasSnap = false; // 当前是否持有有效快照 - StellarX::RouRectangle rouRectangleSize; // 圆角矩形椭圆宽度和高度 + StellarX::RouRectangle rouRectangleSize; // 圆角矩形椭圆宽度和高度 - LOGFONT* currentFont = new LOGFONT(); // 保存当前字体样式和颜色 - COLORREF* currentColor = new COLORREF(); - COLORREF* currentBkColor = new COLORREF(); // 保存当前填充色 - COLORREF* currentBorderColor = new COLORREF(); // 边框颜色 - LINESTYLE* currentLineStyle = new LINESTYLE(); // 保存当前线型 + LOGFONT* currentFont = new LOGFONT(); // 保存当前字体样式和颜色 + COLORREF* currentColor = new COLORREF(); + COLORREF* currentBkColor = new COLORREF(); // 保存当前填充色 + COLORREF* currentBorderColor = new COLORREF(); // 边框颜色 + LINESTYLE* currentLineStyle = new LINESTYLE(); // 保存当前线型 - Control(const Control&) = delete; - Control& operator=(const Control&) = delete; - Control(Control&&) = delete; - Control& operator=(Control&&) = delete; + Control(const Control&) = delete; + Control& operator=(const Control&) = delete; + Control(Control&&) = delete; + Control& operator=(Control&&) = delete; - Control() : localx(0),x(0), localy(0),y(0), localWidth(100),width(100),height(100), localHeight(100) {} - Control(int x, int y, int width, int height) - : localx(x), x(x), localy(y), y(y), localWidth(width), width(width), height(height), localHeight(height){} + Control() : localx(0), x(0), localy(0), y(0), localWidth(100), width(100), height(100), localHeight(100) {} + Control(int x, int y, int width, int height) + : localx(x), x(x), localy(y), y(y), localWidth(width), width(width), height(height), localHeight(height) { + } public: - virtual ~Control() - { - delete currentFont; - delete currentColor; - delete currentBkColor; - delete currentBorderColor; - delete currentLineStyle; + virtual ~Control() + { + delete currentFont; + delete currentColor; + delete currentBkColor; + delete currentBorderColor; + delete currentLineStyle; - currentFont = nullptr; - currentColor = nullptr; - currentBkColor = nullptr; - currentBorderColor = nullptr; - currentLineStyle = nullptr; - discardBackground(); - } + currentFont = nullptr; + currentColor = nullptr; + currentBkColor = nullptr; + currentBorderColor = nullptr; + currentLineStyle = nullptr; + discardBackground(); + } protected: - //向上请求重绘 - virtual void requestRepaint(Control* parent); - //根控件/无父时触发重绘 - virtual void onRequestRepaintAsRoot(); + //向上请求重绘 + virtual void requestRepaint(Control* parent); + //根控件/无父时触发重绘 + virtual void onRequestRepaintAsRoot(); protected: - //保存背景快照 - virtual void saveBackground(int x, int y, int w, int h); - // putimage 回屏 - virtual void restBackground(); - // 释放快照(窗口重绘/尺寸变化后必须作废) - void discardBackground(); + //保存背景快照 + virtual void saveBackground(int x, int y, int w, int h); + // putimage 回屏 + virtual void restBackground(); + // 释放快照(窗口重绘/尺寸变化后必须作废) + void discardBackground(); public: - //释放快照重新保存,在尺寸变化时更新背景快照避免尺寸变化导致显示错位 - void updateBackground(); - //窗口变化丢快照 - virtual void onWindowResize(); - // 获取位置和尺寸 - int getX() const { return x; } - int getY() const { return y; } - int getWidth() const { return width; } - int getHeight() const { return height; } - int getRight() const { return x + width; } - int getBottom() const { return y + height; } - - int getLocalX() const { return localx; } - int getLocalY() const { return localy; } - int getLocalWidth() const { return localWidth; } - int getLocalHeight() const { return localHeight; } - int getLocalRight() const { return localx + localWidth; } - int getLocalBottom() const { return localy + localHeight; } + //释放快照重新保存,在尺寸变化时更新背景快照避免尺寸变化导致显示错位 + void updateBackground(); + //窗口变化丢快照 + virtual void onWindowResize(); + // 获取位置和尺寸 + int getX() const { return x; } + int getY() const { return y; } + int getWidth() const { return width; } + int getHeight() const { return height; } + int getRight() const { return x + width; } + int getBottom() const { return y + height; } - virtual void setX(int x) { this->x = x; dirty = true; } - virtual void setY(int y) { this->y = y; dirty = true; } - virtual void setWidth(int width) { this->width = width; dirty = true; } - virtual void setHeight(int height) { this->height = height; dirty = true; } + int getLocalX() const { return localx; } + int getLocalY() const { return localy; } + int getLocalWidth() const { return localWidth; } + int getLocalHeight() const { return localHeight; } + int getLocalRight() const { return localx + localWidth; } + int getLocalBottom() const { return localy + localHeight; } + + virtual void setX(int x) { this->x = x; dirty = true; } + virtual void setY(int y) { this->y = y; dirty = true; } + virtual void setWidth(int width) { this->width = width; dirty = true; } + virtual void setHeight(int height) { this->height = height; dirty = true; } public: - virtual void draw() = 0; - virtual bool handleEvent(const ExMessage& msg) = 0;//返回true代表事件已消费 - //设置是否显示 - virtual void setIsVisible(bool show); - //设置父容器指针 - void setParent(Control* parent) { this->parent = parent; } - //设置是否重绘 - virtual void setDirty(bool dirty) { this->dirty = dirty; } - //检查控件是否可见 - bool IsVisible() const { return show; }; - //获取控件id - std::string getId() const { return id; } - //检查是否为脏 - bool isDirty() { return dirty; } - //用来检查对话框是否模态,其他控件不用实现 - virtual bool model()const = 0; - //布局 - void setLayoutMode(StellarX::LayoutMode layoutMode_); - void setAnchor(StellarX::Anchor anchor_1, StellarX::Anchor anchor_2); - StellarX::Anchor getAnchor_1() const; - StellarX::Anchor getAnchor_2() const; - StellarX::LayoutMode getLayoutMode() const; + virtual void draw() = 0; + virtual bool handleEvent(const ExMessage& msg) = 0;//返回true代表事件已消费 + //设置是否显示 + virtual void setIsVisible(bool show); + //设置父容器指针 + void setParent(Control* parent) { this->parent = parent; } + //设置是否重绘 + virtual void setDirty(bool dirty) { this->dirty = dirty; } + //检查控件是否可见 + bool IsVisible() const { return show; }; + //获取控件id + std::string getId() const { return id; } + //检查是否为脏 + bool isDirty() { return dirty; } + //用来检查对话框是否模态,其他控件不用实现 + virtual bool model()const = 0; + //布局 + void setLayoutMode(StellarX::LayoutMode layoutMode_); + void setAnchor(StellarX::Anchor anchor_1, StellarX::Anchor anchor_2); + StellarX::Anchor getAnchor_1() const; + StellarX::Anchor getAnchor_2() const; + StellarX::LayoutMode getLayoutMode() const; protected: - void saveStyle(); - void restoreStyle(); + void saveStyle(); + void restoreStyle(); }; \ No newline at end of file diff --git a/include/StellarX/CoreTypes.h b/include/StellarX/CoreTypes.h index 3038717..dd2f1ac 100644 --- a/include/StellarX/CoreTypes.h +++ b/include/StellarX/CoreTypes.h @@ -27,363 +27,364 @@ */ namespace StellarX { - /** - * @枚举类名称: FillStyle - * @功能描述: 用来定义控件填充图案的枚举类 - * - * @详细说明: - * 根据此枚举类可以自定义控件填充图案 - * 可以在控件初始化时设置填充图案 - * 根据具体情况选择不同的填充图案 - * 默认填充图案为水平线 - * - * @取值说明: - * Horizontal - 水平线 - * Vertical - 垂直线 - * FDiagonal - 反斜线 - * BDiagonal - 正斜线 - * Cross - 十字 - * DiagCross - 网格 - * - * @使用示例: - * FillStyle var = FillStyle::Horizontal; - * - * @备注: - * 此枚举类仅支持图案填充模式 - */ - enum class FillStyle - { - Horizontal = HS_HORIZONTAL, // 水平线 - Vertical = HS_VERTICAL, // 垂直线 - FDiagonal = HS_FDIAGONAL, // 反斜线 - BDiagonal = HS_BDIAGONAL, // 正斜线 - Cross = HS_CROSS, // 十字 - DiagCross = HS_DIAGCROSS // 网格 - }; + /** + * @枚举类名称: FillStyle + * @功能描述: 用来定义控件填充图案的枚举类 + * + * @详细说明: + * 根据此枚举类可以自定义控件填充图案 + * 可以在控件初始化时设置填充图案 + * 根据具体情况选择不同的填充图案 + * 默认填充图案为水平线 + * + * @取值说明: + * Horizontal - 水平线 + * Vertical - 垂直线 + * FDiagonal - 反斜线 + * BDiagonal - 正斜线 + * Cross - 十字 + * DiagCross - 网格 + * + * @使用示例: + * FillStyle var = FillStyle::Horizontal; + * + * @备注: + * 此枚举类仅支持图案填充模式 + */ + enum class FillStyle + { + Horizontal = HS_HORIZONTAL, // 水平线 + Vertical = HS_VERTICAL, // 垂直线 + FDiagonal = HS_FDIAGONAL, // 反斜线 + BDiagonal = HS_BDIAGONAL, // 正斜线 + Cross = HS_CROSS, // 十字 + DiagCross = HS_DIAGCROSS // 网格 + }; - /** - * @枚举类名称: FillMode - * @功能描述: 用来定义控件填充模式的枚举类 - * - * @详细说明: - * 根据此枚举类可以自定义控件填充模式 - * 可以在控件初始化时设置填充模式 - * 根据具体情况选择不同的填充模式 - * 默认填充模式为固实填充 - * - * @取值说明: - * Solid - 固实填充 - * Null - 不填充 - * Hatched - 图案填充 - * Pattern - 自定义图案填充 - * DibPattern - 自定义图像填充 - * - * @使用示例: - * FillMode var = FillMode::Solid; - */ - enum class FillMode - { - Solid = BS_SOLID, //固实填充 - Null = BS_NULL, // 不填充 - Hatched = BS_HATCHED, // 图案填充 - Pattern = BS_PATTERN, // 自定义图案填充 - DibPattern = BS_DIBPATTERN // 自定义图像填充 - }; + /** + * @枚举类名称: FillMode + * @功能描述: 用来定义控件填充模式的枚举类 + * + * @详细说明: + * 根据此枚举类可以自定义控件填充模式 + * 可以在控件初始化时设置填充模式 + * 根据具体情况选择不同的填充模式 + * 默认填充模式为固实填充 + * + * @取值说明: + * Solid - 固实填充 + * Null - 不填充 + * Hatched - 图案填充 + * Pattern - 自定义图案填充 + * DibPattern - 自定义图像填充 + * + * @使用示例: + * FillMode var = FillMode::Solid; + */ + enum class FillMode + { + Solid = BS_SOLID, //固实填充 + Null = BS_NULL, // 不填充 + Hatched = BS_HATCHED, // 图案填充 + Pattern = BS_PATTERN, // 自定义图案填充 + DibPattern = BS_DIBPATTERN // 自定义图像填充 + }; - /** - * @枚举类名称: LineStyle - * @功能描述: 此枚举类用来定义控件边框线型 - * - * @详细说明: - * 根据此枚举类可以自定义控件边框线型 - * 可以在控件初始化时设置边框线型 - * 根据具体情况选择不同的线型 - * 默认线型为实线 - * - * @取值说明: - * Solid // 实线 - * Dash // 虚线 - * Dot // 点线 - * DashDot // 点划线 - * DashDotDot // 双点划线 - * Null // 无线 - * - * @使用示例: - * LineStyle var = LineStyle::Solid; - */ - enum class LineStyle - { - Solid = PS_SOLID, // 实线 - Dash = PS_DASH, // 虚线 - Dot = PS_DOT, // 点线 - DashDot = PS_DASHDOT, // 点划线 - DashDotDot = PS_DASHDOTDOT, // 双点划线 - Null = PS_NULL // 无线 - }; + /** + * @枚举类名称: LineStyle + * @功能描述: 此枚举类用来定义控件边框线型 + * + * @详细说明: + * 根据此枚举类可以自定义控件边框线型 + * 可以在控件初始化时设置边框线型 + * 根据具体情况选择不同的线型 + * 默认线型为实线 + * + * @取值说明: + * Solid // 实线 + * Dash // 虚线 + * Dot // 点线 + * DashDot // 点划线 + * DashDotDot // 双点划线 + * Null // 无线 + * + * @使用示例: + * LineStyle var = LineStyle::Solid; + */ + enum class LineStyle + { + Solid = PS_SOLID, // 实线 + Dash = PS_DASH, // 虚线 + Dot = PS_DOT, // 点线 + DashDot = PS_DASHDOT, // 点划线 + DashDotDot = PS_DASHDOTDOT, // 双点划线 + Null = PS_NULL // 无线 + }; - /** - * @结构体名称: ControlText - * @功能描述: 控件字体样式 可以自定义不同的样式 - * - * @详细说明: - * 主要使用的场景为:需要修改或想自定义控件字体大小,字体样式,颜色等 - * - * @成员说明: - * int nHeight = 0; - 字体高度 - * int nWidth = 0; - 字体宽度 如果为0则自适应 - * LPCTSTR lpszFace = "宋体"; - 字体名称 - * COLORREF color = RGB(0, 0, 0); - 字体颜色 - * int nEscapement = 0; - 字符串旋转角度 - * int nOrientation = 0; - 字符旋转角度 - * int nWeight = 0; - 字体粗细 范围0~1000 0表示默认 - * bool bItalic = false; - 是否斜体 - * bool bUnderline = false; - 是否下划线 - * bool bStrikeOut = false; - 是否删除线 - */ - struct ControlText - { - int nHeight = 0; //- 字体高度 - int nWidth = 0; //- 字体宽度 如果为0则自适应 - LPCTSTR lpszFace = "微软雅黑"; //- 字体名称 - COLORREF color = RGB(0, 0, 0); //- 字体颜色 - int nEscapement = 0; //- 字符串旋转角度 - int nOrientation = 0; //- 字符旋转角度 - int nWeight = 0; //- 字体粗细 范围0~1000 0表示默认 - bool bItalic = false; //- 是否斜体 - bool bUnderline = false; //- 是否下划线 - bool bStrikeOut = false; //- 是否删除线 + /** + * @结构体名称: ControlText + * @功能描述: 控件字体样式 可以自定义不同的样式 + * + * @详细说明: + * 主要使用的场景为:需要修改或想自定义控件字体大小,字体样式,颜色等 + * + * @成员说明: + * int nHeight = 0; - 字体高度 + * int nWidth = 0; - 字体宽度 如果为0则自适应 + * LPCTSTR lpszFace = "宋体"; - 字体名称 + * COLORREF color = RGB(0, 0, 0); - 字体颜色 + * int nEscapement = 0; - 字符串旋转角度 + * int nOrientation = 0; - 字符旋转角度 + * int nWeight = 0; - 字体粗细 范围0~1000 0表示默认 + * bool bItalic = false; - 是否斜体 + * bool bUnderline = false; - 是否下划线 + * bool bStrikeOut = false; - 是否删除线 + */ + struct ControlText + { + int nHeight = 0; //- 字体高度 + int nWidth = 0; //- 字体宽度 如果为0则自适应 + LPCTSTR lpszFace = "微软雅黑"; //- 字体名称 + COLORREF color = RGB(0, 0, 0); //- 字体颜色 + int nEscapement = 0; //- 字符串旋转角度 + int nOrientation = 0; //- 字符旋转角度 + int nWeight = 0; //- 字体粗细 范围0~1000 0表示默认 + bool bItalic = false; //- 是否斜体 + bool bUnderline = false; //- 是否下划线 + bool bStrikeOut = false; //- 是否删除线 - bool operator!=(const ControlText& text); - ControlText& operator=(const ControlText& text); - }; + bool operator!=(const ControlText& text); + ControlText& operator=(const ControlText& text); + }; - /** - * @枚举名称: ControlShape - * @功能描述: 枚举控件的不同几何样式 - * - * @详细说明: - * 定义了四种(有无边框算一种)不同的几何样式,可以根据具体需求 - * 自定义控件的形状。 - * - * @取值说明: - * RECTANGLE = 1, //有边框矩形 - * B_RECTANGLE, //无边框矩形 - * ROUND_RECTANGLE, //有边框圆角矩形 - * B_ROUND_RECTANGLE, //无边框圆角矩形 - * CIRCLE, //有边框圆形 - * B_CIRCLE, //无边框圆形 - * ELLIPSE, //有边框椭圆 - * B_ELLIPSE //无边框椭圆 - * - * @使用示例: - * ControlShape shape = ControlShape::ELLIPSE; - * - * @备注: - * 按钮类支持所有形状,部分控件只支持部分形状,具体请参考控件类。 - */ - enum class ControlShape - { - RECTANGLE = 1, //有边框矩形 - B_RECTANGLE, //无边框矩形 - ROUND_RECTANGLE, //有边框圆角矩形 - B_ROUND_RECTANGLE, //无边框圆角矩形 - CIRCLE, //有边框圆形 - B_CIRCLE, //无边框圆形 - ELLIPSE, //有边框椭圆 - B_ELLIPSE //无边框椭圆 - }; + /** + * @枚举名称: ControlShape + * @功能描述: 枚举控件的不同几何样式 + * + * @详细说明: + * 定义了四种(有无边框算一种)不同的几何样式,可以根据具体需求 + * 自定义控件的形状。 + * + * @取值说明: + * RECTANGLE = 1, //有边框矩形 + * B_RECTANGLE, //无边框矩形 + * ROUND_RECTANGLE, //有边框圆角矩形 + * B_ROUND_RECTANGLE, //无边框圆角矩形 + * CIRCLE, //有边框圆形 + * B_CIRCLE, //无边框圆形 + * ELLIPSE, //有边框椭圆 + * B_ELLIPSE //无边框椭圆 + * + * @使用示例: + * ControlShape shape = ControlShape::ELLIPSE; + * + * @备注: + * 按钮类支持所有形状,部分控件只支持部分形状,具体请参考控件类。 + */ + enum class ControlShape + { + RECTANGLE = 1, //有边框矩形 + B_RECTANGLE, //无边框矩形 + ROUND_RECTANGLE, //有边框圆角矩形 + B_ROUND_RECTANGLE, //无边框圆角矩形 + CIRCLE, //有边框圆形 + B_CIRCLE, //无边框圆形 + ELLIPSE, //有边框椭圆 + B_ELLIPSE //无边框椭圆 + }; - /** - * @枚举类名称: TextBoxmode - * @功能描述: 定义了文本框的两种模式 - * - * @详细说明: - * 需要限制文本框是否接受用户输入时使用 - * - * @取值说明: - * INPUT_MODE, // 用户可输入模式 - * READONLY_MODE // 只读模式 - */ - enum class TextBoxmode - { - INPUT_MODE, // 用户可输入模式 - READONLY_MODE // 只读模式 - }; + /** + * @枚举类名称: TextBoxmode + * @功能描述: 定义了文本框的两种模式 + * + * @详细说明: + * 需要限制文本框是否接受用户输入时使用 + * + * @取值说明: + * INPUT_MODE, // 用户可输入模式 + * READONLY_MODE // 只读模式 + */ + enum class TextBoxmode + { + INPUT_MODE, // 用户可输入模式 + READONLY_MODE, // 只读模式 + PASSWORD_MODE// 密码模式 + }; - /** - * @枚举名称: ButtonMode - * @功能描述: 定义按钮的工作模式 - * - * @详细说明: - * 根据按钮的工作模式,按钮可以有不同的行为。 - * 用户可以在具体情况下设置按钮的工作模式。 - * - * @取值说明: - * NORMAL = 1, - 普通模式,点击后触发回调,但不会保持状态。 - * TOGGLE, - 切换模式,点击后会在选中和未选中之间切换,触发不同的回调函数。 - * DISABLED - 禁用模式,按钮不可点击,显示为灰色,文本显示删除线。 - * - * @使用示例: - * ButtonMode mode = ButtonMode::NORMAL; - */ - enum class ButtonMode - { - NORMAL = 1, //普通模式 - TOGGLE, //切换模式 - DISABLED //禁用模式 - }; + /** + * @枚举名称: ButtonMode + * @功能描述: 定义按钮的工作模式 + * + * @详细说明: + * 根据按钮的工作模式,按钮可以有不同的行为。 + * 用户可以在具体情况下设置按钮的工作模式。 + * + * @取值说明: + * NORMAL = 1, - 普通模式,点击后触发回调,但不会保持状态。 + * TOGGLE, - 切换模式,点击后会在选中和未选中之间切换,触发不同的回调函数。 + * DISABLED - 禁用模式,按钮不可点击,显示为灰色,文本显示删除线。 + * + * @使用示例: + * ButtonMode mode = ButtonMode::NORMAL; + */ + enum class ButtonMode + { + NORMAL = 1, //普通模式 + TOGGLE, //切换模式 + DISABLED //禁用模式 + }; - /** - * @结构体名称: RouRectangle - * @功能描述: 定义了控件圆角矩形样式时圆角的椭圆尺寸 - * - * @详细说明: - * 需要修改控件圆角矩形样式时的圆角椭圆。 - * - * @成员说明: - * int ROUND_RECTANGLEwidth = 20; //构成圆角矩形的圆角的椭圆的宽度。 - * int ROUND_RECTANGLEheight = 20; //构成圆角矩形的圆角的椭圆的高度。 - */ - struct RouRectangle - { - int ROUND_RECTANGLEwidth = 20; //构成圆角矩形的圆角的椭圆的宽度。 - int ROUND_RECTANGLEheight = 20; //构成圆角矩形的圆角的椭圆的高度。 - }; + /** + * @结构体名称: RouRectangle + * @功能描述: 定义了控件圆角矩形样式时圆角的椭圆尺寸 + * + * @详细说明: + * 需要修改控件圆角矩形样式时的圆角椭圆。 + * + * @成员说明: + * int ROUND_RECTANGLEwidth = 20; //构成圆角矩形的圆角的椭圆的宽度。 + * int ROUND_RECTANGLEheight = 20; //构成圆角矩形的圆角的椭圆的高度。 + */ + struct RouRectangle + { + int ROUND_RECTANGLEwidth = 20; //构成圆角矩形的圆角的椭圆的宽度。 + int ROUND_RECTANGLEheight = 20; //构成圆角矩形的圆角的椭圆的高度。 + }; - // 消息框类型 - enum class MessageBoxType - { - OK, // 只有确定按钮 - OKCancel, // 确定和取消按钮 - YesNo, // 是和否按钮 - YesNoCancel, // 是、否和取消按钮 - RetryCancel, // 重试和取消按钮 - AbortRetryIgnore, // 中止、重试和忽略按钮 - }; + // 消息框类型 + enum class MessageBoxType + { + OK, // 只有确定按钮 + OKCancel, // 确定和取消按钮 + YesNo, // 是和否按钮 + YesNoCancel, // 是、否和取消按钮 + RetryCancel, // 重试和取消按钮 + AbortRetryIgnore, // 中止、重试和忽略按钮 + }; - // 消息框返回值 - enum class MessageBoxResult - { - OK = 1, // 确定按钮 - Cancel = 2, // 取消按钮 - Yes = 6, // 是按钮 - No = 7, // 否按钮 - Abort = 3, // 中止按钮 - Retry = 4, // 重试按钮 - Ignore = 5 // 忽略按钮 - }; + // 消息框返回值 + enum class MessageBoxResult + { + OK = 1, // 确定按钮 + Cancel = 2, // 取消按钮 + Yes = 6, // 是按钮 + No = 7, // 否按钮 + Abort = 3, // 中止按钮 + Retry = 4, // 重试按钮 + Ignore = 5 // 忽略按钮 + }; #if 0 //布局管理器相关 —待实现— - /* - * - *@枚举名称: LayoutKind - * @功能描述 : 定义布局管理类型 - * - *@详细说明 : - * 根据布局管理类型,控件可以有不同的布局方式。 - * 用户可以在具体情况下设置布局管理类型。 - * - * @取值说明 : - * Absolute:不管,保持子控件自己的坐标(向后兼容)。 - * HBox: 水平方向排队;支持固定宽、权重分配、对齐、拉伸。 - * VBox: 竖直方向排队;同上。 - * Grid(网格):按行列摆;支持固定/自适应/权重行列;支持跨行/跨列;单元内对齐/拉伸。 - * - */ - // 布局类型 - enum class LayoutKind - { - Absolute = 1, - HBox, - VBox, - Grid, - Flow, - Stack - }; + /* + * + *@枚举名称: LayoutKind + * @功能描述 : 定义布局管理类型 + * + *@详细说明 : + * 根据布局管理类型,控件可以有不同的布局方式。 + * 用户可以在具体情况下设置布局管理类型。 + * + * @取值说明 : + * Absolute:不管,保持子控件自己的坐标(向后兼容)。 + * HBox: 水平方向排队;支持固定宽、权重分配、对齐、拉伸。 + * VBox: 竖直方向排队;同上。 + * Grid(网格):按行列摆;支持固定/自适应/权重行列;支持跨行/跨列;单元内对齐/拉伸。 + * + */ + // 布局类型 + enum class LayoutKind + { + Absolute = 1, + HBox, + VBox, + Grid, + Flow, + Stack + }; - // 布局参数 - struct LayoutParams - { - // 边距左、右、上、下 - int marginL = 0, marginR = 0, marginT = 0, marginB = 0; - // 固定尺寸(>=0 强制;-1 用控件当前尺寸) - int fixedW = -1, fixedH = -1; - // 主轴权重(HBox=宽度、VBox=高度、Grid见下) - float weight = 0.f; - // 对齐(非拉伸时生效) - enum Align { Start = 0, Center = 1, End = 2, Stretch = 3 }; - int alignX = Start; // HBox: 次轴=Y;VBox: 次轴=X;Grid: 单元内 - int alignY = Start; // Grid :控制单元内垂直(HBox / VBox通常只用 alignX) - // Grid 专用(可先不做) - int gridRow = 0, gridCol = 0, rowSpan = 1, colSpan = 1; - // Flow 专用(可先不做) - int flowBreak = 0; // 1=强制换行 - }; + // 布局参数 + struct LayoutParams + { + // 边距左、右、上、下 + int marginL = 0, marginR = 0, marginT = 0, marginB = 0; + // 固定尺寸(>=0 强制;-1 用控件当前尺寸) + int fixedW = -1, fixedH = -1; + // 主轴权重(HBox=宽度、VBox=高度、Grid见下) + float weight = 0.f; + // 对齐(非拉伸时生效) + enum Align { Start = 0, Center = 1, End = 2, Stretch = 3 }; + int alignX = Start; // HBox: 次轴=Y;VBox: 次轴=X;Grid: 单元内 + int alignY = Start; // Grid :控制单元内垂直(HBox / VBox通常只用 alignX) + // Grid 专用(可先不做) + int gridRow = 0, gridCol = 0, rowSpan = 1, colSpan = 1; + // Flow 专用(可先不做) + int flowBreak = 0; // 1=强制换行 + }; #endif - /* - * @枚举名称: TabPlacement - * @功能描述: 定义了选项卡页签的不同位置 - * - * @详细说明: - * 根据选项卡页签的位置,选项卡页签可以有不同的布局方式。 - * - * @成员说明: - * Top, - 选项卡页签位于顶部 - * Bottom, - 选项卡页签位于底部 - * Left, - 选项卡页签位于左侧 - * Right - 选项卡页签位于右侧 - * - * @使用示例: - * TabPlacement placement = TabPlacement::Top; - */ - enum class TabPlacement - { - Top, - Bottom, - Left, - Right - }; - /* - * @枚举名称: LayoutMode - * @功能描述: 定义了两种布局模式 - * - * @详细说明: - * 根据不同模式,在窗口拉伸时采用不同的布局策略 - * - * @成员说明: - * Fixed, - 固定布局 - * AnchorToEdges - 锚定布局 - * - * @使用示例: - * LayoutMode mode = LayoutMode::Fixed; - */ - enum class LayoutMode - { - Fixed, - AnchorToEdges - }; - /* - * @枚举名称: Anchor - * @功能描述: 定义了控件相对于窗口锚定的位置 - * - * @详细说明: - * 根据不同的锚定位置,有不同的拉伸策略 - * - * @成员说明: - * Top, - 锚定上边,控件上边与窗口上侧距离保持不变 - * Bottom, - 锚定底边,控件底边与窗口底边距离保持不变 - * Left, - 锚定左边,控件左边与窗口左侧距离保持不变 - * Right - 锚定右边,控件上边与窗口右侧距离保持不变 - * - * @使用示例: - * Anchor a = Anchor::Top; - */ - enum class Anchor - { - NoAnchor = 0, - Left = 1, - Right, - Top, - Bottom - }; + /* + * @枚举名称: TabPlacement + * @功能描述: 定义了选项卡页签的不同位置 + * + * @详细说明: + * 根据选项卡页签的位置,选项卡页签可以有不同的布局方式。 + * + * @成员说明: + * Top, - 选项卡页签位于顶部 + * Bottom, - 选项卡页签位于底部 + * Left, - 选项卡页签位于左侧 + * Right - 选项卡页签位于右侧 + * + * @使用示例: + * TabPlacement placement = TabPlacement::Top; + */ + enum class TabPlacement + { + Top, + Bottom, + Left, + Right + }; + /* + * @枚举名称: LayoutMode + * @功能描述: 定义了两种布局模式 + * + * @详细说明: + * 根据不同模式,在窗口拉伸时采用不同的布局策略 + * + * @成员说明: + * Fixed, - 固定布局 + * AnchorToEdges - 锚定布局 + * + * @使用示例: + * LayoutMode mode = LayoutMode::Fixed; + */ + enum class LayoutMode + { + Fixed, + AnchorToEdges + }; + /* + * @枚举名称: Anchor + * @功能描述: 定义了控件相对于窗口锚定的位置 + * + * @详细说明: + * 根据不同的锚定位置,有不同的拉伸策略 + * + * @成员说明: + * Top, - 锚定上边,控件上边与窗口上侧距离保持不变 + * Bottom, - 锚定底边,控件底边与窗口底边距离保持不变 + * Left, - 锚定左边,控件左边与窗口左侧距离保持不变 + * Right - 锚定右边,控件上边与窗口右侧距离保持不变 + * + * @使用示例: + * Anchor a = Anchor::Top; + */ + enum class Anchor + { + NoAnchor = 0, + Left = 1, + Right, + Top, + Bottom + }; } \ No newline at end of file diff --git a/include/StellarX/Dialog.h b/include/StellarX/Dialog.h index 1205e17..7463c27 100644 --- a/include/StellarX/Dialog.h +++ b/include/StellarX/Dialog.h @@ -30,7 +30,7 @@ #define titleToTextMargin 10 //标题到文本的距离 #define textToBorderMargin 10 //文本到边框的距离 #define BorderWidth 3 //边框宽度 -class Dialog : public Canvas +class Dialog : public Canvas { Window& hWnd; //窗口引用 @@ -45,19 +45,17 @@ class Dialog : public Canvas std::string message; //提示信息 std::vector lines; //消息内容按行分割 - - bool needsInitialization = true; //是否需要初始化 + bool needsInitialization = true; //是否需要初始化 bool close = false; //是否关闭 bool modal = true; //是否模态 - COLORREF backgroundColor = RGB(240, 240, 240); //背景颜色 + COLORREF backgroundColor = RGB(240, 240, 240); //背景颜色 COLORREF borderColor = RGB(100, 100, 100); //边框颜色 COLORREF buttonTrueColor = RGB(211, 190, 190); //按钮被点击颜色 COLORREF buttonFalseColor = RGB(215, 215, 215); //按钮未被点击颜色 COLORREF buttonHoverColor = RGB(224, 224, 224); //按钮悬浮颜色 - Button* closeButton = nullptr; //关闭按钮 StellarX::MessageBoxResult result = StellarX::MessageBoxResult::Cancel; // 对话框结果 @@ -76,8 +74,7 @@ public: //获取对话框消息,用以去重 std::string GetCaption() const; //获取对话框消息,用以去重 - std::string GetText() const; - + std::string GetText() const; public: Dialog(Window& hWnd, std::string text, std::string message = "对话框", StellarX::MessageBoxType type = StellarX::MessageBoxType::OK, bool modal = true); @@ -105,28 +102,27 @@ public: // 显示对话框 void Show(); // 关闭对话框 - void Close(); + void Close(); //初始化 void setInitialization(bool init); - private: // 初始化按钮 - void initButtons(); + void initButtons(); // 初始化关闭按钮 - void initCloseButton(); + void initCloseButton(); // 初始化标题 - void initTitle(); + void initTitle(); // 按行分割消息内容 - void splitMessageLines(); + void splitMessageLines(); // 获取文本大小 - void getTextSize(); + void getTextSize(); //初始化对话框尺寸 - void initDialogSize(); + void initDialogSize(); void addControl(std::unique_ptr control); - + // 清除所有控件 - void clearControls(); + void clearControls(); //创建对话框按钮 std::unique_ptr