[haiku-3rdparty-dev] Re: SetViewColor for BString not working :-(

  • From: Dennis Catt <dcatt.haiku@xxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Sat, 08 Oct 2016 11:35:49 -0400

Rene Gollent wrote:


On Oct 7, 2016 19:27, "Dennis Catt" <dcatt.haiku@xxxxxxx <mailto:dcatt.haiku@xxxxxxx>> wrote:
>
> I'll try to play around with it some more this weekend.  I re-ordered
> some code to get around it where I don't SetViewColor to the BStringView
> until after it's been added to its parent BView.  The funny part is,
> that also works in the case of A4 though I figured it would and wish I'd
> would have thought of that before now.
>

Just as a general note, for the most part it's best practice to attach a view/control to a window before you start trying to perform much in the way of any operations on it. The reason is twofold:

1) quite a few controls inherit settings from their parent on AttachedToWindow(), especially since things like the various UI colors require querying the app_server, which the view cannot do until it has a parent window.

2) related to the last part, until the view is attached to a window, it cannot send/receive messages, which quite a bit of other functionality also relies upon.

I haven't checked the source for this case in particular to confirm, but chances are what was happening is the string view was adopting its parent's view color when added, thus overwriting the one you had manually set prior to that.

Regards,

Rene

Rene,

So maybe this isn't a bug after all and the change in behavior I saw in the spring with a nightly build was actually a bug itself that got squashed? I'm okay with the approach of not manipulating child view objects after they've been added to their parent view objects. However, in my mind it is weird and unexpected behavior since I can set various things prior that don't get overridden by chance when added, which would lead one to believe that maybe there is a bug.

-DCatt

Other related posts: