Skip to content

feat(UI): add AnvilLib-Ui module for declarative UI library#35

Draft
Gu-ZT wants to merge 75 commits into
Anvil-Dev:dev/26.1from
Gu-ZT:feat/ui/26.1
Draft

feat(UI): add AnvilLib-Ui module for declarative UI library#35
Gu-ZT wants to merge 75 commits into
Anvil-Dev:dev/26.1from
Gu-ZT:feat/ui/26.1

Conversation

@Gu-ZT

@Gu-ZT Gu-ZT commented May 18, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings May 18, 2026 12:08
@Gu-ZT Gu-ZT marked this pull request as draft May 18, 2026 12:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new module.ui subproject for an AnvilLib UI module and wires it into the build, test, main aggregator, and CI/release workflows.

Changes:

  • Registers module.ui in Gradle settings and adds basic module metadata/resources.
  • Adds the AnvilLibUi mod entrypoint and resource helper.
  • Includes the UI module in test/main dependencies and CI/release job matrices.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
settings.gradle Registers and names the new UI subproject.
module.ui/build.gradle Adds the module build file.
module.ui/gradle.properties Defines UI module metadata.
module.ui/src/main/java/dev/anvilcraft/lib/v2/ui/AnvilLibUi.java Adds the UI module entrypoint.
module.ui/src/main/java/dev/anvilcraft/lib/v2/ui/package-info.java Marks the UI package as null-marked.
module.ui/src/main/resources/META-INF/neoforge.mods.toml Adds NeoForge mod metadata.
module.ui/src/main/resources/anvillib_ui.mixins.json Adds an empty mixin config for the module.
module.test/build.gradle Adds UI as a test module dependency.
module.main/build.gradle Bundles UI into the main AnvilLib artifact.
.github/workflows/ci.yml Adds UI to CI build/deploy flow.
.github/workflows/release.yml Adds UI to release build/deploy flow.
.github/workflows/pull_request.yml Adds UI to PR checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread module.ui/src/main/resources/META-INF/neoforge.mods.toml
Comment thread module.ui/src/main/resources/META-INF/neoforge.mods.toml
Comment thread module.ui/src/main/resources/META-INF/neoforge.mods.toml

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 41 changed files in this pull request and generated 33 comments.

Comments suppressed due to low confidence (1)

module.ui/src/main/java/dev/anvilcraft/lib/v2/ui/UIScope.java:51

  • Any state read used to compute the button label is evaluated before the button is emitted, so it cannot be tracked against the button's slot. Dynamic labels based on MutableState will not reliably trigger recomposition.
        Composition.current().emit(c);
        return c;
    }

Comment on lines +43 to +44
for (Composition.Slot slot : readers) {
slot.markDirty();
extractor.centeredText(font, comp, (int) (x + width / 2), (int) (y + (height - font.lineHeight) / 2), TEXT_COLOR);
}

void click() {
Comment on lines +29 to +33
Composition comp = Composition.currentOrNull();
if (comp != null && comp.currentSlot != null) {
comp.currentSlot.addReadState(this);
readers.add(comp.currentSlot);
}
Comment on lines +36 to +38
static ModifierElement width(float w) {
return new SizeElement(0, Float.MAX_VALUE, w, w);
}
Comment on lines +40 to +42
static ModifierElement height(float h) {
return new SizeElement(h, 0, h, Float.MAX_VALUE);
}
Comment thread .github/workflows/release.yml Outdated
Comment on lines +359 to +370
ui:
uses: ./.github/workflows/build_and_test.yml
with:
module: ui
module_id: anvillib-ui
mod_id: anvillib_ui
ci_build: false
pr_build: false
secrets:
maven_url: ${{ secrets.MAVEN_URL }}
maven_user: ${{ secrets.MAVEN_USER }}
maven_pass: ${{ secrets.MAVEN_PASS }}
Comment on lines +58 to +60
public MeasuredSize measure(Constraints constraints) {
if (children.isEmpty()) return MeasuredSize.ZERO;

Comment on lines +80 to +84
constraints.constrainWidth(maxWidth),
constraints.constrainHeight(totalHeight)
);
}

Comment on lines +89 to +92
this.width = width;
this.height = height;

List<Float> heights = new ArrayList<>(childSizes.size());
Comment on lines +41 to +44
}

// ── component builders ──

Gu-ZT added 22 commits May 19, 2026 22:26
…tests and update Slider/TextField components to use Consumer for change handling
Gu-ZT added 3 commits May 19, 2026 22:43
…d update UI components to use new method signatures
# Conflicts:
#	.github/workflows/ci.yml
#	.github/workflows/pull_request.yml
#	.github/workflows/release.yml
#	module.rendering/src/main/java/dev/anvilcraft/lib/v2/rendering/sdf/Sdf2d.java
#	module.rendering/src/main/java/dev/anvilcraft/lib/v2/rendering/sdf/SdfParameters.java
#	module.rendering/src/main/java/dev/anvilcraft/lib/v2/rendering/sdf/SdfRenderType.java
#	module.rendering/src/main/resources/assets/anvillib_rendering/shaders/core/sdf_graphics.fsh
#	module.test/src/main/java/dev/anvilcraft/lib/v2/test/client/AnvilLibTestClient.java
#	module.test/src/main/java/dev/anvilcraft/lib/v2/test/client/gui/SdfGraphicsLayer.java
#	settings.gradle
@Gugle2308

Copy link
Copy Markdown

❌ Non-retryable error (HTTP 402): HTTP 402: Insufficient Balance

@Gugle2308

Copy link
Copy Markdown

⚠️ Error code: 402 - {'error': {'message': 'Insufficient Balance', 'type': 'unknown_error', 'param': None, 'code': 'invalid_request_error'}}

@Gugle2308

Copy link
Copy Markdown

🌿 Roseau API Breaking Change Report

Module Status Breaking Changes
codec ✅ Compatible 0
collision ✅ Compatible 0
config ✅ Compatible 0
integration ✅ Compatible 0
moveable-entity-block ✅ Compatible 0
network ✅ Compatible 0
rendering ✅ Compatible 0
space-select ✅ Compatible 0
font ✅ Compatible 0
util ✅ Compatible 0
explosion ✅ Compatible 0
rpc ✅ Compatible 0
multiblock ✅ Compatible 0
recipe ✅ Compatible 0
registrum ✅ Compatible 0
sync ✅ Compatible 0
wheel ✅ Compatible 0
main ✅ Compatible 0

Full CSVs: see the Artifacts section of this workflow run.

Gu-ZT added 7 commits July 3, 2026 23:56
- 将 Animatable 从基于 tick 的动画改为帧时间驱动的通用补间动画
- 添加插值器、缓动函数和动画配置选项(重复、延迟、yoyo等)
- 重写布局系统使用 LayoutHelper 统一处理子组件测量、布局和渲染
- 为所有容器组件(Box、Column、Flex、Grid、LazyColumn)实现新的布局机制
- 修复排列算法中的负间隙计算问题
- 优化虚化列表的缓存和渲染性能
- 为下拉组件添加事件优先级和运行状态复制功能
- 新增填充修饰符元素和颜色插值器
- 在SdfGraphics单例上调用reset方法清除上次绘制的stroke/onion等残留状态
- 将非居中模式的box坐标转换为以矩形中心为原点的居中模式坐标
- 使用bounds中心点坐标替代原始左上角坐标进行box绘制
- 显式设置center(true)确保正确的居中渲染行为
- 修复按钮组件在有自定义修饰符时不绘制默认背景色的问题
- 在下拉组件箭头渲染前添加重置操作避免状态污染
- 确保UI组件渲染状态的一致性
- 在triangle方法中添加了坐标更新逻辑
- 确保绘制后图形位置参数正确同步
- 修复了由于坐标未及时更新导致的渲染偏差
- 使用LayoutHelper.renderChildrenSorted方法替代手动循环渲染子组件
- 在Composition类中按renderingPriority对根作用域子组件进行排序渲染
- 在DeclarativeScreen类中按eventPriority对鼠标事件处理组件进行倒序排序
- 添加新的renderChildrenSorted方法支持按渲染优先级排序渲染
- 移除多个组件类中的重复循环渲染代码,统一使用工具方法
- 修复滚动条拖拽区域判断逻辑,确保在整个滚动条区域内都能响应点击
- 优化滚动条拖拽锚点计算,在非滑块区域点击时自动定位到滑块中心
- 改进滚动位置计算公式,使滚动行为更加平滑准确
- 移除过时的滚动条高度和位置计算代码,简化交互逻辑
- 添加了 Minecraft 客户端实例导入
- 将 closeAllDropdowns 方法重命名为 closeUnrelatedDropdowns
- 实现了仅关闭鼠标点击区域外的下拉组件功能
- 添加了鼠标坐标获取和碰撞检测逻辑
- 修改了鼠标点击事件处理流程,先分发事件再关闭无关下拉组件
- 更新了递归方法以支持坐标参数传递和精确的下拉状态控制
@Gugle2308

Copy link
Copy Markdown

现在我已收集足够的数据。以下是完整的审查报告。


代码审查摘要

PR #35 | feat(UI): add AnvilLib-Ui module for declarative UI library
作者: Gu-ZT | 分支: feat/ui/26.1dev/26.1
范围: 57 个新文件,5,255 新增行,65 删除行

结论: COMMENT — 质量优良的新模块引入,架构设计清晰。发现 1 个需注意的配置问题 + 4 个需修复的格式问题。


🔴 关键

(无)


⚠️ 警告

  1. compatibilityLevel: "JAVA_8" 应为 "JAVA_21"anvillib_ui.mixins.json 第 5 行:当前值为 "JAVA_8",但项目目标为 MC 26.1 运行在 Java 21 上。Mixin 的 compatibilityLevel 设置为过低版本不会导致注入立即失败(当前 mixin 列表为空),但后续添加 mixin 时会导致所有注入静默跳过而不报编译错误或运行时错误。建议立即修正为 "JAVA_21",避免未来排查困难。

  2. 5 个文件缺少结尾换行符 — 缺失 POSIX 换行符,影响 diff 整洁和部分工具兼容性:

    • module.ui/build.gradle
    • module.ui/gradle.properties
    • module.ui/src/main/java/dev/anvilcraft/lib/v2/ui/AnvilLibUi.java
    • module.ui/src/main/java/dev/anvilcraft/lib/v2/ui/package-info.java
    • module.ui/src/main/resources/anvillib_ui.mixins.json
  3. 无接口模块间依赖声明neoforge.mods.toml 仅声明了 neoforgeminecraft 依赖,但 module.ui/build.gradle 声明了对 anvillib-rendering-neoforge-26.1 的实现依赖,因 UI 使用了渲染模块的 SDF 图形(background/border/dropdown 箭头)。当前通过 jarJar 统一打包不影响运行,但若未来将渲染模块作为独立 mod JAR 分发则会出现类加载顺序问题。建议在 neoforge.mods.toml 中添加 anvillib_rendering[[dependencies]] 声明。


💡 建议

  1. SDF 三角形渲染类型命名一致性问题SdfRenderType 新增 TRIANGLE(普通三角形),与已有等边三角形的 TRIANGLE_EQUILATERAL、等腰三角形的 TRIANGLE_ISOSCELES 对比,命名模式不够一致。建议考虑 TRIANGLE_GENERICTRIANGLE_FREE 以显式区分三类三角形的语义差异。(注:shader 端的 RT_TRIANGLE 命名与 RT_ETRIANGLE/RT_ITRIANGLE 一致,需要同步。仅 Java 枚举命名需修正。)

  2. TODO.md 包含在发布资源中module.ui/TODO.md 包含 52 项组件进度跟踪表,内容详细且对开发者有用,但不应随发布 JAR 一起分发。建议通过 .jar 排除或移入 docs/ 目录。

  3. Build 系统整洁性(极小)module.ui/build.gradle 仅 3 行。其他子模块的 build.gradle 通常包含 plugins 块和 sourceSets 声明。确认 module.ui 的 Gradle 继承链已正确从根项目或 module.main 继承这些配置。(如已继承则为安全,建议增加注释说明)


✅ 看起来不错

  • 架构设计Composition + slot-table 的 diff/remember 模型设计优雅,借鉴 ArkUI 思路适配 MC 的 26.1 渲染管线。状态追踪按 slot 精确 markDirty 而非全树 recompose,性能意识好。
  • 事件系统DeclarativeScreen 使用 eventPriorityrenderingPriority 双优先级系统,替代 instanceof 硬编码分发,扩展性好。
  • 裁剪安全ScrollableComponentLazyColumnComponent 均正确使用 enableScissor/disableScissor 做渲染裁剪。
  • API 版本一致性:使用 jspecify Nullable / NullMarkedIdentifierGuiGraphicsExtractorCharacterEvent/MouseButtonEvent/KeyEvent 等 26.1 新 API,迁移正确。
  • Math.clamp 使用TextInputComponent.java:79 正确使用了 Java 21 的 Math.clamp(pos, 0, value.length()) 而非 Mth.clamp
  • 测试覆盖DeclarativeTestScreen 覆盖了 10 类组件场景,含 Text 样式、Button+状态、Box 层叠、Grid 网格、Column/Row、Checkbox、Slider、TextInput、Dropdown、ForEach、Modifier 样式。
  • SDF 扩展sdTriangle 函数正确引用了 IQ 的 2D SDF 公式,GPU 和 CPU 两端实现一致。shader 中 intBitsToFloat 的正确使用确保了顶点坐标传参无误。

总体评价:高质量的模块初始提交。架构整洁,API 对齐 26.1 新标准,测试覆盖全面。建议在合并前修复 EOF 换行符和 compatibilityLevel 配置。

@Gugle2308

Copy link
Copy Markdown

🌿 Roseau API Breaking Change Report

Module Status Breaking Changes
codec ✅ Compatible 0
collision ✅ Compatible 0
config ✅ Compatible 0
integration ✅ Compatible 0
moveable-entity-block ✅ Compatible 0
network ✅ Compatible 0
rendering ✅ Compatible 0
space-select ✅ Compatible 0
font ✅ Compatible 0
util ✅ Compatible 0
explosion ✅ Compatible 0
rpc ✅ Compatible 0
multiblock ✅ Compatible 0
recipe ✅ Compatible 0
registrum ✅ Compatible 0
sync ✅ Compatible 0
wheel ✅ Compatible 0
main ✅ Compatible 0

Full CSVs: see the Artifacts section of this workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants