Skip to content

Add UiImage offset property#5629

Closed
afonsolage wants to merge 6 commits intobevyengine:mainfrom
afonsolage:ui_uimage_offset
Closed

Add UiImage offset property#5629
afonsolage wants to merge 6 commits intobevyengine:mainfrom
afonsolage:ui_uimage_offset

Conversation

@afonsolage
Copy link
Contributor

@afonsolage afonsolage commented Aug 9, 2022

Objective

Currently UiImage component is just a unit struct for Handle<Image> . At it's core, it draws the image and that's it. If someone needs to have a more complex use case, like implementing a nine patch, one have to use TextureAtlas which is good, but is a overkill for ui works.

This PR is related to #5070, but it aims to make TextureAtlas to work with UiImage which is a different use case IMO, since one should use TextureAtlas and UiImage together on same entity.

Solution

Add an offset property to UiImage and enable to render a portion of the image, much like a TexturaAtlas but simplified, so users may create it's own image atlas and reuse on many UiImage components.

Changelog

  • Added offset property on UiImage and changed to from unit struct to normal struct;
  • Removed Deref and DerefMut from UiImage since it's no longer a unit struct;
  • Changed extract_uinodes to use UiImage::offset when it's non-zero;
  • Added image_button example:
    image_button

Migration Guide

UiImage is now a normal struct so it can't be directly dereferenced anymore and should use normal struct initialization.

@IceSentry IceSentry added A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible labels Aug 9, 2022
@alice-i-cecile
Copy link
Member

Ping @ManevilleF for review here :)

@alice-i-cecile alice-i-cecile requested a review from mockersf August 9, 2022 16:24
@alice-i-cecile alice-i-cecile added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Aug 9, 2022

fn main() {
App::new()
// Change image filter to a pixel-art friendly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Change image filter to a pixel-art friendly
// Change image filter to a pixel-art friendly mode

}

// Image rect in pixels, inside the base image.
// Values are using to built a rect with begin (X, Y) and end (X, Y) format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users would really benefit from some more advice on how these values were determined.

align_items: AlignItems::Center,
..default()
},
// Default image has no offset, but that's OK since it'll be update it on button_system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Default image has no offset, but that's OK since it'll be update it on button_system
// Default image has no offset, but that's OK since it'll be updated in button_system

@alice-i-cecile
Copy link
Member

Code quality and docs seem fine, minus a few nits. I'm not fully sold on the grand vision here, so I'll defer to @mockersf and @ManevilleF who've thought about this space more.

@ManevilleF
Copy link
Contributor

ManevilleF commented Aug 9, 2022

The new property offset should be called rect and I think it should be a separate component, overriding the default behaviour to be more ECS friendly.

But to customize Rect of a texture is what a TextureAtlas is for, and I think #5103 + #5072 is the way, as UI and sprites shouldn't behave differently in that scope

@alice-i-cecile alice-i-cecile added the X-Needs-SME This type of work requires an SME to approve it. label Aug 9, 2022
@mockersf
Copy link
Member

mockersf commented Aug 9, 2022

I can't do a complete review anytime soon, but anything that impact rendered size should impact layout, and I didn't see layout files being modified in this PR

@alice-i-cecile
Copy link
Member

Closing in favor of #5103; let's collect our efforts there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide X-Needs-SME This type of work requires an SME to approve it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants