Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

enhance UiRect with convenience methods #4323

Closed
pubrrr opened this issue Mar 24, 2022 · 12 comments
Closed

enhance UiRect with convenience methods #4323

pubrrr opened this issue Mar 24, 2022 · 12 comments
Labels
A-Utils Utility functions and types C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@pubrrr
Copy link
Contributor

pubrrr commented Mar 24, 2022

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

Rect, UiRect respectively after #4276 is merged, is a plain data structure representing rectangles used for UI. There are certain computations associated to rectangles, that users might frequently need.

What solution would you like?

Offer convenience methods such as

  • center(&self) -> Point
  • translate(self, Vec2) -> Self,
  • ...

Additional context

Egui already has a similar struct.

@pubrrr pubrrr added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Mar 24, 2022
@mockersf
Copy link
Member

Rect/UiRect is not really a rectangle, it's informations about each side of a rectangle: the width of the border, the margins, ...
So center or translate don't really make sense for this

@ghost
Copy link

ghost commented Mar 25, 2022

Adding to what @mockersf said:

I think the Rect that should be updated here is not the Rect/UiRect from bevy_math/bevy_ui but the Rect from bevy_sprite. This one also has two points like the one in egui and offers the same width, height and size methods. For this Rect it would make sense to have something like a center function.

bevy_math

/// A rect, as defined by its "side" locations
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
#[reflect(PartialEq)]
pub struct Rect<T: Reflect + PartialEq> {
    pub left: T,
    pub right: T,
    pub top: T,
    pub bottom: T,
}

bevy_sprite

/// A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere
/// (top-left, bottom-left, etc)
#[repr(C)]
#[derive(Default, Clone, Copy, Debug, Reflect)]
pub struct Rect {
    /// The beginning point of the rect
    pub min: Vec2,
    /// The ending point of the rect
    pub max: Vec2,
}

@pubrrr
Copy link
Contributor Author

pubrrr commented Mar 25, 2022

For my understanding: What is the difference between those two Rects? How are they supposed to be used?

@ghost
Copy link

ghost commented Mar 26, 2022

Rect/UiRect from bevy_math/bevy_ui

The Rect/UiRect from bevy_math/bevy_ui is used to define a size for each side of a rectangle (e.g. position, margin, padding, borders). So essentially stuff like "How large should my padding on the left be?" or "How thick should the right border be?".

For more details about how the UiRect is used you can read through the documentation here.

Rect from bevy_sprite

The Rect from bevy_sprite is used to define an actual rectangle. This is for example used in the TextureAtlas to define the area/ the rectangle of every sprite that is located inside of it (see TextureAtlas).

@pubrrr
Copy link
Contributor Author

pubrrr commented Mar 27, 2022

Isn't it a bit weird to express a position or a margin as a rectangle? At least for me this sounds really confusing.

@mockersf
Copy link
Member

The name isn't very good... Don't hesitate if you have a better idea in #4276

@aevyrie aevyrie added A-Utils Utility functions and types and removed S-Needs-Triage This issue needs to be labelled labels Apr 22, 2022
@james7132 james7132 added the D-Trivial Nice and easy! A great choice to get started with Bevy label Dec 10, 2022
@dtaralla
Copy link
Contributor

Since #5686 was merged and the center() method now exists on bevy_math::Rect, should this be closed or can I mirror additional utility methods from egui? Like

  • shrink(self, amount: Vec2) -> Rect (Shrinks or dilates)
  • translate(self, amount: Vec2) -> Rect

There are other methods like rotate_bb(), to get the bounding box of a rotated rect, but I'm not sure if these would be nice to have too. Translation and dilation seem basic enough that some users might look for them at some point I guess. I didn't find any sites in bevy or examples where any of these would be useful though. I think it might be better to close this issue as resolved by #5686?

@viridia
Copy link
Contributor

viridia commented Aug 22, 2023

Naming suggestion: "Insets".

@Jax-Hax
Copy link

Jax-Hax commented Sep 12, 2023

Should there be a way to convert between the two? Then it would allow for building a Rect in bevy_math then converting it to a UIRect in bevy_ui. Or should there be the corresponding functions like center() on the UIRect as well? Sorry if these already exist, trying to find my first contribution and I don't really know what I'm doing.

@theotherphil
Copy link
Contributor

I'm another new user who's stumbled across this issue while looking to make a first contribution to Bevy and is not sure what, if anything, needs to actually be done here.

I think this issue is either fixed by #5686 or is too vague to be actionable.

I'm not sure what the etiquette is for pinging maintainers, so I'll just ask @alice-i-cecile directly: do you agree that this issue should be closed, or is there something specific required to resolve it?

@viridia
Copy link
Contributor

viridia commented Jun 7, 2024

Other name suggestions:

  • UiEdgeWidths
  • UiEdges
  • UiSides
  • UiInsets
  • UiMargins

@alice-i-cecile
Copy link
Member

I think this should be closed. I'm not opposed to more utility methods, but I don't think this is a useful place to start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Utils Utility functions and types C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

No branches or pull requests

9 participants