Skip to content

Add GridRect GUI node - #80

Merged
Xrayez merged 12 commits into
gd3from
grid-rect
May 24, 2021
Merged

Xrayez merged 12 commits into
gd3from
grid-rect

Conversation

@Xrayez

@Xrayez Xrayez commented May 18, 2021 •

Copy link
Copy Markdown
Contributor

Resolves godotengine/godot-proposals#2662.

image

Features:

  • Infinite grid;
  • Offset and scale the grid's origin (can be centered, and main axes can be optionally displayed);
  • Flip X/Y axes by using negative origin scale.
  • Customize individual lines by overriding _draw_line() virtual method (skipping every n-th line, different colors) (thanks to @LikeLakers2 for the idea presented in Add GridRect node for displaying a two-dimensional grid (for editors/charts) godotengine/godot-proposals#2662 (comment));
  • Convert between grid and view coordinates (with or without snapping);
  • Configurable cell's origin, so snapping can work either in top-left or center of the cell (useful for aiding the debugging process of other classes such as TileMap).
  • Customize colors, including background (can be transparent, which allows to layer many GridRect nodes on top of each other).
  • Shows grid's coordinates and metadata via tooltip by default.

image

Note that this only provides essential features needed to draw grids. Things like scroll, drag, zoom are possible to implement via script as of now. Depending on whether I'll need those features myself, it may be reasonable to add GridEdit node which can inherit this class.

Example project

grid.zip

Editor builds of this PR (have to be logged in GitHub):

Xrayez added 8 commits May 18, 2021 16:24
This introduces `LINE_AXIS` constant.
Also added `origin_axes_line_width`.
Previously it was just `offset` property which acted like a "view" offset. Now, it's named as `origin_offset`, and shifting the origin has an effect of scrolling in terms of view.
Cell size is not determined from number of subdivisions here.
Users are free to interpret cell drawing as "minor" if they use divisions, but when there are no divisions, cells could be treated as "major" in the same manner, so just get rid of "minor/major" terms, because they can be ambiguous (the same applies to "primary/secondary" lines).

This change makes existing terminology of "cells/divisions" consistent throughout class.
@Xrayez Xrayez added feature 💡 New feature proposal topic:gui labels May 18, 2021
@Xrayez Xrayez added this to the gd3 milestone May 18, 2021
Xrayez added 3 commits May 19, 2021 19:42
This is not the "proper" way to test this, but scene-based approach is easier to maintain and update when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 💡 New feature proposal topic:gui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GridRect node for displaying a two-dimensional grid (for editors/charts)

1 participant