Files
EzUI/CLAUDE.md
2026-02-20 16:18:16 +08:00

3.7 KiB

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)

# 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

# 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) - Top-level window, inherits from Object, manages HWND, handles message loop
  • Control (include/EzUI/Control.h) - Base class for all UI elements, contains m_controls (child collection), Style/HoverStyle/ActiveStyle/DisabledStyle
  • Application (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:

  • 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)