[haiku-development] Re: Patch for BTextControl to add the EmptyHint functionality

  • From: Ryan Leavengood <leavengood@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 21 Jun 2012 17:35:47 -0400

On Thu, Jun 21, 2012 at 11:43 AM, François Revol <revol@xxxxxxx> wrote:
>
> FWIW, placeholder is the name used by HTML5:
> http://diveintohtml5.info/forms.html

Yeah I had the same thought since I actually used that for the first
time just the other day in HTML. Except for our class it should be
Placeholder not PlaceHolder (no capital H) since placeholder is a
valid English word.

As for your implementation, I think you have chosen a bad approach.
You should not use SetText, nor do you need the fEmptyHintShow
instance variable. You just need the placeholder text, and if it is
not NULL and the current text length is 0, you should draw it with a
lighter tint of the text color for the text view (using whatever other
facilities the text view has for drawing text and wrapping it, which
probably means _DrawLines and _DrawLine, which will likely need to be
changed a bit for this.) There are just too many things which can go
wrong with the SetText approach, plus the placeholder text should be
drawn lighter (hence my suggestion for tinting the normal text color
lighter.)

Also I like the implementation of the HTML5 placeholder which actually
does not disappear until you have typed something, instead of when the
input gets focused. That actually makes it easier to implement,
because basically you don't worry about the focus, just whether there
is any text.

-- 
Regards,
Ryan

Other related posts: