Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default cancelTouchFocusChild() to protected #2355

Closed
wants to merge 1 commit into from

Conversation

@Phibedy
Copy link
Contributor

Phibedy commented Sep 20, 2014

To be able to extend Scrollpane and have control about those methods,
see http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=16416
Not sure what has to be changed on the gwt backend

To be able to extend Scrollpane and have control about those methods,
see http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=16416
Not sure what has to be changed on the gwt backend
@NathanSweet
Copy link
Member

NathanSweet commented Sep 20, 2014

Does setting ScrollPane#setCancelTouchFocus to false help your issue?

@Phibedy
Copy link
Contributor Author

Phibedy commented Sep 20, 2014

No, as I need some informationa about the Scrollpane to block it or not.
A protected method ScrollPane#isCancelTouchFocus(InputEvent event) that is called in ScrollPane#cancelTouchFocusedChild (InputEvent event) would do the job. (line 234 - if (!cancelTouchFocus) return;) -> if (!isCancelTouchFocus(event)) return;
isCancelTouchFocus(InputEvent event) would return by default "cancelTouchFocus" so it wouldn't change the bahavior but I could override it and have the Inputevent.
Thanks for support :)

@NathanSweet
Copy link
Member

NathanSweet commented Sep 20, 2014

Before I merge, I'd like to understand why you need it. Why block it sometimes? Maybe disable flick scrolling?

@Phibedy
Copy link
Contributor Author

Phibedy commented Sep 20, 2014

Dont think it would do the job:
I got a scrollpane full of WidgetGroups (two actors in each, one on top of the other). if the user drags left/right the scrollpane should not scroll down/up (User wont get a 100% left/right move). Instead the actor on the top will move to the lift/right you will see the actor underneeth.
That's why I cant just block the scrollpane like block "touchDown-events" as I still want to be able to scroll up/down.
I need a way to determine if the user does a scroll-y (if yes, cancelChild..., if no block cancelChild)

@NathanSweet
Copy link
Member

NathanSweet commented Sep 20, 2014

How about setScrollingDisabled(false, true)?

@Phibedy
Copy link
Contributor Author

Phibedy commented Sep 20, 2014

Yes, I am using that for disabling scrolling, but that doesnt have any effect on releasing the focus of the childs. the draglistener is attached to each widgetGround inside the scrollpane.
see http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=16416

@NathanSweet
Copy link
Member

NathanSweet commented Sep 20, 2014

Maybe you can show a simple executable example of the problem? I'm guessing you can stop the drag event so it never reaches the scroll pane if the DragAndDrop is handling it.

@Phibedy
Copy link
Contributor Author

Phibedy commented Sep 20, 2014

Project :)
Just a scrollpane with two actos and draglisteners inside a table.
applicationlistener:
www.mineforce.de/testp.zip
complete project:
www.mineforce.de/test.zip
I dont think it can be stopped by some listeners as I dont want to block scroll-y and touch-up-events cant be blocked in scene2d.

@NathanSweet
Copy link
Member

NathanSweet commented Sep 20, 2014

Next time please use post a single class that shows the issue. Here's code to do what you want, I don't think ScrollPane needs any changes.

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.DragListener;

public class TestGui extends Table {

    private Table contentTable;

    /** if the user drags in x -direction drag should be called until the user, not the scrollpane calls the touchUp <br>
     * I am not looking for a hacky solution I need one class to do this as this feature is used very often <br>
     * @param stage */
    public TestGui (final Stage stage) {
        stage.clear();
        this.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        this.defaults().top();
        contentTable = new Table();
        Image firstL = new Image(new Texture("badlogic.jpg"));
        Image secondL = new Image(new Texture("badlogic.jpg"));
        contentTable.add(firstL).expandX().fillX();
        contentTable.row();
        contentTable.add(secondL).expandX().fillX();
        contentTable.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        final ScrollPane sp = new ScrollPane(contentTable);
        add(sp).expandX().fillX().height(Gdx.graphics.getHeight() / 2);
        sp.setScrollingDisabled(true, false);
        stage.addActor(this);

        DragListener dragListener = new DragListener() {
            private boolean ignoreHorizontalDrag;

            public void dragStart (InputEvent event, float x, float y, int pointer) {
                System.out.println(Math.abs(getTouchDownY() - y));
                ignoreHorizontalDrag = Math.abs(getTouchDownY() - y) > getTapSquareSize();
                if (ignoreHorizontalDrag) {
                    System.out.println("Drag started vertically, ignore DragListener drag.");
                } else {
                    System.out.println("Drag started horizontally, ignore ScrollPane drag.");
                    sp.cancel();
                }
            }

            public void drag (InputEvent event, float x, float y, int pointer) {
                if (ignoreHorizontalDrag) return;
                System.out.println("drag first " + x);
            }
        };
        dragListener.setTapSquareSize(19); // Can be anything less than the ScrollPane's default of 20.
        firstL.addListener(dragListener);
    }

    public static void main (String[] arg) {
        new LwjglApplication(new Test());
    }
}
@Phibedy
Copy link
Contributor Author

Phibedy commented Sep 20, 2014

I will do it next time :)
That's not exactly what I was looking for. For example if I draw an "L" it wont perform a scrolldown -> move actor to the left.
But thanks for helping anyways :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.