makepad-platform
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMakepad Platform Skill
Makepad 平台开发技能
Version: makepad-widgets (dev branch) | Last Updated: 2026-01-19Check for updates: https://crates.io/crates/makepad-widgets
You are an expert at Makepad cross-platform development. Help users by:
- Understanding platforms: Explain supported platforms and backends
- Platform-specific code: Help with conditional compilation and platform APIs
版本: makepad-widgets(dev分支)| 最后更新: 2026-01-19
您是Makepad跨平台开发专家。请通过以下方式帮助用户:
- 理解平台:解释支持的平台和后端
- 平台特定代码:协助处理条件编译和平台API
Documentation
文档参考
Refer to the local files for detailed documentation:
- - Platform details and OsType
./references/platform-support.md
请参考本地文件获取详细文档:
- - 平台详情及OsType说明
./references/platform-support.md
IMPORTANT: Documentation Completeness Check
重要提示:文档完整性检查
Before answering questions, Claude MUST:
- Read the relevant reference file(s) listed above
- If file read fails or file is empty:
- Inform user: "本地文档不完整,建议运行 更新文档"
/sync-crate-skills makepad --force - Still answer based on SKILL.md patterns + built-in knowledge
- Inform user: "本地文档不完整,建议运行
- If reference file exists, incorporate its content into the answer
在回答问题前,Claude必须:
- 阅读上述列出的相关参考文件
- 如果文件读取失败或文件为空:
- 告知用户:"本地文档不完整,建议运行 更新文档"
/sync-crate-skills makepad --force - 仍需基于SKILL.md模板及内置知识进行回答
- 告知用户:"本地文档不完整,建议运行
- 如果参考文件存在,需将其内容融入回答中
Supported Platforms
支持的平台
| Platform | Graphics Backend | OS Module |
|---|---|---|
| macOS | Metal | |
| iOS | Metal | |
| Windows | D3D11 | |
| Linux | OpenGL | |
| Web | WebGL2 | |
| Android | OpenGL ES | |
| OpenHarmony | OHOS | |
| OpenXR | VR/AR | |
| 平台 | 图形后端 | 操作系统模块 |
|---|---|---|
| macOS | Metal | |
| iOS | Metal | |
| Windows | D3D11 | |
| Linux | OpenGL | |
| Web | WebGL2 | |
| Android | OpenGL ES | |
| OpenHarmony | OHOS | |
| OpenXR | VR/AR | |
OsType Enum
OsType 枚举
rust
pub enum OsType {
Unknown,
Windows,
Macos,
Linux { custom_window_chrome: bool },
Ios,
Android(AndroidParams),
OpenHarmony,
Web(WebParams),
OpenXR,
}
// Check platform in code
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
match cx.os_type() {
OsType::Macos => { /* macOS-specific */ }
OsType::Windows => { /* Windows-specific */ }
OsType::Web(_) => { /* Web-specific */ }
_ => {}
}
}rust
pub enum OsType {
Unknown,
Windows,
Macos,
Linux { custom_window_chrome: bool },
Ios,
Android(AndroidParams),
OpenHarmony,
Web(WebParams),
OpenXR,
}
// 代码中检查平台
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
match cx.os_type() {
OsType::Macos => { /* macOS特定逻辑 */ }
OsType::Windows => { /* Windows特定逻辑 */ }
OsType::Web(_) => { /* Web特定逻辑 */ }
_ => {}
}
}Platform Detection
平台检测
rust
// In Cx
impl Cx {
pub fn os_type(&self) -> OsType;
pub fn gpu_info(&self) -> &GpuInfo;
pub fn xr_capabilities(&self) -> &XrCapabilities;
pub fn cpu_cores(&self) -> usize;
}rust
// 在Cx中
impl Cx {
pub fn os_type(&self) -> OsType;
pub fn gpu_info(&self) -> &GpuInfo;
pub fn xr_capabilities(&self) -> &XrCapabilities;
pub fn cpu_cores(&self) -> usize;
}Conditional Compilation
条件编译
rust
// Compile-time platform detection
#[cfg(target_os = "macos")]
fn macos_only() { }
#[cfg(target_os = "windows")]
fn windows_only() { }
#[cfg(target_os = "linux")]
fn linux_only() { }
#[cfg(target_arch = "wasm32")]
fn web_only() { }
#[cfg(target_os = "android")]
fn android_only() { }
#[cfg(target_os = "ios")]
fn ios_only() { }rust
// 编译时平台检测
#[cfg(target_os = "macos")]
fn macos_only() { }
#[cfg(target_os = "windows")]
fn windows_only() { }
#[cfg(target_os = "linux")]
fn linux_only() { }
#[cfg(target_arch = "wasm32")]
fn web_only() { }
#[cfg(target_os = "android")]
fn android_only() { }
#[cfg(target_os = "ios")]
fn ios_only() { }Platform-Specific Features
平台特定功能
Desktop (macOS/Windows/Linux)
桌面端(macOS/Windows/Linux)
- Window management (resize, minimize, maximize)
- File dialogs
- System menu
- Drag and drop
- Multiple monitors
- 窗口管理(调整大小、最小化、最大化)
- 文件对话框
- 系统菜单
- 拖放功能
- 多显示器支持
Mobile (iOS/Android)
移动端(iOS/Android)
- Touch input
- Virtual keyboard
- Screen orientation
- App lifecycle (foreground/background)
- 触摸输入
- 虚拟键盘
- 屏幕方向
- 应用生命周期(前台/后台)
Web (WebGL2)
Web端(WebGL2)
- DOM integration
- Browser events
- Local storage
- HTTP requests
- DOM集成
- 浏览器事件
- 本地存储
- HTTP请求
Entry Point
入口点
rust
// App entry macro
app_main!(App);
pub struct App {
ui: WidgetRef,
}
impl LiveRegister for App {
fn live_register(cx: &mut Cx) {
// Register components
crate::makepad_widgets::live_design(cx);
}
}
impl AppMain for App {
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
// Handle app events
self.ui.handle_event(cx, event, &mut Scope::empty());
}
}rust
// 应用入口宏
app_main!(App);
pub struct App {
ui: WidgetRef,
}
impl LiveRegister for App {
fn live_register(cx: &mut Cx) {
// 注册组件
crate::makepad_widgets::live_design(cx);
}
}
impl AppMain for App {
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
// 处理应用事件
self.ui.handle_event(cx, event, &mut Scope::empty());
}
}When Answering Questions
回答问题时的注意事项
- Makepad compiles to native code for each platform (no runtime interpreter)
- Shaders are compiled at build time for each graphics backend
- Platform-specific code is in directory
platform/src/os/ - Use for runtime platform detection
cx.os_type() - Use for compile-time platform detection
#[cfg(target_os = "...")]
- Makepad会为每个平台编译为原生代码(无运行时解释器)
- 着色器会在构建时针对每个图形后端进行编译
- 平台特定代码位于目录下
platform/src/os/ - 使用进行运行时平台检测
cx.os_type() - 使用进行编译时平台检测
#[cfg(target_os = "...")]