Cant use TappedEventArgs in OnTapped Event - event-handling

In all examples regarding Tapping Eventhandling in MAUI I have seen the Handlerfunction gets TappedEventArgs.
-> void OnTapGestureRecognizerTapped(object sender, TappedEventArgs args)
-> XAML: ...
If I try to do so, Visual Studio says "CS0123 - No overload for "OnTapGestureRecognizerTapped" matches the delegate EventHandler".
I have to change it from TappedEventArgs to EventArgs.
No matter if in XAML or C# I always get this result.
What am I doing wrong?
Did I miss any Using xyz?
I need TappedEventArgs or how else can I detect the tapped position?
Please help me.
I need an Eventhandler with TappedEventArgs instead of EventArgs.
I tried casting, but does not work.

Related

Set OnAutomaticHitTest and OnInteractiveHitTest during runtime

I'm placing my Plane Stage and Plane Finder and setting the attributes at runtime, but there are two attributes I can't figure out how to set: OnAutomaticHitTest and OnInteractiveHitTest.
I saw that it expects something of the type HitTestEvent, but i can't figure out how to set my custom function here.
Can someone Help me?
You can find the documentation for the PlaneFinderBehaviour here
Essentially, you don't actually define these attribute but you use them to fire events.
For example:
public class CustomPlaneFinderBehaviour : PlaneFinderBehaviour
{
public void CustomIntPerformHitTest(Vector2 screenPosition)
{
//Triggered on interactive hit test
}
public void CustomAutoPerformHitTest(Vector2 screenPosition)
{
//Triggered on automatic hit test
}
}
Then in the inspector you are able to define the events, by pressing the plus button and choosing the current script in the box. It then gives you the option to change the function that is called.
Here on interactive hit test has been defined and automatic hit test has not:
You need to use Unity's AddListener call
void HandleHitTest(HitTestResult htr)
{
//Handle Test Here
}
planeFinderBehavior.OnAutomaticHitTest.AddListener(HandleHitTest);

SetAllDirty() not working at runtime in Unity?

Edit:
After doing a little more debugging I found that it doesn't work only when I start the game and have the panel/canvas that it sits on disabled. If I have the panel/canvas enabled the whole time then it redraws correctly. However, this obviously isn't a proper solution because I can't show the results before the end of the quiz. I need the panel to be disabled so that I can show it later after the end of the quiz.Is there a reason this is happening? How can I fix this?
End Edit
So I found a script on GitHub that basically creates a UI polygon. It works great in the Editor, however, I want to modify it at runtime. From everything I read all I need to do is call the method SetAllDirty() and it will update the MaskableGraphic and Redraw it. However, whenever I call it, nothing happens. SetVerticesDirty() also did not work. Can someone see where I am going wrong here.
All I am doing is calling DrawPolygon and giving it 4 sides, and passing a float[5] I modified it so that right after I finish setting up my new variables I call SetAllDirty()
Something like this:
public void DrawPolygon(int _sides, float[] _VerticesDistances)
{
sides = _sides;
VerticesDistances = _VerticesDistances;
rotation = 0;
SetAllDirty();
}
Like I said, it works fine in the editor(not runtime), and I am also getting all the values passed to the script correctly(during runtime), but it is not redrawing. As soon as I manipulate something in the inspector it will redraw to the correct shape.
The rest of the script is posted here:
https://github.com/CiaccoDavide/Unity-UI-Polygon/blob/master/UIPolygon.cs
This is the method that I call DrawPolygon from on a Manager script. I see in the log that it prints out the statement, Quiz has ended.
void EndQuiz()
{
Debug.Log("Quiz has ended.");
QuizPanel.SetActive(false);
ResultsPanel.SetActive(true);
float[] Vertices = new float[5] { score1, score2, score3, score4, score1};
resultsPolygon.DrawPolygon(4, Vertices);
}

GWT input event on TextBox

Given the following code:
TextBox tb = new TextBox();
tb.addValueChangeHandler(new ValueChangeHandler<String>() {
#Override
public void onValueChange(ValueChangeEvent<String> event) {
Window.alert(event.getValue());
}
});
onValueChange will be called if the TextBox loses focus. I am trying to have it called whenever the input value changes. The solutions I have read all involve handling the keyup and paste events such as in this answer. How to build a Facebook-style input box in GWT Hasn't this been addresses in GWT 2.5.1? Is there a way to bind to the native input change method? Another widget or using the UI framework would be acceptable if they have this functionality
The only way in GWT is to bind to the key down/key up and paste events.
Please send a patch to add support for the input event (using addBitlessDomHandler): http://www.gwtproject.org/makinggwtbetter.html, it should be rather easy (add a acase in DOMImpl) and has good chances to make it in (and if sent early enough, would have good chances to ship in GWT 2.6)
The solution is use the right event and that is the input event, so look how to hook on it, there are many ways to do it. Because I work with elements and not with Widgets this the code that I use it:
Element input = Document.get().getElementById("my-input");
DOM.sinkBitlessEvent(input, "input");
DOM.setEventListener(input, event -> GWT.log("Event!"));
You can just use addChangeHandler() and onChange, tb.getValue().
I used the following to detect when the value of a textbox changes. Just bare in mind this only detects if the text box goes from empty to full or full to empty. This was done to try reduce async calls to the server to validate the input
#UiHandler("notes")
#SuppressWarnings("unused")
public void notes(KeyUpEvent event) {
if (!areNotesCaptured && !notes.getText().isEmpty()){
fireLeaveSelectionUpdatedEvent();
areNotesCaptured = true;
} else if (areNotesCaptured && notes.getText().isEmpty()){
fireLeaveSelectionUpdatedEvent();
areNotesCaptured = false;
}
}

Handle Window close event

I'm trying to handle the event when the close button of a Window is clicked:
// View Code
#Override
public void attachWindowListener(WindowListener listener) {
window.addWindowListener(listener);
}
// Presenter code
view.attachWindowListener(new WindowListener(){
public void windowHide(WindowEvent we) {
GWT.log("Window Event - Processing fields");
processFields();
}
});
However, the windowHide function seems to be not executed since I can't see the log I placed there.
How to properly handle that event?
How about
Window.addCloseHandler(
new CloseHandler<Window>()
{
public void onClose( CloseEvent<Window> windowCloseEvent )
{
// Do your worst here
}
} );
I usually put this in onModuleLoad() in my EntryPoint class.
Cheers,
Based on the information provided I would guess that either a.) the events you think are firing do not fire for the Window component (even if it seems like they should) or b.) the events are firing but in a different order than you expect.
For example, it's possible that a BrowserEvent or some other event is firing first as the window is being closed and the Window object's WindowEvent never fires. According to the API docs for GXT 2.x, the WindowEvent will fire on hide and deactivate but it does not specify that it fires on close. The GXT 3.0.x API doc is less clear on this point but I would assume the same behavior. Unfortunately Sencha does not provide good documentation on what events fire for a given component and in what order.
With that said, I have had some luck working through similar issues to this by using a debug class which outputs all the events on a component to which it is attached. This may shed some light on which events are firing and their order of execution, and you may find an optimal event to which you can attach your processFields() method.
For a good example of a debugger class, see this answer from a related post: https://stackoverflow.com/a/2891746/460638. It also includes an example of how to attach the debugger to your component.
API Doc for Window, GXT 2.x: http://dev.sencha.com/deploy/gxt-2.2.5/docs/api/com/extjs/gxt/ui/client/widget/Window.html
API Doc for Window, GXT 3.0.x: http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/widget/core/client/Window.html
This worked:
window.addListener(Events.Hide, new Listener<ComponentEvent>() {
#Override
public void handleEvent(ComponentEvent be) {
// Do stuff
}
});

UiHandler doesn't work with SuggestBox SuggestionEvent

I am using a SuggestBox and trying to capture the SuggestionEvent that is fired when the user selects a Suggestion. I can do this with normal event handlers easily enough:
itemInputBox.addEventHandler(new SuggestionHandler() {
#Override
public void onSuggestionSelect(SuggestionEvent event) {
Window.alert(event.getSelectedSuggestion().getReplacementString());
}
});
That works fine, event fires with the correct replacement string. However, I like to use UiHandler whenever possible due to how much cleaner the code is. So I've tried the following:
#UiHandler("itemInputBox")
void onSuggestionSelect(SuggestionEvent event) {
Window.alert(event.getSelectedSuggestion().getReplacementString());
}
But this results in the following errors:
[WARN] [jsonp] - Method 'getAssociatedType()' could not be found in the event 'SuggestionEvent'.
[ERROR] [jsonp] - Parameter 'SuggestionEvent' is not an event (subclass of GwtEvent).
I have a different UiHandler working correctly on the same SuggestBox so I am kind of confused where I'm going wrong:
#UiHandler("itemInputBox")
void onKeyUp(KeyUpEvent event) {
Window.alert("Key up event firing.");
}
I don't understand why one UiHandler fires correctly, while the other results in a error.
SuggestionEvent does not extend GwtEvent instead it extends java.util.EventObject.
This is why it will not work with UiBinder. I will bring this up on the GWT contributer list to see if there is a specific reason for this. Right now I am just guessing that it was forgotten when moving to the new event system.