Skip to content

Conversation

@mateuszJS
Copy link
Owner

@mateuszJS mateuszJS commented Oct 1, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced selection/hover borders with smoother, consistent rendering.
  • Bug Fixes
    • More reliable text wrapping and line breaks, including explicit handling of long lines and Enter key presses.
    • Improved picking/interaction accuracy around asset borders.
  • Refactor
    • Consolidated asset handling into a unified model for images, shapes, and text.
    • Internal cleanup to standardize transform and rendering logic for borders and vertices.

Copilot AI review requested due to automatic review settings October 1, 2025 16:30
@coderabbitai
Copy link

coderabbitai bot commented Oct 1, 2025

Walkthrough

Refactors asset handling by moving Asset and AssetSerialized unions to types.zig with bounds helpers, updates index.zig to use transform_ui and new asset APIs, adds transform_ui.getBorderDrawVertex, and restructures texts.zig line-wrapping to unify ENTER and width-triggered breaks with explicit markers and vertices.

Changes

Cohort / File(s) Summary
Asset type centralization
src/logic/types.zig
Introduces public unions Asset and AssetSerialized with img/shape/text variants; adds getBounds and getBoundsPtr helpers; imports images/shapes/texts modules.
Transform UI API usage update
src/logic/index.zig
Renames TransformUI import to transform_ui; replaces local Asset unions with imports from types.zig; switches bound extraction to asset.getBoundsPtr(); updates draw/pick calls to transform_ui.*; uses transform_ui.getBorderDrawVertex for hovered/selected borders.
Transform UI border helper
src/logic/transform_ui.zig
Adds pub fn getBorderDrawVertex(asset, color) -> [8]triangles.DrawInstance that builds border draw instances from asset bounds via lines.getDrawVertexData and shared.render_scale.
Text wrapping/newline handling
src/logic/texts/texts.zig
Merges ENTER and width-exceed conditions; resets line position and kerning on wrap; explicitly appends soft-break and ENTER markers with corresponding vertices; removes prior post-wrap reset block.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as index.zig
  participant A as types.Asset
  participant TU as transform_ui
  participant L as lines
  participant G as triangles buffer

  UI->>A: getBoundsPtr()
  Note right of A: Returns *[4]PointUV
  UI->>TU: getBorderDrawVertex(asset, color)
  TU->>A: getBoundsPtr()
  TU->>L: getDrawVertexData(points, thickness, color, render_scale)
  L-->>TU: Draw instances
  TU-->>UI: [8] DrawInstance
  UI->>G: Append border draw instances
Loading
sequenceDiagram
  autonumber
  participant T as texts.zig
  participant V as Vertex list

  T->>T: For each code point
  alt ENTER or exceeded max width
    T->>V: Mark previous char last_in_line
    T->>V: Append SOFT_BREAK_MARKER (when width exceeded)
    T->>V: Append line-break vertex
    T->>V: Append ENTER marker
    T->>V: Append line-break vertex
    T->>T: Reset next_pos, space_before=0
  else
    T->>V: Append regular glyph vertex
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~55 minutes

Possibly related PRs

Suggested labels

released on @next

Poem

A nib of code, a hop of state,
New bounds I trace, then iterate.
Soft breaks fall like leaves at night,
Borders drawn in tidy light.
I twitch my ears—refactors sing—
Assets unioned: thump-thump, spring! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “fix: refactor transform border” correctly references the refactoring of the border‐rendering code in transform_ui but does not capture the broader asset and import renaming, type unifications, and text wrapping updates included in this pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-transform-border

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors transform border rendering by centralizing Asset-related shapes and border drawing logic, and adjusts text wrapping behavior.

  • Move Asset and AssetSerialized unions to types.zig and add helpers to access bounds.
  • Extract border line vertex generation into transform_ui.getBorderDrawVertex and update call sites to use transform_ui alias.
  • Improve text line-breaking: handle ENTER vs soft-wrap distinctly and set last_in_line earlier.

Reviewed Changes

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

File Description
src/logic/types.zig Introduces Asset/AssetSerialized unions and helper methods getBounds/getBoundsPtr to unify access to per-asset bounds.
src/logic/transform_ui.zig Adds getBorderDrawVertex to produce border draw instances for any Asset; imports Asset and AssetId.
src/logic/texts/texts.zig Modifies line-breaking flow to break on ENTER or width, mark previous glyph as last_in_line, and only insert soft break markers for width overflow.
src/logic/index.zig Switches to transform_ui alias, uses new Asset helpers, refactors drawBorder to call transform_ui.getBorderDrawVertex, and updates pick rendering constants.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/logic/texts/texts.zig (2)

180-195: Consistent break markers on width wrap: OK; also set an explicit zero-width marker on ENTER for parity.

Width-wrap path emits a SOFT_BREAK then ENTER marker with null CharVertex. Do the same for explicit ENTER to keep model/render parity and selection math stable, without fetching glyphs.

             if (exceeded_max_width) {
                 try updated_content.append(SOFT_BREAK_MARKER);
                 try self.text_vertex.append(CharVertex{
                     .relative_bounds = self.getDrawRelativeBounds(0, 0, 0, 0, next_pos),
                     .origin = next_pos,
                     .char = null,
                 });
                 // add word joiner character before line break so that when user copies the text, they get the same line breaks
                 try updated_content.append(ENTER_CHAR_CODE);
                 try self.text_vertex.append(CharVertex{
                     .relative_bounds = self.getDrawRelativeBounds(0, 0, 0, 0, next_pos),
                     .origin = next_pos,
                     .char = null,
                 });
             }
+            if (cp == ENTER_CHAR_CODE) {
+                // mirror width-wrap behavior for explicit newlines
+                try updated_content.append(ENTER_CHAR_CODE);
+                try self.text_vertex.append(CharVertex{
+                    .relative_bounds = self.getDrawRelativeBounds(0, 0, 0, 0, next_pos),
+                    .origin = next_pos,
+                    .char = null,
+                });
+                continue; // skip glyph emission
+            }

208-216: Skip CharVertex glyph emission for ENTER; remove last_in_line flag coupling to codepoint.

After adopting the guards above, ensure glyph vertices are only emitted for drawable code points.

-            // Encode the Unicode codepoint as UTF-8 bytes
-            try updated_content.append(cp);
-            try self.text_vertex.append(CharVertex{
-                .relative_bounds = relative_bounds,
-                .char = cp,
-                .origin = next_pos,
-                .last_in_line = cp == ENTER_CHAR_CODE,
-            });
+            // Encode the Unicode codepoint as UTF-8 bytes
+            try updated_content.append(cp);
+            if (cp != ENTER_CHAR_CODE) {
+                try self.text_vertex.append(CharVertex{
+                    .relative_bounds = relative_bounds,
+                    .char = cp,
+                    .origin = next_pos,
+                });
+            }
🧹 Nitpick comments (1)
src/logic/transform_ui.zig (1)

11-12: Remove unused import or use it.

AssetId is imported but not referenced.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a39a91 and 7e24b65.

📒 Files selected for processing (4)
  • src/logic/index.zig (7 hunks)
  • src/logic/texts/texts.zig (1 hunks)
  • src/logic/transform_ui.zig (2 hunks)
  • src/logic/types.zig (1 hunks)
🔇 Additional comments (11)
src/logic/types.zig (3)

2-4: Centralizing type imports looks good.

Importing images/shapes/texts here simplifies cohesion of Asset types. No issues.


6-26: Asset union + bounds helpers LGTM.

Switch-based accessors are clear; pointer version uses self.* correctly. Good ergonomics.


28-32: AssetSerialized union LGTM.

Keeps serialization variants co-located with Asset.

src/logic/transform_ui.zig (1)

244-264: Remove incorrect type-mismatch suggestions
The call to lines.getDrawVertexData in src/logic/lines.zig:33 is defined as

pub fn getDrawVertexData(
    buffer: *[2]triangles.DrawInstance,
    start: anytype,
    end: anytype,
    width: f32,
    color: [4]u8,
    rounded: f32,
) void

so passing color: [4]u8 and your point/next_point values (anytype) already matches the signature. No toPoint() conversion or switch to @Vector(4,u8) is required.

Likely an incorrect or invalid review comment.

src/logic/index.zig (7)

6-6: LGTM! Improved naming and modularity.

The rename from TransformUI to transform_ui follows Zig conventions, and moving Asset/AssetSerialized to types.zig improves code organization.

Also applies to: 22-23


546-546: LGTM! Consistent with renamed import.

The function call correctly uses the new transform_ui module name.


680-684: LGTM! Consistent with renamed import.

The transformPoints call correctly uses the new transform_ui module name.


664-664: LGTM! Cleaner abstraction.

Using asset.getBoundsPtr() eliminates switch-based bound extraction, improving maintainability and reducing code duplication.


743-748: LGTM! Simplified border rendering.

Delegating border rendering to transform_ui.getBorderDrawVertex eliminates manual border point calculations and improves code clarity. The color coding (red for hovered, green for selected) is intuitive.

Also applies to: 753-758


1340-1342: LGTM! Consistent with renamed import.

The renderPick function correctly uses transform_ui.PICK_TRIANGLE_INSTANCES and transform_ui.getPickVertexData with the new module name.


761-762: Asset methods verified
Both pub fn getBounds(self: Asset) [4]PointUV and pub fn getBoundsPtr(self: *Asset) *[4]PointUV are implemented in src/logic/types.zig, so the by-value call on line 762 is intentional.

@mateuszJS mateuszJS merged commit 9fafbd0 into next Oct 1, 2025
6 checks passed
@github-actions
Copy link

github-actions bot commented Oct 6, 2025

🎉 This PR is included in version 0.1.0-next.22 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants