I'm trying to implement a button action that displays text on my ScrollLayer when the Select button is pressed. I used:
scroll_layer_set_click_config_onto_window(scrollLayer, window);
to set the BUTTON_UP and BUTTON_DOWN callback functions automatically (to scroll). So then I want to set a BUTTON_SELECT callback function. I wrote these two functions:
//Performs an action whenver the 'select' button is pressed
void select_click_handler(ClickRecognizerRef recognizer, void *ctx) {
text_layer_set_text(textLayer, "You pressed select");
}
//Links the select button to a function, select_click_handler
void click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
}
And in my initializer I have:
void init() {
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
window_set_click_config_provider(window, click_config_provider);
window_stack_push(window,true);
}
When I run this, it compiles and installs on the watch just fine, however, when I hit the select button, nothing happens. When I comment out scroll_layer_set_click_config_onto_window(scrollLayer, window);
it works like it is supposed to.
Is there a way to override the select button callback without having to comment out the above line?
Thanks in advance!
I found a simple workaround using scroll_layer_set_callbacks() function here:
http://forums.getpebble.com/discussion/11432/scroll-layer-set-callbacks
Now you can find it in Pebble official document(SDK 2.0).
ScrollLayer // Pebble Developers
http://developer.getpebble.com/docs/c/User_Interface/Layers/ScrollLayer/
The SELECT button can be configured by installing a click configuration provider using scroll_layer_set_callbacks().
Related
Is there any way to detect the press of the back button of the Navigation Page in Xamarin forms?
You can override your navigation page "OnBackButtonPressed" method:
protected override bool OnBackButtonPressed()
{
Device.BeginInvokeOnMainThread(async () =>
{
if (await DisplayAlert("Exit?", "Are you sure you want to exit from this page?", "Yes", "No"))
{
base.OnBackButtonPressed();
await App.Navigation.PopAsync();
}
});
return true;
}
If you are using the shell, you can override the Shell's OnNavigating event:
void OnNavigating(object sender, ShellNavigatingEventArgs e)
{
// Cancel back navigation if data is unsaved
if (e.Source == ShellNavigationSource.Pop && !dataSaved)
{
e.Cancel();
}
}
Update:
OnBackButtonPressed event will get fired ONLY on Android when user press the Hardware back button.
Seems like you are more interested to implement when any page get disappeared you want to do something!
In that case:
You have the page's two methods -
protected override void OnAppearing()
{
base.OnAppearing();
Console.WriteLine("Hey, Im coming to your screen");
}
protected override void OnDisappearing()
{
base.OnDisappearing();
Console.WriteLine("Hey, Im going from your screen");
}
You can override those 2 methods on any page to track when they appear and disappear.
Recent updates to Xamarin forms mean you can now do this in an application made with Shell Navigation for navigation back arrow on both platforms.
Use the Shell.SetBackButtonBehavior method, for example running this code in the constructor of your page object will allow the back navigation to take place only when the bound viewmodel is not busy:
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
Command = new Command(async() =>
{
if (ViewModel.IsNotBusy)
{
await Shell.Current.Navigation.PopAsync();
}
})
});
In the body of the Command you can do whatever you need to do when you are intercepting the click of the back button.
Note that this will affect only the navigation back button, not the Android hardware back button - that will need handling separately as per the answers above. You could write a shared method called from both the back button pressed override and the command on shell back button behaviour places to share the logic.
You must override native navigationbar button behavior with custom renderer. OnBackButtonPressed triggers only physical device button. You can read good article how to achive this here
So I'm trying to make an event happen with buttons in xcode, and it's working fine, and executing the way I want it to, but now I want a different section of code to run if the button is not being pushed. I don't know how to test for if a button is NOT being pushed. Any ideas?
While a NSButton is pressed its state is non-zero.
if (myButton.state) {
// My button is pushed!
}
Here's something that can help you. Define a var ,notPushed whose value can be checked to see if button is called or not.
var notPushed:Bool=true
#IBAction func buttonPressed(sender:UIButton)
{
//....
notPushed=false
}
To check wether the button is pressed :
if notPushed==true{
//...
} else {
//...
}
Link your button to the buttonPressed.
I am making a game with ui controller. i use button to make that controller.
in the picture, i have "A" button. when my "character" facing npc, i want to talk with that npc with click that button. when dialogue is over, i need to close the dialogue box using this button too.
but what i got is, this button clicked over and over, so the first dialogue is skipped, and the dialogue which is showed up is the third or maybe the fourth dialog.
i attach event trigger on this button.
and this is my code that is attached on that event trigger
using UnityEngine;
using System.Collections;
public class aButtonScript : MonoBehaviour {
void Start(){
}
public void click(){
if(walkingScript.walking.interact == true)
{
loadGame.loadSave.objPrince.GetComponent<plantingScript>().aButton = false;
loadGame.loadSave.objPrince.GetComponent<walkingScript>().aButton = true;
}
}
public void clicked()
{
if(plantingScript.planting.toolBoxCanvas != null)
{
loadGame.loadSave.objPrince.GetComponent<plantingScript>().aButton = false;
choosingTools.ct.setTool();
}
}
public void unclicked()
{
loadGame.loadSave.objPrince.GetComponent<plantingScript>().aButton = false;
}
}
well, this is my first time making a game. hope whoever who read this question can help me. sorry for my bad english. thank you.
Not quite sure, but I've had similar problems when using GetMouseButton instead of GetMouseButtonDown. The first one triggers for each frame the button is pressed. Looking at your UI setup it seems you acivate the script when the button is pressed, for each frame it is pressed, and finally when it is released.
I'm developing an MFC application dedicated to Windows 7 GUI on visual studio 2013. What I've done so far is I've added Main Item and Button into Application Button by getting some help from http://msdn.microsoft.com/en-us/library/ee354414.aspx as you can see in below image.Now, I want to know that how can I add Event Handler into it.
Sorry, I'm giving answer of my own question.I've done this by adding few line of code show below.In MainFrm.h I've declare two public method
afx_msg void OnMainItemKasim();
afx_msg void OnButtonKasim();
In MainFrm.cpp. Define empty stub of both method
void CMainFrame::OnMainItemKasim()
{
// TODO: Add your command handler code here
}
void CMainFrame::OnButtonKasim()
{
// TODO: Add your command handler code here
}
finally, write following lines in BEGIN_MESSAGE_MAP
ON_COMMAND(ID_FILE_KASIM, &CMainFrame::OnMainItemKasim)
ON_COMMAND(ID_APP_KASIM, &CMainFrame::OnButtonKasim)
where, ID_FILE_KASIM is Main Item below Save As & ID_APP_KASIM is button next to Exit button
finally it looks like this
I have an application, the main page contains few functions. To explain in detail - I have save, color palette button in my main page. When any of these buttons are clicked, save pop up or color palette appears. How to handle back button of the device, when color palette or save pop up is opened. When back button is pressed at these scenario it should just make them invisible and stay on the main page. When nothing is being performed in the main page, then it should come out of the app. I tried to make their visibility collapsed on back button press. But it still is coming out of the application.
Please, guide me in this. Thanks in advance.
Override PhoneApplicationPage.OnBackKeyPress and then set CancelEventArgs.Cancel to true if you want to stop it from actually going back.
protected override void OnBackKeyPress(CancelEventArgs args)
{
if (PanelIsShowing)
{
HidePanel();
args.Cancel = true;
}
}
The back button behaves as is intended by Microsoft.
If you change its behavior you risk your application not being certified for the Marketplace.
If you want the back button to close the popups, turn the popups into pages so the back button navigates back to the main page..
You need to use
protected override void OnBackKeyPress(CancelEventArgs e)
{
if (_popup.IsOpen)
{
_popup.IsOpen= false;
e.Cancel = true;
}
else
{
base.OnBackKeyPress(e);
}
}
That should do the trick.