Compare commits
2 Commits
6aa522f3e2
...
b71f601088
| Author | SHA1 | Date | |
|---|---|---|---|
| b71f601088 | |||
| 767169d647 |
7
.claude/settings.local.json
Normal file
7
.claude/settings.local.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(cmake:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
# EditorConfig helps maintain consistent coding styles
|
||||
# https://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8-bom
|
||||
end_of_line = crlf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{cpp,h,hpp}]
|
||||
indent_style = tab
|
||||
|
||||
[*.{json,xml,yml,yaml,md}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
14
.vscode/settings.json
vendored
Normal file
14
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"files.encoding": "utf8",
|
||||
"files.autoGuessEncoding": false,
|
||||
"editorconfig.enable": true,
|
||||
"[cpp]": {
|
||||
"files.encoding": "utf8-bom"
|
||||
},
|
||||
"[h]": {
|
||||
"files.encoding": "utf8-bom"
|
||||
},
|
||||
"[c]": {
|
||||
"files.encoding": "utf8-bom"
|
||||
}
|
||||
}
|
||||
115
CLAUDE.md
Normal file
115
CLAUDE.md
Normal file
@@ -0,0 +1,115 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
EzUI is a Windows desktop UI framework built on Direct2D. It provides a C++ API for creating modern Windows applications with custom controls, layouts, and styling.
|
||||
|
||||
## Build Commands
|
||||
|
||||
The project uses CMake for building. Prebuilt libraries exist in `lib/` for both x64 and x86 architectures.
|
||||
|
||||
### Build Static Library (EzUI)
|
||||
|
||||
```bash
|
||||
# Generate and build Debug x64
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -S . -B build/x64
|
||||
cmake --build build/x64 --config Debug
|
||||
|
||||
# Generate and build Release x64
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -S . -B build/x64
|
||||
cmake --build build/x64 --config Release
|
||||
|
||||
# Or use build.bat to build all configurations at once
|
||||
build.bat
|
||||
```
|
||||
|
||||
### Build Demos
|
||||
|
||||
```bash
|
||||
# Build demos (from demo/ directory)
|
||||
cd demo
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
cmake --build . --config Debug/Release
|
||||
```
|
||||
|
||||
Key demo projects in `demo/`:
|
||||
- `helloWorld` - Basic controls demo
|
||||
- `QQ` - QQ-style login UI demo
|
||||
- `kugou` - Kugou music player demo
|
||||
- `TableViewDemo` - TableView control demo
|
||||
|
||||
## Architecture
|
||||
|
||||
### Core Classes
|
||||
|
||||
- **Window** ([include/EzUI/Window.h](include/EzUI/Window.h)) - Top-level window, inherits from Object, manages HWND, handles message loop
|
||||
- **Control** ([include/EzUI/Control.h](include/EzUI/Control.h)) - Base class for all UI elements, contains m_controls (child collection), Style/HoverStyle/ActiveStyle/DisabledStyle
|
||||
- **Application** ([include/EzUI/Application.h](include/EzUI/Application.h)) - Manages message loop, resource loading, high DPI
|
||||
|
||||
### Layout System
|
||||
|
||||
- **HLayout** - Horizontal layout container
|
||||
- **VLayout** - Vertical layout container
|
||||
- Uses DockStyle (None, Horizontal, Vertical, Fill) for child control positioning
|
||||
- Layout state machine: None → Pend → Layouting → None
|
||||
|
||||
### Rendering
|
||||
|
||||
- **DXRender** (Direct2D) handles all graphics
|
||||
- Paint pipeline: OnPaintBefore → OnBackgroundPaint → OnForePaint → OnBorderPaint → OnChildPaint
|
||||
- Uses PushLayer/PopLayer for clipping regions
|
||||
- Color uses BGRA format internally
|
||||
|
||||
### Control Hierarchy
|
||||
|
||||
```
|
||||
Object
|
||||
├── Control (base for all widgets)
|
||||
│ ├── Window (top-level, owns HWND)
|
||||
│ ├── BorderlessWindow
|
||||
│ ├── LayeredWindow
|
||||
│ ├── PopupWindow
|
||||
│ ├── Label
|
||||
│ ├── Button
|
||||
│ ├── TextBox
|
||||
│ ├── ComboBox
|
||||
│ ├── CheckBox
|
||||
│ ├── RadioButton
|
||||
│ ├── PictureBox
|
||||
│ ├── ProgressBar
|
||||
│ ├── Menu
|
||||
│ ├── ScrollBar / HScrollBar / VScrollBar
|
||||
│ ├── HLayout / VLayout
|
||||
│ ├── HListView / VListView / TileListView / PagedListView
|
||||
│ ├── TreeView
|
||||
│ ├── TableView
|
||||
│ └── TabLayout
|
||||
└── IFrame (container frame)
|
||||
```
|
||||
|
||||
### Event System
|
||||
|
||||
Events defined in [include/EzUI/EzUI.h](include/EzUI/EzUI.h):
|
||||
- Mouse: OnMouseDown, OnMouseUp, OnMouseMove, OnMouseEnter, OnMouseLeave, OnMouseWheel, OnMouseDoubleClick
|
||||
- Keyboard: OnKeyDown, OnKeyUp, OnKeyChar
|
||||
- Focus: OnFocus, OnKillFocus
|
||||
- Paint: OnPaint
|
||||
- Layout: OnMove, OnSize
|
||||
|
||||
ControlState enum: None, Static, Disabled, Checked, Hover, Active
|
||||
|
||||
### Key Patterns
|
||||
|
||||
1. **Thread Safety**: Use `BeginInvoke()` and `Invoke()` for cross-thread UI updates (uses hidden message window)
|
||||
2. **Memory Management**: Controls can be parented - parent deletes children. Use `Attach()` / `Detach()` for resource management
|
||||
3. **Styling**: ControlStyle supports inheritance. Use SetStyleSheet() for CSS-like styling
|
||||
4. **XML Loading**: Window::LoadXml() loads UI from XML files
|
||||
|
||||
### File Organization
|
||||
|
||||
- `include/EzUI/` - Public headers
|
||||
- `sources/` - Implementation files
|
||||
- `lib/` - Prebuilt static libraries (EzUI_Debug/Release_{Win32,x64}.lib)
|
||||
76
CMakeLists.txt
Normal file
76
CMakeLists.txt
Normal file
@@ -0,0 +1,76 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(EzUI)
|
||||
|
||||
# Set C++ standard
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Set available configurations
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
|
||||
|
||||
# Output directory for libraries - directly to lib/
|
||||
# Use per-configuration output directories for Visual Studio generators
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/lib)
|
||||
|
||||
# Include directories - sources use #include "Control.h" style
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/EzUI)
|
||||
|
||||
# Source files
|
||||
file(GLOB SOURCES
|
||||
${CMAKE_SOURCE_DIR}/sources/*.cpp
|
||||
)
|
||||
|
||||
# Create static library
|
||||
add_library(EzUI STATIC ${SOURCES})
|
||||
|
||||
# Preprocessor definition for static library
|
||||
target_compile_definitions(EzUI PRIVATE EZUI_STATIC)
|
||||
|
||||
# Additional system libraries required
|
||||
target_link_libraries(EzUI PRIVATE
|
||||
gdiplus.lib
|
||||
dwrite.lib
|
||||
d2d1.lib
|
||||
Windowscodecs.lib
|
||||
shlwapi.lib
|
||||
imm32.lib
|
||||
)
|
||||
|
||||
# Windows-specific settings
|
||||
add_definitions(-D_UNICODE)
|
||||
add_definitions(-DUNICODE)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
|
||||
# Force UTF-8 encoding for source files to avoid encoding issues
|
||||
# when editing in VSCode and building in VS2022
|
||||
add_compile_options(/utf-8)
|
||||
|
||||
# Set runtime library: MTD for Debug, MT for Release
|
||||
# This ensures static linking to the C/C++ runtime
|
||||
set_target_properties(EzUI PROPERTIES
|
||||
# Debug: MultiThreadedDebug (MTD)
|
||||
# Release: MultiThreaded (MT)
|
||||
DEBUG_POSTFIX ""
|
||||
)
|
||||
|
||||
# Set output name based on configuration and platform
|
||||
# Debug|Win32 -> EzUI_Debug_Win32.lib
|
||||
# Debug|x64 -> EzUI_Debug_x64.lib
|
||||
# Release|Win32 -> EzUI_Release_Win32.lib
|
||||
# Release|x64 -> EzUI_Release_x64.lib
|
||||
set_target_properties(EzUI PROPERTIES
|
||||
OUTPUT_NAME_DEBUG "EzUI_Debug_$(Platform)"
|
||||
OUTPUT_NAME_RELEASE "EzUI_Release_$(Platform)"
|
||||
)
|
||||
|
||||
# Explicitly set runtime library per configuration
|
||||
# Debug: MTD (MultiThreadedDebug) - static
|
||||
# Release: MT (MultiThreaded) - static
|
||||
target_compile_options(EzUI PRIVATE
|
||||
$<$<CONFIG:Debug>:/MTd>
|
||||
$<$<CONFIG:Release>:/MT>
|
||||
)
|
||||
81
build.bat
Normal file
81
build.bat
Normal file
@@ -0,0 +1,81 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal
|
||||
|
||||
echo ========================================
|
||||
echo EzUI Static Library Build Script
|
||||
echo VS2022 + CMake
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
REM Check if CMake is available
|
||||
where cmake >nul 2>&1
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: CMake not found. Please install CMake.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Get the directory of this script
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
cd /d "%SCRIPT_DIR%"
|
||||
|
||||
REM Clean previous build
|
||||
echo [1/4] Cleaning previous build...
|
||||
if exist "build" rmdir /s /q build
|
||||
if exist "lib\*.lib" del /q "lib\*.lib"
|
||||
if exist "lib\*.pdb" del /q "lib\*.pdb"
|
||||
|
||||
REM Generate and build Win32
|
||||
echo.
|
||||
echo [2/4] Building Win32...
|
||||
cmake -G "Visual Studio 17 2022" -A Win32 -S . -B build\Win32
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: CMake generation failed for Win32
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
cmake --build build\Win32 --config Debug
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: Build failed for Win32 Debug
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
cmake --build build\Win32 --config Release
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: Build failed for Win32 Release
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Generate and build x64
|
||||
echo.
|
||||
echo [3/4] Building x64...
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -S . -B build\x64
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: CMake generation failed for x64
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
cmake --build build\x64 --config Debug
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: Build failed for x64 Debug
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
cmake --build build\x64 --config Release
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo Error: Build failed for x64 Release
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Show results
|
||||
echo.
|
||||
echo [4/4] Build completed!
|
||||
echo.
|
||||
echo Generated libraries:
|
||||
dir /b lib\*.lib
|
||||
echo.
|
||||
echo ========================================
|
||||
echo Build Successful!
|
||||
echo ========================================
|
||||
|
||||
endlocal
|
||||
24
clean.bat
Normal file
24
clean.bat
Normal file
@@ -0,0 +1,24 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
|
||||
echo Cleaning EzUI build artifacts...
|
||||
|
||||
REM Remove build directory
|
||||
if exist "build" (
|
||||
rmdir /s /q build
|
||||
echo Removed: build\
|
||||
)
|
||||
|
||||
REM Remove lib files
|
||||
if exist "lib\*.lib" (
|
||||
del /q lib\*.lib
|
||||
echo Removed: lib\*.lib
|
||||
)
|
||||
|
||||
if exist "lib\*.pdb" (
|
||||
del /q lib\*.pdb
|
||||
echo Removed: lib\*.pdb
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Clean completed!
|
||||
Reference in New Issue
Block a user