From 767169d6474c3237967a759d8682bd6f7392fca8 Mon Sep 17 00:00:00 2001 From: anry Date: Fri, 20 Feb 2026 16:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E7=BD=AEclaude?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 7 +++ CLAUDE.md | 115 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 72 ++++++++++++++++++++++ build.bat | 81 +++++++++++++++++++++++++ clean.bat | 24 ++++++++ 5 files changed, 299 insertions(+) create mode 100644 .claude/settings.local.json create mode 100644 CLAUDE.md create mode 100644 CMakeLists.txt create mode 100644 build.bat create mode 100644 clean.bat diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..010dac1 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "allow": [ + "Bash(cmake:*)" + ] + } +} diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..04eb6a4 --- /dev/null +++ b/CLAUDE.md @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..61ef02a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,72 @@ +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) + +# 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 + $<$:/MTd> + $<$:/MT> +) diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..6235734 --- /dev/null +++ b/build.bat @@ -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 diff --git a/clean.bat b/clean.bat new file mode 100644 index 0000000..f9adb9e --- /dev/null +++ b/clean.bat @@ -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!