Code Monkey home page Code Monkey logo

Comments (12)

choco avatar choco commented on June 23, 2024

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?

from twui.

Naituw avatar Naituw commented on June 23, 2024

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...

from twui.

choco avatar choco commented on June 23, 2024

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!

from twui.

Naituw avatar Naituw commented on June 23, 2024

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.
    }
}

from twui.

choco avatar choco commented on June 23, 2024

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.

from twui.

Naituw avatar Naituw commented on June 23, 2024

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

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

from twui.

choco avatar choco commented on June 23, 2024

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

from twui.

choco avatar choco commented on June 23, 2024

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.

from twui.

Naituw avatar Naituw commented on June 23, 2024

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 .

from twui.

choco avatar choco commented on June 23, 2024

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.

from twui.

Naituw avatar Naituw commented on June 23, 2024

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];

from twui.

mrjjwright avatar mrjjwright commented on June 23, 2024

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];
        }
    }

from twui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.