鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

gpui-context

提供 GPUI 框架内的多层级上下文管理能力,支持全局应用状态、窗口生命周期、组件级实体更新与异步任务调度,实现 UI 渲染、状态同步、事件响应及跨上下文协作。

效率工具
访问 GitHub
文档Skills.MD
name
gpui-context
description
Context management in GPUI including App, Window, and AsyncApp. Use when working with contexts, entity updates, or window operations. Different context types provide different capabilities for UI rendering, entity management, and async operations.

Overview

GPUI uses different context types for different scenarios:

Context Types:

  • App: Global app state, entity creation
  • Window: Window-specific operations, painting, layout
  • Context<T>: Entity-specific context for component T
  • AsyncApp: Async context for foreground tasks
  • AsyncWindowContext: Async context with window access

Quick Start

Context - Component Context

▼
rust
复制代码
impl MyComponent { fn update_state(&mut self, cx: &mut Context<Self>) { self.value = 42; cx.notify(); // Trigger re-render // Spawn async task cx.spawn(async move |cx| { // Async work }).detach(); // Get current entity let entity = cx.entity(); } }

App - Global Context

▼
rust
复制代码
fn main() { let app = Application::new(); app.run(|cx: &mut App| { // Create entities let entity = cx.new(|cx| MyState::default()); // Open windows cx.open_window(WindowOptions::default(), |window, cx| { cx.new(|cx| Root::new(view, window, cx)) }); }); }

Window - Window Context

▼
rust
复制代码
impl Render for MyView { fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { // Window operations let is_focused = window.is_window_focused(); let bounds = window.bounds(); div().child("Content") } }

AsyncApp - Async Context

▼
rust
复制代码
cx.spawn(async move |cx: &mut AsyncApp| { let data = fetch_data().await; entity.update(cx, |state, inner_cx| { state.data = data; inner_cx.notify(); }).ok(); }).detach();

Common Operations

Entity Operations

▼
rust
复制代码
// Create entity let entity = cx.new(|cx| MyState::default()); // Update entity entity.update(cx, |state, cx| { state.value = 42; cx.notify(); }); // Read entity let value = entity.read(cx).value;

Notifications and Events

▼
rust
复制代码
// Trigger re-render cx.notify(); // Emit event cx.emit(MyEvent::Updated); // Observe entity cx.observe(&entity, |this, observed, cx| { // React to changes }).detach(); // Subscribe to events cx.subscribe(&entity, |this, source, event, cx| { // Handle event }).detach();

Window Operations

▼
rust
复制代码
// Window state let focused = window.is_window_focused(); let bounds = window.bounds(); let scale = window.scale_factor(); // Close window window.remove_window();

Async Operations

▼
rust
复制代码
// Spawn foreground task cx.spawn(async move |cx| { // Async work with entity access }).detach(); // Spawn background task cx.background_spawn(async move { // Heavy computation }).detach();

Context Hierarchy

▼
text
复制代码
App (Global) └─ Window (Per-window) └─ Context<T> (Per-component) └─ AsyncApp (In async tasks) └─ AsyncWindowContext (Async + Window)

Reference Documentation

  • API Reference: See api-reference.md
    • Complete context API, methods, conversions
    • Entity operations, window operations
    • Async contexts, best practices
效率工具

快捷安装

复制到终端去安装 Skill

npxskillsaddlongbridge/gpui-component--skill"gpui-context"
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
webapp-testing
提供本地 Web 应用的端到端测试能力,支持页面导航、元素交互、表单填写、动态等待、断言验证、截图捕获、浏览器日志收集及网络请求拦截,适用于前端功能验证与 UI 行为调试。
definition-of-done-generator
自动生成项目完成标准的规范定义与配置文件,提供符合企业级工作流要求的最佳实践指导,输出可直接投入生产环境的代码和验证结果,适用于需要标准化流程审批、合规审查及跨系统集成的复杂项目管理场景。
implement
实现 Linus Dashboard 的功能开发与集成,基于 TypeScript 和 Python 构建前后端组件,遵循严格的代码规范与架构模式,完成视图、卡片、服务及传感器等模块的创建与验证,确保高质量交付并兼容 Home Assistant 生态。
cloud-scheduler-job-creator
自动处理 Google Cloud Platform 中的云调度任务创建,提供符合最佳实践的配置方案与生产级代码生成,支持计算、存储、大数据及机器学习服务的集成部署。
planning-with-files
通过创建任务计划、笔记与交付文件三个持久化文档,实现对复杂任务的结构化管理。在多阶段工作中保持目标清晰,动态更新进度并沉淀研究过程,适用于需长期跟踪的规划、研究及创作场景。