mirror of
https://github.com/sojamo/controlp5
synced 2024-12-23 03:33:49 +01:00
Changed behavior of the delete key
Added click selection support for Textfields
This commit is contained in:
parent
1f7cb64986
commit
2e47b179cf
@ -843,7 +843,7 @@ public final class ControlWindow {
|
|||||||
_myApplet.frame.removeNotify( );
|
_myApplet.frame.removeNotify( );
|
||||||
_myApplet.frame.setUndecorated( isUndecorated );
|
_myApplet.frame.setUndecorated( isUndecorated );
|
||||||
_myApplet.setSize( _myApplet.width , _myApplet.height );
|
_myApplet.setSize( _myApplet.width , _myApplet.height );
|
||||||
_myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height );
|
//_myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height );
|
||||||
_myApplet.frame.setSize( _myApplet.width , _myApplet.height );
|
_myApplet.frame.setSize( _myApplet.width , _myApplet.height );
|
||||||
_myApplet.frame.addNotify( );
|
_myApplet.frame.addNotify( );
|
||||||
}
|
}
|
||||||
|
@ -134,8 +134,8 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
keyMapping = new HashMap< Integer , TextfieldCommand >( );
|
keyMapping = new HashMap< Integer , TextfieldCommand >( );
|
||||||
keyMapping.put( ENTER , new Enter( ) );
|
keyMapping.put( ENTER , new Enter( ) );
|
||||||
keyMapping.put( DEFAULT , new InsertCharacter( ) );
|
keyMapping.put( DEFAULT , new InsertCharacter( ) );
|
||||||
keyMapping.put( DELETE , new DeleteCharacter( ) );
|
keyMapping.put( DELETE , new DeleteCharacterRight( ) );
|
||||||
keyMapping.put( BACKSPACE , new DeleteCharacter( ) );
|
keyMapping.put( BACKSPACE , new DeleteCharacterLeft( ) );
|
||||||
keyMapping.put( LEFT , new MoveLeft( ) );
|
keyMapping.put( LEFT , new MoveLeft( ) );
|
||||||
keyMapping.put( RIGHT , new MoveRight( ) );
|
keyMapping.put( RIGHT , new MoveRight( ) );
|
||||||
keyMapping.put( UP , new MoveUp( ) );
|
keyMapping.put( UP , new MoveUp( ) );
|
||||||
@ -261,11 +261,27 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
@Override protected void mousePressed( ) {
|
@Override protected void mousePressed( ) {
|
||||||
if ( isActive ) {
|
if ( isActive ) {
|
||||||
// TODO System.out.println("adjust cursor");
|
// TODO System.out.println("adjust cursor");
|
||||||
|
// Multiline not supported
|
||||||
}
|
}
|
||||||
int x = ( int ) ( getControlWindow( ).mouseX - x( getAbsolutePosition( ) ) );
|
int x = ( int ) ( getControlWindow( ).mouseX - x( getPosition( ) ) );
|
||||||
int y = ( int ) ( getControlWindow( ).mouseY - y( getAbsolutePosition( ) ) );
|
int y = ( int ) ( getControlWindow( ).mouseY - y( getPosition( ) ) );
|
||||||
|
|
||||||
// TODO System.out.println(x + ":" + y);
|
int i = 0;
|
||||||
|
int textWidth;
|
||||||
|
for(i = 0 ; i <= _myTextBuffer.length() ; i++) {
|
||||||
|
textWidth = ControlFont.getWidthFor( _myTextBuffer.substring( 0 , i ) , _myValueLabel , buffer );
|
||||||
|
if(textWidth > x) {
|
||||||
|
if(i != 0 && textWidth-x > ControlFont.getWidthFor( _myTextBuffer.substring( i-1 , i ) , _myValueLabel , buffer )/2) {
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i > _myTextBuffer.length())
|
||||||
|
i = _myTextBuffer.length();
|
||||||
|
|
||||||
|
setIndex(i);
|
||||||
|
|
||||||
setFocus( true );
|
setFocus( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +440,7 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeleteCharacter implements TextfieldCommand {
|
class DeleteCharacterLeft implements TextfieldCommand {
|
||||||
|
|
||||||
public void execute( ) {
|
public void execute( ) {
|
||||||
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex > 0 ) {
|
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex > 0 ) {
|
||||||
@ -434,6 +450,16 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeleteCharacterRight implements TextfieldCommand {
|
||||||
|
|
||||||
|
public void execute( ) {
|
||||||
|
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex < _myTextBuffer.length( ) ) {
|
||||||
|
_myTextBuffer.deleteCharAt( _myTextBufferIndex );
|
||||||
|
setIndex( _myTextBufferIndex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MoveLeft implements TextfieldCommand {
|
class MoveLeft implements TextfieldCommand {
|
||||||
|
|
||||||
public void execute( ) {
|
public void execute( ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user