[haiku-bugs] Re: [Haiku] #3825: URL linkification in People [easy]

  • From: "stippi" <trac@xxxxxxxxxxxx>
  • Date: Mon, 05 Apr 2010 10:04:46 -0000

#3825: URL linkification in People [easy]
---------------------------------+------------------------------------------
 Reporter:  humdinger            |       Owner:  nobody
     Type:  enhancement          |      Status:  new   
 Priority:  low                  |   Milestone:  R1    
Component:  Applications/People  |     Version:        
 Keywords:                       |   Blockedby:        
 Platform:  All                  |    Blocking:        
---------------------------------+------------------------------------------

Comment(by stippi):

 Ok, just now noticed it's supposed to be identifying a click on the label
 "URL". The position of "URL" is Divider() on the right side and Divider()
 - StringWidth(Label()) on the left side. The top and bottom could be
 either Bounds().top and Bounds().bottom or with an inset. But hardcoding
 bottom to 15 will just break things when the user has a bigger font
 configured. Also nice will be overriding MouseMoved() and use the new
 BCursor(B_CURSOR_ID_FOLLOW_LINK) via SetViewCursor(). Since you will need
 the position of the URL label in both functions, it would be nice to code
 a new private method BRect _VisibleLabelBounds() const like this:

 {{{
 BRect
 TTextControl::_VisibleLabelBounds() const
 {
     BRect bounds(Bounds());
     // TODO: Could actually check current alignment of the label.
     // The code below works only for right aligned labels.
     bounds.right = Divider();
     bounds.left = bounds.right - StringWidth(Label());
    return bounds;
 }
 }}}

 And then you can check the current mouse pos in MouseDown():

 {{{
     if (_VisibleLabelBounds().Contains(mousePos))
         _LaunchURL(Text());
     else
         BTextControl::MouseDown(mousePos);
 }}}

 and in MouseMoved():

 {{{
     if (_VisibleLabelBounds().Contains(mousePos)) {
         BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK);
         SetViewCursor(&linkCursor, true);
     } else
         SetViewCursor(B_SYSTEM_CURSOR_DEFAULT, true);

     BTextControl::MouseMoved(mousePos, ...);
 }}}

 (All from memory so may contain errors...)

 As you can see, writing small functions like this can greatly improve the
 code quality and readability. It is totally clear what happens in
 MouseDown() now, even without any comments. While it wouldn't be clear at
 all in your version of the code, unless one reads the complete description
 of this ticket. :-)

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/3825#comment:6>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: