Skip to content

slavniyteo/rect-ex

Repository files navigation

Rect Extensions

Read about RextEx on habr (ru). Extended docs at Documentation folder (according to Unity Package Layout).

RectEx is a tool that simplify drawing EditorGUI (not Layout) elements with Unity3d.

RectEx consists of a bunch of Rect extensions, which provides an interface to work with rects easier.

GitHub release GitHub Release Date Github commits (since latest release) GitHub last commit

Stop doing

rect.height = 18;
GUI.LabelField(rect, "First line");
rect.y += rect.height;
GUI.LabelField(rect, "Second line");
rect.y += rect.height;
rect.width = (rect.width - 5) / 2;
GUI.LabelField(rect, "Third line: left part");
rect.x += rect.width + 5;
GUI.LabelField(rect, "Third line: right part");

Use Column and Row instead:

using RectEx;
var rects = rect.Column(3);
GUI.LabelField(rects[0], "First line");
GUI.LabelField(rects[1], "Second line");

rects = rects[2].Row(2);
GUI.LabelField(rects[0], "Third line: left part");
GUI.LabelField(rects[1], "Third line: right part");

Why do you need it?

Because you don't want to get lost among all these rect.y += rect.height and rect.width = (rect.width - 5) / 2.

Because you want to draw your GUI elements easily and feel yourself comfortable.

Because you want to make your code readable.

Because you aren't afraid of trying new awesome things, are you?

Contributing

If you want to add a bug report or feature request, just add an issue or PR.

If you create a Pull Request with new feature or bugfix, please write tests.

If you find any errors in this text, feel free to fix it.

Installation

The preferrable way to install RectEx is Unity Package Manager.

To add RectEx to your Unity project, add following dependency to your manifest.json as described here and here. Use master or any version above v0.1.0 because v0.1.0 and previos versions are not compatible with Unity Package Manager.

{
  "dependencies": {
    "st.rect-ex": "https://github.com/slavniyteo/rect-ex.git#master"
  }
}

To be able to run tests add these lines:

{
  "dependencies": {
    "st.rect-ex": "https://github.com/slavniyteo/rect-ex.git#master"
  },
  "testables": [
    "st.rect-ex"
  ]
}