Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create LayoutComponent classes #2302

Open
st-pasha opened this issue Jan 28, 2023 · 2 comments · Fixed by #2350
Open

Create LayoutComponent classes #2302

st-pasha opened this issue Jan 28, 2023 · 2 comments · Fixed by #2350
Assignees

Comments

@st-pasha
Copy link
Contributor

Proposal

LayoutComponent will be the base class for a family of utility classes which handle the layout of their children. This would be quite similar to Flutter layout widgets such as Align, Column, Center, Container, Padding, SizedBox, etc.

The purpose of these new components is to assist with constructing UIs within a game: dialogue boxes, HUD, informational screens, in-game UIs such as dialogue or trade windows, etc.

PR #1971 already attempts to add two such layout classes: Row and Column -- this proposal is to have more of them, all under a single umbrella of LayoutComponent.

For example, suppose you're making a game and you want to display current score in the top right corner. Then, you should be able to declare it like this:

camera.viewport.add(
  Padding(
    padding: EdgeInsets.all(20),
    children: [
      Align(
        anchor: Anchor.topRight,
        child: ScoreComponent(),
      ),
    ],
  ),
);

After this, the game would take care to properly position the ScoreComponent and move it whenever the game resizes.

Implementation

LayoutComponent would rely on the onParentResize lifecycle method (#1421).

The tree structure can be either normal (the target is added as a child of the LayoutComponent), or flat (the target is added to the parent directly, and layout component is a sibling). I'm not sure which option is better here.

@st-pasha st-pasha self-assigned this Jan 28, 2023
@spydon
Copy link
Member

spydon commented Jan 28, 2023

Sounds good! Should we close #1971 then?

@st-pasha
Copy link
Contributor Author

Should we close #1971 then?

We'll add the new layout classes, and then #1971 could use this new interface to implement the Row and Column.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants