Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

MouseExited called when mouse enter subview #61

Closed
Naituw opened this issue Aug 27, 2011 · 12 comments
Closed

MouseExited called when mouse enter subview #61

Naituw opened this issue Aug 27, 2011 · 12 comments

Comments

@Naituw
Copy link

Naituw commented Aug 27, 2011

Every time I move cursor into a TUITableViewCell's subview, TUIView will call cell's mouseExited. but cursor is still in cell. Is there any way to know when cursor exited the cell to another cell. Thanks!

@choco
Copy link

choco commented Aug 27, 2011

Can you post your code please? Right now I can't reproduce your problem. Are you tracking the subview with mouseEntered:onSubview: or you set the delegate to the tableviewcell view?

@Naituw
Copy link
Author

Naituw commented Aug 28, 2011

Like Twitter for Mac, If I move cursor to a cell , will call cell's mouseEntered: method.Then I move cursor to a profile image , mouseExited: will be called , I don't wanna this happen .

in my TUITableViewCell subclass:

- (void)mouseEntered:(NSEvent *)theEvent{
    [super mouseEntered:theEvent];
    isMouseInside = YES;
}

- (void)mouseExited:(NSEvent *)theEvent{
    [super mouseExited:theEvent];
    isMouseInside = NO;
}

move cursor to profile image will set isMouseInside to NO...

@choco
Copy link

choco commented Aug 28, 2011

Oh I understand...
You could try to use isPointInside inside mouseExited to check if the pointer really exited the tableviewcell like:

if([self pointInside:[self localPointForEvent:theEvent] withEvent:theEvent]) {
    NSLog(@"You're still inside the cell!");
}

But actually I'm not sure if this is the best way!

@Naituw
Copy link
Author

Naituw commented Aug 28, 2011

Thanks~ I'm coding like this now:

- (void)mouseExited:(NSEvent *)theEvent{
    if (![self eventInside:theEvent]) {
        isMouseInside = NO;
        [TUIView animateWithDuration:0.3 animations:^{
            [self redraw];
        }];
    }
    else{
        // mouse still inside.
    }
}

@Naituw Naituw closed this as completed Aug 28, 2011
@choco
Copy link

choco commented Aug 28, 2011

The downside of this solution is that if the mouse exits from the part where is located the scroll knob the appellation will think that the mouse is still inside.....
I think we should find a better way.

@Naituw
Copy link
Author

Naituw commented Aug 28, 2011

I added below code to avoid this problem, just like most app does :P

- (void)scrollWheel:(NSEvent *)theEvent {
    [super scrollWheel:theEvent];
    isMouseInside = NO;
}

@choco
Copy link

choco commented Aug 28, 2011

Are you sure this solves the problem? Because just tested it and it doesn't work! That method gets called only when you scroll.

@choco
Copy link

choco commented Aug 29, 2011

Only wanted to note that I solved using view:mouseEntered and view:mouseExited. It's more like a hack than a solution but it works pretty well and I think it's the way Twitter for mac uses.

@Naituw
Copy link
Author

Naituw commented Aug 29, 2011

How did you done this?

in TUIView+Event.m

- (void)mouseExited:(NSEvent *)event
{
  if(self.superview != nil){
    [self.superview mouseExited:event fromSubview:self];
  }
    if(_viewFlags.delegateMouseExited){
        [_viewDelegate view:self mouseExited:event];
    }
}

I have noticed it , but it seems only call in - (void)mouseExited:(NSEvent *)event , and pass cell self to delegate .

@choco
Copy link

choco commented Aug 30, 2011

You just need to create another instance variable isMouseInsideSubview and then use it to check if we are inside a subview setting its value by subclassing the methods

-(void)view:(TUIView *)v mouseEntered:(NSEvent *)event
{
    ismouseinsidesubview=YES;
}

-(void)view:(TUIView *)v mouseExited:(NSEvent *)event
{
    ismouseinsidesubview=NO;
}

and later checking this value inside the mouseExited:(NSEvent *)event and mouseEntered:(NSEvent *)event.

Another way to accomplish the same result is to set the subviews inside the the main cell view userinteractionenabled=NO and then react to the events relative to them by using the point inside method, just like it's done for the scroll knob.

@Naituw
Copy link
Author

Naituw commented Aug 31, 2011

Thanks~~ I'v done it too~ you can simply move ismouseinsidesubview=YES; to

- (void)mouseEntered:(NSEvent *)event onSubview:(TUIView *)subview{
    if (!_cellFlags.isMouseInSubView) {
        _cellFlags.isMouseInSubView = YES;
    }
    if (!_cellFlags.isMouseInside) {
        _cellFlags.isMouseInside = YES;
        [self updateViewAnimated];
    }
}

that delegate method called in cell's [super mouseEntered:theEvent];

@mrjjwright
Copy link

Here is how I handled that in a simple view

    - (void) userIsHovering {
        if (_tracking) {
            [self setControlsHidden:NO];
        }
    }

    - (void) mouseEntered:(NSEvent *)theEvent {
        _tracking = YES;
        [self performSelector:@selector(userIsHovering) withObject:nil afterDelay:0.9];
    }

    - (void) mouseEntered:(NSEvent *)event onSubview:(TUIView *)subview {
        _tracking = YES;
        _trackingSubview = YES;
    }

    -(void) mouseExited:(NSEvent *)event fromSubview:(TUIView *)subview {
        _trackingSubview  = NO;
    }

    - (void) mouseExited:(NSEvent *)theEvent {
        if (!_trackingSubview) {
            _tracking = NO;
        }

        if (!collapsed && !_tracking) {
            [self setControlsHidden:YES];
        }
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants