{"id":13730859,"url":"https://github.com/Thundernerd/Unity3D-ConstrainedRect","last_synced_at":"2025-05-08T03:32:05.858Z","repository":{"id":89650662,"uuid":"240896939","full_name":"Thundernerd/Unity3D-ConstrainedRect","owner":"Thundernerd","description":"A simple helper for constraining rects to windows and other rects","archived":false,"fork":false,"pushed_at":"2021-01-06T19:36:58.000Z","size":49,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-13T23:41:27.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Thundernerd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"thundernerd","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-02-16T13:31:43.000Z","updated_at":"2023-12-23T13:19:33.000Z","dependencies_parsed_at":"2024-01-06T15:27:05.731Z","dependency_job_id":null,"html_url":"https://github.com/Thundernerd/Unity3D-ConstrainedRect","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thundernerd%2FUnity3D-ConstrainedRect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thundernerd%2FUnity3D-ConstrainedRect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thundernerd%2FUnity3D-ConstrainedRect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thundernerd%2FUnity3D-ConstrainedRect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thundernerd","download_url":"https://codeload.github.com/Thundernerd/Unity3D-ConstrainedRect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224695745,"owners_count":17354473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:20.459Z","updated_at":"2024-11-14T21:31:42.669Z","avatar_url":"https://github.com/Thundernerd.png","language":"C#","readme":"# Constrained Rect\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg alt=\"GitHub package.json version\" src =\"https://img.shields.io/github/package-json/v/Thundernerd/Unity3D-ConstrainedRect\" /\u003e\n\t\u003ca href=\"https://github.com/Thundernerd/Unity3D-ConstrainedRect/issues\"\u003e\n\t\t\u003cimg alt=\"GitHub issues\" src =\"https://img.shields.io/github/issues/Thundernerd/Unity3D-ConstrainedRect\" /\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/Thundernerd/Unity3D-ConstrainedRect/pulls\"\u003e\n\t\t\u003cimg alt=\"GitHub pull requests\" src =\"https://img.shields.io/github/issues-pr/Thundernerd/Unity3D-ConstrainedRect\" /\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/Thundernerd/Unity3D-ConstrainedRect/blob/master/LICENSE.md\"\u003e\n\t\t\u003cimg alt=\"GitHub license\" src =\"https://img.shields.io/github/license/Thundernerd/Unity3D-ConstrainedRect\" /\u003e\n\t\u003c/a\u003e\n\t\u003cimg alt=\"GitHub last commit\" src =\"https://img.shields.io/github/last-commit/Thundernerd/Unity3D-ConstrainedRect\" /\u003e\n\u003c/p\u003e\n\nConstrained Rect is a small helper that aims to make it easier to create Rect's based on existing ones.\n\n## Installation\n1. The package is available on the [openupm registry](https://openupm.com). You can install it via [openupm-cli](https://github.com/openupm/openupm-cli).\n```\nopenupm add net.tnrd.constrainedrect\n```\n2. Installing through a [Unity Package](http://package-installer.glitch.me/v1/installer/package.openupm.com/net.tnrd.constrainedrect?registry=https://package.openupm.com) created by the [Package Installer Creator](https://package-installer.glitch.me) from [Needle](https://needle.tools)\n\n[\u003cimg src=\"https://img.shields.io/badge/-Download-success?style=for-the-badge\"/\u003e](http://package-installer.glitch.me/v1/installer/package.openupm.com/net.tnrd.constrainedrect?registry=https://package.openupm.com)\n\n3. You can also install via git url by adding these entries in your **manifest.json**\n```json\n\"net.tnrd.constrainedrect\": \"https://github.com/Thundernerd/Unity3D-ConstrainedRect.git\"\n```\n\n\n## Usage\nUsing constrained rects is easy. You simply call `Constrain.To(...)` and pass it either a `Rect` or an `EditorWindow`.\n\n\nHere's an example using a simple Rect\n```csharp\nprivate void Foo()\n{\n    Rect rect = new Rect(16, 16, 128, 128);\n\n    Rect constrainedRect = Constrain.To(rect)\n        .Left.Relative(8)\n        .Top.Relative(16)\n        .Right.Relative(24)\n        .Bottom.Relative(32)\n        .ToRect();\n\n    Debug.Log(constrainedRect.xMin); // Logs 24\n    Debug.Log(constrainedRect.yMin); // Logs 32\n    Debug.Log(constrainedRect.xMax); // Logs 104\n    Debug.Log(constrainedRect.yMax); // Logs 96\n}\n```\n\nAside from `Left`, `Top`, `Right`, and `Bottom`, you can also use `Width` and `Height`. If you want to use `width` and `height` you will have to omit either `left` or `right` and `top` or `bottom` respectively. \n\nOther modifiers are `Absolute` and `Percentage`. \nAbsolute is what it suggests: instead of taking into account it's constraints it just returns the value given.\n\nPercentage expects a float value between 0 and 1 (inclusive) and multiplies that value with the constrained property.\n```csharp\nprivate void Foo()\n{\n    Rect rect = new Rect(16, 16, 128, 128);\n\n    Rect constrainedRect = Constrain.To(rect)\n        .Width.Percentage(0.5f)\n        .ToRect();\n\n    Debug.Log(constrainedRect.width); // Logs 64\n}\n```\n\n### Important\nDue to the nature of Unity's editor architecture it is common to use Constrained Rects in high volume. In an attempt to prevent creating and collecting too much garbage as a result of using Constrained Rects they are now being pooled.\n\nAfter you've finalized your Constrained Rect by calling `.ToRect()` the Constrained Rect will be returned to the pool and free to use for other instances. \n\nWhile all of this happens under the hood it is important to understand that from the moment that you call `.ToRect()` the Constrained Rect will throw an exception if it is not being used. This also means that if it is being used then the properties and variables might be different from what you might expect.\n\n## Support\n**Constrained Rect** is a small and open-source utility that I hope helps other people. It is by no means necessary but if you feel generous you can support me by donating.\n\n[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/J3J11GEYY)\n\n## Contributing\nPull requests are welcomed. Please feel free to fix any issues you find, or add new features.\n","funding_links":["https://ko-fi.com/thundernerd","https://ko-fi.com/J3J11GEYY"],"categories":["C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThundernerd%2FUnity3D-ConstrainedRect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FThundernerd%2FUnity3D-ConstrainedRect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThundernerd%2FUnity3D-ConstrainedRect/lists"}