fix for issue #12

This commit is contained in:
sojamo 2015-07-30 10:59:52 +08:00
parent 096c553452
commit 12235cb462
5 changed files with 36 additions and 28 deletions

View File

@ -35,7 +35,7 @@ To get started, here a simple example that demonstrates how to create a slider a
![example 1](resources/images/cp5-example-1_s.png) ![example 1](./resources/images/cp5-example-1_s.png)
_example 1, see code below_ _example 1, see code below_

View File

@ -124,7 +124,6 @@ public class Button extends Controller< Button > {
isActive = false; isActive = false;
isOn = !isOn; isOn = !isOn;
setValue( _myValue ); setValue( _myValue );
} }
} }

View File

@ -294,7 +294,7 @@ public class ControlP5Legacy {
public ScrollableList addScrollableList( final Object theObject , String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) { public ScrollableList addScrollableList( final Object theObject , String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) {
ScrollableList myController = new ScrollableList( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH ); ScrollableList myController = new ScrollableList( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController ); base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "listBoxItems" ).registerProperty( "value" ); myController.registerProperty( "items" ).registerProperty( "value" );
return myController; return myController;
} }

View File

@ -695,6 +695,7 @@ public abstract class Controller< T > implements ControllerInterface< T > , CDra
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_LEAVE ) ); cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_LEAVE ) );
_myControlWindow.removeMouseOverFor( this ); _myControlWindow.removeMouseOverFor( this );
cp5.getTooltip( ).deactivate( ); cp5.getTooltip( ).deactivate( );
setIsInside( false ); /* added after issue 6 has been reported */
} }
return me; return me;
} }

View File

@ -134,23 +134,28 @@ public class ScrollableList extends Controller< ScrollableList > implements Cont
// n += itemRange; /* UP */ // n += itemRange; /* UP */
int index = ( int ) n + itemIndexOffset; int index = ( int ) n + itemIndexOffset;
updateIndex( index );
}
}
}
if ( index >= items.size( ) ) { private void updateIndex( int theIndex ) {
if ( theIndex >= items.size( ) ) {
return; return;
} }
Map m = items.get( index ); Map m = items.get( theIndex );
switch ( _myType ) { switch ( _myType ) {
case ( LIST ): case ( LIST ):
setValue( index ); super.setValue( theIndex );
for ( Object o : items ) { for ( Object o : items ) {
( ( Map ) o ).put( "state" , false ); ( ( Map ) o ).put( "state" , false );
} }
m.put( "state" , !ControlP5.b( m.get( "state" ) ) ); m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break; break;
case ( DROPDOWN ): case ( DROPDOWN ):
setValue( index ); super.setValue( theIndex );
setOpen( false ); setOpen( false );
getCaptionLabel( ).setText( ( m.get( "text" ).toString( ) ) ); getCaptionLabel( ).setText( ( m.get( "text" ).toString( ) ) );
break; break;
@ -160,7 +165,10 @@ public class ScrollableList extends Controller< ScrollableList > implements Cont
} }
} }
}
public ScrollableList setValue( float theValue ) {
updateIndex( ( int ) ( theValue ) );
return this;
} }
@Override protected void onDrag( ) { @Override protected void onDrag( ) {