librelist archives

« back to archive

Best way to handle links in TUITextRenderer?

Best way to handle links in TUITextRenderer?

From:
Zach Waugh
Date:
2011-07-05 @ 01:54
I can't quite figure out how to handle the clicking of a link in a 
TUITextRenderer that's drawn in a TUITableViewCell. I have a 
TUITextRendererDelegate providing a ABFlavoredRange via 
activeRangesForTextRenderer:. It highlights the link on click, but I can't
find any delegate methods to handle that click. The code I'm trying is in 
the example project on a branch of my fork 
(https://github.com/zachwaugh/twui/tree/link-test).

Thanks,
Zach

Re: [twui] Best way to handle links in TUITextRenderer?

From:
Loren Brichter
Date:
2011-07-05 @ 02:01
Right now the best way to detect a click is by overriding mouseUp... quick
code off the top of my head:

- (void)mouseUp:(NSEvent *)event
{
	[super mouseUp:event];

	if([self eventInside:event]) { // prevent mouse down/drag-out/up activating links
		if(myRenderer.hitRange) { // will be non-nil if the mouse just clicked 
an active range
			// do something with the range
		}
	}
}

Loren

On Jul 4, 2011, at 9:54 PM, Zach Waugh wrote:

> I can't quite figure out how to handle the clicking of a link in a 
TUITextRenderer that's drawn in a TUITableViewCell. I have a 
TUITextRendererDelegate providing a ABFlavoredRange via 
activeRangesForTextRenderer:. It highlights the link on click, but I can't
find any delegate methods to handle that click. The code I'm trying is in 
the example project on a branch of my fork 
(https://github.com/zachwaugh/twui/tree/link-test).
> 
> Thanks,
> Zach

Re: [twui] Best way to handle links in TUITextRenderer?

From:
Zach Waugh
Date:
2011-07-05 @ 15:50
Thanks, that put me on the right track. Found that mouseUp: in
TUITableViewCell already does most of the work, so I can handle it in the
TUITableViewDelegate method, which works even better in my case:

- (void)tableView:(TUITableView *)tableView
didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent
*)event
{
    if ([event clickCount] == 1) {
        TUITableViewCell *cell = [tableView
cellForRowAtIndexPath:indexPath];

        for (TUITextRenderer *textRenderer in cell.textRenderers) {
            // will be non-nil if the mouse just clicked an active range
            if (textRenderer.hitRange) {
                // Do something with link...
                NSLog(@"hitRange: %@", textRenderer.hitRange);
                [textRenderer resetSelection]; // right place for this?
            }
        }
    }
}

One other small issue, the link gets highlighted with a white background on
click, but that highlight doesn't go away until you click somewhere else. I
can clear it with the [textRenderer resetSelection], but not sure if that's
the best way.

Zach

(sorry if this is a dupe, replied yesterday, but got a confirm subscription
email back, so wasn't sure if it made it through)

On Mon, Jul 4, 2011 at 10:01 PM, Loren Brichter <loren.brichter@gmail.com>wrote:

> Right now the best way to detect a click is by overriding mouseUp... quick
> code off the top of my head:
>
> - (void)mouseUp:(NSEvent *)event
> {
> [super mouseUp:event];
>
> if([self eventInside:event]) { // prevent mouse down/drag-out/up activating
> links
> if(myRenderer.hitRange) { // will be non-nil if the mouse just clicked an
> active range
> // do something with the range
> }
> }
> }
>
> Loren
>
> On Jul 4, 2011, at 9:54 PM, Zach Waugh wrote:
>
>  I can't quite figure out how to handle the clicking of a link in a
> TUITextRenderer that's drawn in a TUITableViewCell. I have a
> TUITextRendererDelegate providing a ABFlavoredRange via 
activeRangesForTextRenderer:.
> It highlights the link on click, but I can't find any delegate methods to
> handle that click. The code I'm trying is in the example project on a branch
> of my fork (https://github.com/zachwaugh/twui/tree/link-test).
>
> Thanks,
> Zach
>
>
>

Re: [twui] Best way to handle links in TUITextRenderer?

From:
Loren Brichter
Date:
2011-07-05 @ 15:56
> Thanks, that put me on the right track. Found that mouseUp: in 
TUITableViewCell already does most of the work, so I can handle it in the 
TUITableViewDelegate method, which works even better in my case:
> 
> - (void)tableView:(TUITableView *)tableView 
didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent 
*)event
> {
>     if ([event clickCount] == 1) {
>         TUITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
>     
>         for (TUITextRenderer *textRenderer in cell.textRenderers) {
>             // will be non-nil if the mouse just clicked an active range
>             if (textRenderer.hitRange) {
>                 // Do something with link...
>                 NSLog(@"hitRange: %@", textRenderer.hitRange);
>                 [textRenderer resetSelection]; // right place for this? 
>             }
>         }
>     }
> }

Awesome.

> One other small issue, the link gets highlighted with a white background
on click, but that highlight doesn't go away until you click somewhere 
else. I can clear it with the [textRenderer resetSelection], but not sure 
if that's the best way.

That's probably your best bet for now.  Perhaps .hitRange should be nil'd 
automatically.  Need to think about the best place to do that (want to 
ensure that everyone who cares about .hitRange has a chance to read it 
before it's nil'd).

> Zach
> 
> (sorry if this is a dupe, replied yesterday, but got a confirm 
subscription email back, so wasn't sure if it made it through)

Weird, it did make it through (sorry I didn't get back to you last night).

Loren

> On Mon, Jul 4, 2011 at 10:01 PM, Loren Brichter 
<loren.brichter@gmail.com> wrote:
> Right now the best way to detect a click is by overriding mouseUp... 
quick code off the top of my head:
> 
> - (void)mouseUp:(NSEvent *)event
> {
> 	[super mouseUp:event];
> 
> 	if([self eventInside:event]) { // prevent mouse down/drag-out/up 
activating links
> 		if(myRenderer.hitRange) { // will be non-nil if the mouse just clicked
an active range
> 			// do something with the range
> 		}
> 	}
> }
> 
> Loren
> 
> On Jul 4, 2011, at 9:54 PM, Zach Waugh wrote:
> 
>> I can't quite figure out how to handle the clicking of a link in a 
TUITextRenderer that's drawn in a TUITableViewCell. I have a 
TUITextRendererDelegate providing a ABFlavoredRange via 
activeRangesForTextRenderer:. It highlights the link on click, but I can't
find any delegate methods to handle that click. The code I'm trying is in 
the example project on a branch of my fork 
(https://github.com/zachwaugh/twui/tree/link-test).
>> 
>> Thanks,
>> Zach
> 
>