feat: add a new awesome feature
This commit is contained in:
52
README.md
52
README.md
@@ -117,42 +117,42 @@ StellarX/
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// 只需包含这一个头文件即可使用所有功能
|
// 只需包含这一个头文件即可使用所有功能
|
||||||
#include "StellarX/StellarX.h"
|
#include "StellarX.h"
|
||||||
|
|
||||||
// 程序入口点(请使用WinMain以获得更好的兼容性)
|
// 程序入口点(请使用WinMain以获得更好的兼容性)
|
||||||
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) {
|
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) {
|
||||||
|
|
||||||
// 1. 创建一个640x480的窗口,背景为白色,标题为"我的应用"
|
|
||||||
StellarX::Window mainWindow(640, 480, 0, RGB(255, 255, 255), "我的第一个星垣应用");
|
|
||||||
|
|
||||||
// 2. 创建一个按钮 (使用智能指针管理)
|
// 1. 创建一个640x480的窗口,背景为白色,标题为"我的应用"
|
||||||
auto myButton = std::make_unique<StellarX::Button>(
|
Window mainWindow(640, 480, 0, RGB(255, 255, 255), "我的第一个星垣应用");
|
||||||
250, 200, 140, 40, // x, y, 宽度, 高度
|
|
||||||
"点击我", // 按钮文本
|
|
||||||
StellarX::ButtonMode::NORMAL,
|
|
||||||
StellarX::ControlShape::ROUND_RECTANGLE
|
|
||||||
);
|
|
||||||
|
|
||||||
// 3. 为按钮设置点击事件(使用Lambda表达式)
|
// 2. 创建一个按钮 (使用智能指针管理)
|
||||||
myButton->setOnClickListener([]() {
|
auto myButton = std::make_unique<Button>(
|
||||||
MessageBox(nullptr, L"Hello, 星垣!", L"问候", MB_OK | MB_ICONINFORMATION);
|
250, 200, 140, 40, // x, y, 宽度, 高度
|
||||||
});
|
"点击我", // 按钮文本
|
||||||
|
StellarX::ButtonMode::NORMAL,
|
||||||
|
StellarX::ControlShape::ROUND_RECTANGLE
|
||||||
|
);
|
||||||
|
|
||||||
// 4. (可选)设置按钮样式
|
// 3. 为按钮设置点击事件(使用Lambda表达式)
|
||||||
myButton->textStyle.nHeight = 20;
|
myButton->setOnClickListener([]() {
|
||||||
myButton->textStyle.color = RGB(0, 0, 128); // 深蓝色文字
|
MessageBox(nullptr, "Hello, 星垣!", "问候", MB_OK | MB_ICONINFORMATION);
|
||||||
myButton->setButtonBorder(RGB(0, 128, 255)); // 蓝色边框
|
});
|
||||||
|
|
||||||
// 5. 将按钮添加到窗口
|
// 4. (可选)设置按钮样式
|
||||||
mainWindow.addControl(std::move(myButton));
|
myButton->textStyle.nHeight = 20;
|
||||||
|
myButton->textStyle.color = RGB(0, 0, 128); // 深蓝色文字
|
||||||
|
myButton->setButtonBorder(RGB(0, 128, 255)); // 蓝色边框
|
||||||
|
|
||||||
// 6. 绘制窗口
|
// 5. 将按钮添加到窗口
|
||||||
mainWindow.draw();
|
mainWindow.addControl(std::move(myButton));
|
||||||
|
|
||||||
// 7. 进入消息循环,等待用户交互
|
// 6. 绘制窗口
|
||||||
mainWindow.runEventLoop();
|
mainWindow.draw();
|
||||||
|
|
||||||
return 0;
|
// 7. 进入消息循环,等待用户交互
|
||||||
|
mainWindow.runEventLoop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Button.h"
|
#include "StellarX/Button.h"
|
||||||
|
|
||||||
Button::Button(int x, int y, int width, int height, const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape)
|
Button::Button(int x, int y, int width, int height, const std::string text, StellarX::ButtonMode mode, StellarX::ControlShape shape)
|
||||||
: Control(x, y, width, height)
|
: Control(x, y, width, height)
|
||||||
@@ -52,7 +52,7 @@ void Button::draw()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 修改这里:确保点击状态的颜色正确显示
|
// 确保点击状态的颜色正确显示
|
||||||
// 点击状态优先级最高,然后是悬停状态,最后是默认状态
|
// 点击状态优先级最高,然后是悬停状态,最后是默认状态
|
||||||
if (click)
|
if (click)
|
||||||
setfillcolor(buttonTrueColor);
|
setfillcolor(buttonTrueColor);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Canvas.h"
|
#include "StellarX/Canvas.h"
|
||||||
|
|
||||||
Canvas::Canvas(int x, int y, int width, int height)
|
Canvas::Canvas(int x, int y, int width, int height)
|
||||||
:Control(x, y, width, height) {}
|
:Control(x, y, width, height) {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Control.h"
|
#include "StellarX/Control.h"
|
||||||
|
|
||||||
StellarX::ControlText& StellarX::ControlText::operator=(const ControlText& text)
|
StellarX::ControlText& StellarX::ControlText::operator=(const ControlText& text)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Label.h"
|
#include "StellarX/Label.h"
|
||||||
|
|
||||||
Label::Label()
|
Label::Label()
|
||||||
:Control(0, 0, 0, 0)
|
:Control(0, 0, 0, 0)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Table.h"
|
#include "StellarX/Table.h"
|
||||||
// 绘制表格的当前页
|
// 绘制表格的当前页
|
||||||
// 使用双循环绘制行和列,考虑分页偏移
|
// 使用双循环绘制行和列,考虑分页偏移
|
||||||
void Table::drawTable()
|
void Table::drawTable()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// TextBox.cpp
|
// TextBox.cpp
|
||||||
#include "TextBox.h"
|
#include "StellarX/TextBox.h"
|
||||||
|
|
||||||
|
|
||||||
TextBox::TextBox(int x, int y, int width, int height, std::string text, StellarX::TextBoxmode mode, StellarX::ControlShape shape)
|
TextBox::TextBox(int x, int y, int width, int height, std::string text, StellarX::TextBoxmode mode, StellarX::ControlShape shape)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Window.h"
|
#include "StellarX/Window.h"
|
||||||
|
|
||||||
Window::Window(int width, int height, int mode)
|
Window::Window(int width, int height, int mode)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user