DioxusLabs / DioxusLabs/taffy

Position::Fixed - window-relative positioning

Open
#718 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
3.6k
Forks
222
Avg merge
10h 41m
Merged PRs (30d)
40

Description

## What problem does this solve or what need does it fill?

UI elements such as dialog boxes and popup menus need to be positioned in window coordinates. One way to do this is to create them as parentless elements, however there are downsides to this approach: it means, for example, that messages that are bubbled up the ancestor chain no longer reach their intended destinations.

Consider for example a menu button widget with a dropdown menu. We don't want the dropdown to be cut off if it's too tall, so we need to clip its size to the window size, and possibly "flip" it to the other side of the button if there is insufficient space. However, we also want the dropdown to behave like a child:

* The dropdown is despawned when the button is.
* Messages emitted by children of the dropdown can be received by the parent.

In CSS, this can be done in a variety of ways, one of which is `position: fixed`, which is an alternative to `position: absolute` or `position: relative`. It indicates that the element should be positioned relative to the window rect rather than to its parent element rect, and in all other respects behaviors like `position: absolute`.

## What solution would you like?

A `Position::Fixed` would behave similarly to the CSS `position: fixed`, in that it would always compute the parent rectangle using the window bounds - in other words, it would treat the element like it had no parent. In all other respects it would behave like `Absolute` positioning.

## What alternative(s) have you considered?

There are workarounds, including:

* Implement this function in Bevy by lying to Taffy about the parent rectangle.
* Use parentless elements with some other means of tracking ownership (doesn't solve the messaging issue).

However, none of these solutions are as clean.

## Additional context

Bevy issue for this: https://github.com/bevyengine/bevy/issues/9564

Contributor guide

Open the contributing guide

Research direction

The issue names no source files or tests. Start by locating the existing Absolute positioning implementation and its parent-rectangle calculation, then compare the requested window-bounds behavior with the linked Bevy issue; done means Fixed preserves Absolute behavior while using window bounds and retaining child ownership and message bubbling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.