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_

View File

@ -124,7 +124,6 @@ public class Button extends Controller< Button > {
isActive = false;
isOn = !isOn;
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 ) {
ScrollableList myController = new ScrollableList( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "listBoxItems" ).registerProperty( "value" );
myController.registerProperty( "items" ).registerProperty( "value" );
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 ) );
_myControlWindow.removeMouseOverFor( this );
cp5.getTooltip( ).deactivate( );
setIsInside( false ); /* added after issue 6 has been reported */
}
return me;
}

View File

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