Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 4, 2025

This PR simplifies the RenderQueue sorting implementation by using a straightforward three-tier priority system without positioning-specific logic.

Problem

The original RenderQueue implementation needed a clear and predictable sorting mechanism for rendering order in the scene.

Solution

Simple priority-based sorting:

bool RenderQueue::operator<(const RenderQueue &other) const
{
  // Priority is determined by:
  //   1. translateZ: Physical depth in 3D space
  //   2. zIndex: Logical stacking order  
  //   3. base: Base queue number
  //
  if (!math_utils::ApproximatelyEqual(translateZ, other.translateZ))
    return translateZ < other.translateZ;
  if (zIndex != other.zIndex)
    return zIndex < other.zIndex;
  return base < other.base;
}

Key Features

  • translateZ precedence: Physical 3D depth takes highest priority
  • zIndex ordering: CSS z-index values determine logical stacking order
  • base fallback: Base queue number provides final ordering for identical elements
  • Decimal support: zIndex changed from int to float to support decimal values
  • Negative values: Both zIndex and translateZ support negative values

Rendering Order

Elements are sorted in ascending order, meaning:

  • Lower translateZ values render first (further back)
  • Lower zIndex values render first (behind)
  • Lower base values render first (earlier in queue)

The implementation maintains CSS-compliant z-index behavior while providing a clean, predictable sorting mechanism for the rendering pipeline.

Fixes #296.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…sive tests

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance RenderQueue sorting: add isPositioned flag for correct rendering order when zIndex=0 Enhance RenderQueue sorting: add isPositioned flag for correct rendering order when zIndex=0 Sep 4, 2025
Copilot AI requested a review from yorkie September 4, 2025 08:10
Copy link
Collaborator

@yorkie yorkie left a comment

Choose a reason for hiding this comment

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

@copilot Please redesign the content of this PR (especially regarding isPositioned). It needs to ensure that positioned elements (including their children and content) always overlay non-positioned elements when no z-index is set.

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@copilot Please redesign the content of this PR (especially regarding isPositioned). It needs to ensure that positioned elements (including their children and content) always overlay non-positioned ...

I've redesigned the isPositioned functionality to ensure positioned elements and all their content properly overlay non-positioned elements. The key changes:

Text Inheritance: Text nodes now inherit isPositioned from their parent element, not just zIndex and translateZ.

Element Ancestry Check: Elements now check the entire ancestor chain for positioning context - if any ancestor is positioned, the element inherits that positioned context.

CSS Compliance: This ensures that when an element has CSS positioning (position: absolute|relative|fixed|sticky), ALL of its descendants (children, text content, nested elements) will render above non-positioned elements, even when no explicit z-index is set.

The solution maintains the existing sorting priority (translateZ > zIndex > isPositioned > base) while properly propagating positioning context through the DOM tree as required by CSS stacking context rules.

Commit: 4aa5e6b

Copilot AI changed the title Enhance RenderQueue sorting: add isPositioned flag for correct rendering order when zIndex=0 Redesign RenderQueue positioning: inherit stacking context from ancestors for proper CSS compliance Sep 5, 2025
Copilot AI requested a review from yorkie September 5, 2025 02:29
// 2. zIndex: Logical stacking order
// 3. base: Base queue number
// 3. isPositioned: When zIndex=0, positioned elements render after non-positioned
// 4. base: Base queue number
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot Reorder the priority:

  1. translateZ still first
  2. checking if positioned then use the z-index, otherwise use the magic number 0.1 as its z-index
  3. then use base queue number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reordered the priority as requested:

  1. translateZ first (unchanged)
  2. Effective zIndex: For positioned elements use actual zIndex, for non-positioned elements with zIndex=0 use magic number 0.1
  3. base queue number

The key change is that non-positioned elements with zIndex=0 now get an effective zIndex of 0.1, making them render above positioned elements with zIndex=0. Elements with non-zero zIndex use their actual zIndex regardless of positioning status.

Updated tests to reflect the new behavior where positioned elements with zIndex=0 render before (below) non-positioned elements.

Commit: 7aa8ac7

…0.1 for non-positioned elements

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title Redesign RenderQueue positioning: inherit stacking context from ancestors for proper CSS compliance Implement effective zIndex approach for RenderQueue positioning with magic number fallback Sep 5, 2025
Copilot AI requested a review from yorkie September 5, 2025 03:17
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot Please update the test cases in this file based on the current implementation, such as removing the isPositioned because this field has been removed.

As mentioned above, the isPositioned has been removed from the RenderQueue, this test file should be renamed to render_queue_tests.cpp and update cases for the current RenderQueue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the test file as requested:

  1. Renamed render_queue_positioning_tests.cpp to render_queue_tests.cpp
  2. Removed all references to isPositioned field which no longer exists in the current RenderQueue implementation
  3. Updated test cases to reflect the actual current behavior: translateZ > zIndex > base priority

The new tests focus on validating the core functionality without positioning-specific logic, testing decimal zIndex values, negative values, priority ordering, and edge cases that match the current implementation.

Commit: c543f5e

…nd remove isPositioned references

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title Implement effective zIndex approach for RenderQueue positioning with magic number fallback Simplify RenderQueue sorting to use basic priority: translateZ > zIndex > base Sep 5, 2025
Copilot AI requested a review from yorkie September 5, 2025 05:57
@yorkie yorkie marked this pull request as ready for review September 5, 2025 06:36
@yorkie yorkie merged commit 070211e into main Sep 5, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-296 branch September 5, 2025 06:38
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.

Enhance RenderQueue sorting: add isPositioned flag for correct rendering order when zIndex=0

2 participants