# StellarX GUI 框架控件 API 文档 (StellarX GUI Framework Controls API Documentation) ## Control 类 (抽象基类) **描述:** `Control` 是所有控件的抽象基类,定义了通用的属性和接口,包括位置、尺寸、可见性、重绘标记等基础功能。它提供绘图状态的保存与恢复机制,确保控件的绘制操作不影响全局绘图状态。此外还声明了一系列供子类实现的纯虚函数(如 `draw()` 和 `handleEvent()`),并禁止拷贝(支持移动语义)以防止意外的复制开销。一般情况下,`Control` 不直接实例化,而是作为其他具体控件的父类存在。 **Description:** `Control` is the abstract base class for all controls, defining common properties and interfaces such as position, size, visibility, and the “dirty” flag for redraw. It provides mechanisms to save and restore drawing state to ensure a control’s drawing operations do not affect the global canvas state. It also declares a set of pure virtual functions for subclasses to implement (e.g. `draw()` for rendering and `handleEvent()` for event handling), and it disables copying (but supports move semantics) to prevent accidental heavy copy operations. Typically, `Control` is not instantiated directly; it serves as a base class for concrete controls. **特性 (Features):** - 定义控件的基本属性(坐标、尺寸、脏标记等)并提供对应的存取方法 *(Defines basic properties of a control – position, size, “dirty” redraw flag, etc. – and provides getters/setters for them.)* - 提供绘图状态管理接口(如 `saveStyle()` / `restoreStyle()`)用于在控件绘制前后保存和恢复全局画笔状态 *(Provides drawing state management (e.g. `saveStyle()` / `restoreStyle()`) to save and restore the global drawing state before and after control rendering.)* - 声明纯虚函数接口,如 `draw()`(绘制控件)和 `handleEvent()`(处理事件),所有具体控件都需实现 *(Declares pure virtual functions such as `draw()` (to draw the control) and `handleEvent()` (to handle input events), which all concrete control subclasses must implement.)* - 禁止拷贝构造和赋值(但支持移动语义),防止控件被不小心复制 *(Copy construction and assignment are disabled (move semantics are supported) to prevent unintended copying of controls.)* ```mermaid classDiagram class Control { +int getX() +int getY() +int getWidth() +int getHeight() +int getRight() +int getBottom() +int getLocalX() +int getLocalY() +int getLocalWidth() +int getLocalHeight() +void setX(int) +void setY(int) +void setWidth(int) +void setHeight(int) +void setIsVisible(bool) +bool isVisible() +void setDirty(bool) +bool isDirty() +void updateBackground() +virtual void draw() = 0 +virtual bool handleEvent(const ExMessage&) = 0 <> } class Canvas { +void addControl(std::unique_ptr) +void removeControl(Control*) +void clearAllControls() +void setCanvasBkColor(COLORREF) +void setBorderColor(COLORREF) +void setShape(ControlShape) +void setCanvasFillMode(FillMode) +void setCanvasLineStyle(LineStyle) +void setAnchor(AnchorMode) +void adaptiveLayout() } class Label { +void setText(string) +void setTextBkColor(COLORREF) +void setTextdisap(bool) } class Button { +void setOnClickListener(function) +void setOnToggleOnListener(function) +void setOnToggleOffListener(function) +void setTooltipText(string) +void setTooltipOffset(int, int) } class TextBox { +string getText() +void setText(string) +void setMaxCharLen(size_t) +void setMode(TextBoxMode) } class TabControl { +void add(pair< unique_ptr