Sticky button in GWT - user-interface

can i create a button in gwt that onClick stays pressed and if it looks pressed onClick releases it?
and the button has a different styles in each state?
any idea?

That sounds like a ToggleButton.

This is a pretty basic approach that should give you the toggle that you want. Basically the first click will put a 'clicked style' that you've created that will give the thing the look you want for when it looks pressed. Clicking it a second time will revert back to your normal button style so it will look not pressed again.
final Button button = new Button();
button.setStyleName("NormalButtonStyle");
button.addClickHandler( new ClickHandler() {
private boolean clickedStyle = false;
public void onClick( final ClickEvent clickEvent ){
clickedStyle = !clickedStyle;
if( clickedStyle ){
button.setStyleName("ClickedButtonStyle");
}
else {
button.setStyleName("NormalButtonStyle");
}
}
});

Related

Why is my JavaFx animation moving further to the right each time the button is pressed?

I am trying to make an animation where a text field an some buttons appear when I press a toggle button, and when I press the toggle button again, it disappears. I have almost succeeded in, but each time I press the toggle button, the toggle menu moves further and further to the right. I'm not that good at explaining, but I made a little gif so you can see. https://gyazo.com/1bd43a95ec988edbce47704674c46418
Hope someone can help me! It is in the method called "routeBtnAction"
The animation method
#FXML
private void routeBtnAction(){
if (routeBtn.isSelected()) {
searchbar.setPromptText("From");
TranslateTransition slideIn = new TranslateTransition();
slideIn.setDuration(Duration.millis(250));
slideIn.setCycleCount(1);
slideIn.setNode(routeMenu);
slideIn.setByX(173);
slideIn.setInterpolator(Interpolator.EASE_OUT);
slideIn.play();
} else {
searchbar.setPromptText("Search");
TranslateTransition slideOut = new TranslateTransition();
slideOut.setDuration(Duration.millis(300));
slideOut.setCycleCount(1);
slideOut.setNode(routeMenu);
slideOut.setByX(-routeMenu.getWidth());
slideOut.setInterpolator(Interpolator.EASE_IN);
slideOut.play();
}
}
I found out. It's supposed to be setToX, not setByX! :)

Navigation back between two fragment xamarin android

MainActivity
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu_white_24dp);
ActionBar.SetDisplayHomeAsUpEnabled (true);
drawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawer_layout);
navigationView = FindViewById<NavigationView> (Resource.Id.nav_view);
Event click on navigatonView
CreateFragments();
LoadInditialFragment ();
navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
Onefragment
Twofragment
Navigation back from second Fragment to first fragment(navigation back on toolbar).??? MainActivity I have a button menu on toolbar.
I want to replace menu icon into back icon when It is standing at second fragment.
Download back arrow and save as navBack.png
Then in SwitchFragment method where we navigate between fragments
switch (FragmentId) {
case Resource.Id.nav_home:
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu_white_24dp);
transaction.Show (homeFragment);
transaction.Commit ();
break;
case Resource.Id.nav_genre:
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.navBack);
transaction.Show (genresFragment);
transaction.Commit ();
break;
}
In Your MainActivity do this in OnCreate:
SupportFragmentManager.BackStackChanged += HandleBackstackChanged;
Implement the HandleBackstackChanged method like this
private void HandleBackstackChanged(object sender, EventArgs e)
{
ActionBar.SetDisplayHomeAsUpEnabled (SupportFragmentManager.BackStackEntryCount > 0);
}
What this will do is toggle between the Menu button and the Back button based on the BackStack count of the FragmentManager.
NOTE:
I am assuming you are using the Support library for backwards compatibility of Fragments. If you aren't using the support library, just use FragmentManger instead of SupportFragmentManager.

New UI Button misunderstood pointer click and pointer down action

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.

back button handling wp7

My problem is that I have a list. When I long press a particular item in the list then it opens a context menu and when I click on a menu item inside context menu then it opens a popup,so on pressing the hardware back button i want that i again go back to the list.
so for doing this my code is:
protected override void OnBackKeyPress(object sender,System.ComponentModel.CancelEventArgs e)
{
if (calendarDescripton.Visibility == Visibility.Visible)
{
calendarDescripton.Visibility = Visibility.Collapsed;
e.Cancel = true;
}
}
After using this code when I click the button that opens the list,the application exits,it does not open list also.
I think first the Navigation should be canceled, before making any other changes. Try this
protected override void OnBackKeyPress(object sender,System.ComponentModel.CancelEventArgs e)
{
if (calendarDescripton.Visibility == Visibility.Visible)
{
e.Cancel = true;
calendarDescripton.Visibility = Visibility.Collapsed;
}
}
If this doesn't help, place a break piont at the if condition and check if it is entering inside the if or not
If the break point doesn't hit, means there is something wrong with your Navigation approach.
If you are using NavigationService.Navigate() method for page navigation, it should work.
Otherwise, if you are using,
App.Current.RootVisual = new MyPage();, then BackKey cannot be overridden.

How to handle back button in windows phone 7?

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.

Resources