Author Topic: [SOLVED] BUG(?)/REQUEST: UIPanel onChange not called if panel resizes  (Read 5881 times)

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Hello there!

Not sure if this is intentional, but the callback onChange in UIPanel will not be called when the panel resizes... I've written my own constraint-system and it works as expected with UIWidget onChange, but UIPanel onChange will only be called in case of widgets inside it changes (?). Is this expected behaviour? If so, it would be really appreciated if you added a callback similar to the one in UIWidget! I'll change it for now, but I really hate having custom code hanging around.

And yes, I do realise the descriptions for the both delegates differ, but it doesn't really make sense (IMO) to not notify about resize-changes.

Even better would be to have this specific callback in the UIRect-class (Any reason why it isn't there in the first place?), so one can listen for changes for all kinds of rects (UIPanel & UIWidget).

Have a nice day. :)
« Last Edit: February 28, 2014, 08:30:26 AM by helmesjo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BUG(?)/REQUEST: UIPanel onChange not called if panel resizes
« Reply #1 on: February 27, 2014, 05:13:31 PM »
They were actually different features added at different times (panel one came first I think). I can certainly see how this can be confusing though. I will give it some thought -- thanks for pointing it out.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: [SOLVED] BUG(?)/REQUEST: UIPanel onChange not called if panel resizes
« Reply #2 on: February 28, 2014, 08:47:17 AM »
Sounds good!

And while we're at it, having the actual rect-data (width, height etc.) in UIRect would make great sense and ease up the usage! :)

EDIT
Just noticed that onChange in UIWidget gets called not only when size/position changes, but also when child-widgets move/resize etc. If this is intentional I think you should really divide these callbacks up into more specific once, and not go fore "one callback to rule them all". In my case I just want to update constraints when the widget/panel (rect) of interest changes size/position, and nothing more (since it's not very efficient to update constraints).
« Last Edit: February 28, 2014, 11:34:35 AM by helmesjo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [SOLVED] BUG(?)/REQUEST: UIPanel onChange not called if panel resizes
« Reply #3 on: February 28, 2014, 06:19:00 PM »
UIWidget's onChanged only gets called when the widget's transform, width or height changes. You can check yourself where 'mMoved = true;' gets set in UIWidget. There are only a few places.
  1.                 // Notify the listeners
  2.                 if (mMoved && onChange != null) onChange();

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: [SOLVED] BUG(?)/REQUEST: UIPanel onChange not called if panel resizes
« Reply #4 on: March 01, 2014, 05:36:16 AM »
Yes you are correct. Noticed after I posted that it was the panels onChange playing tricks on me (since I expected it to only get called when panel resized/moved)! That onChange in UIRect would be a lifesaver! ;)

EDIT
Since I'm already spamming away here: Please make sure to always pass the sender of the event as a parameter (eg. pass the actual UIWidget that changed as first parameter).

Ciao!