Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement features for Input text box #7308

Merged
merged 40 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1096ee0
WIP + NEEDTOFIX : text-align
NeylMahfouf2608 Jan 14, 2025
28e578e
small fix on missed return statements (does not change behavior)
NeylMahfouf2608 Jan 14, 2025
65402bd
add form support for input, add padding and text-align support in pix…
NeylMahfouf2608 Jan 19, 2025
5c9debd
forgotten file in last commit
NeylMahfouf2608 Jan 19, 2025
11e623a
Update JsExtension.js
NeylMahfouf2608 Jan 20, 2025
0d50de1
deleted wrong import
NeylMahfouf2608 Jan 20, 2025
925e98f
Merge branch 'improvement-text-input' of https://github.com/4ian/GDev…
NeylMahfouf2608 Jan 20, 2025
908d0a5
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
7e07906
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
ce99c0a
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
c9849cd
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
fb3e8a1
Merge branch 'improvement-text-input' of https://github.com/4ian/GDev…
NeylMahfouf2608 Jan 20, 2025
ea375f4
fixed small issue
NeylMahfouf2608 Jan 20, 2025
9efefa3
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
9898f2a
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
ec48bb4
Update textinputruntimeobject.pixiruntimegamewithassets.spec.js
NeylMahfouf2608 Jan 20, 2025
6e35339
Update JsExtension.js
NeylMahfouf2608 Jan 20, 2025
26c09f8
Update JsExtension.js
NeylMahfouf2608 Jan 20, 2025
8e9b935
Update JsExtension.js
NeylMahfouf2608 Jan 20, 2025
95d508c
Update Extensions/TextInput/JsExtension.js
NeylMahfouf2608 Jan 20, 2025
c5f54e9
Update Extensions/TextInput/JsExtension.js
NeylMahfouf2608 Jan 20, 2025
c2e22d1
move logic from renderer to object
NeylMahfouf2608 Jan 20, 2025
6e86b5c
Update JsExtension.js
NeylMahfouf2608 Jan 20, 2025
4293040
Update JsExtension.js
NeylMahfouf2608 Jan 20, 2025
c62f4fd
update JsExtensions
NeylMahfouf2608 Jan 20, 2025
0fb2efa
update for better maxlength support
NeylMahfouf2608 Jan 21, 2025
3fa2b58
Update JsExtension.js
NeylMahfouf2608 Jan 21, 2025
76a049c
Update JsExtension.js
NeylMahfouf2608 Jan 21, 2025
79b9aa5
Merge branch 'improvement-text-input' of https://github.com/4ian/GDev…
NeylMahfouf2608 Jan 21, 2025
4849017
Update Extensions/TextInput/JsExtension.js
NeylMahfouf2608 Jan 21, 2025
c62f41a
Update textinputruntimeobject-pixi-renderer.ts
NeylMahfouf2608 Jan 21, 2025
7cfa661
Update textinputruntimeobject.ts
NeylMahfouf2608 Jan 21, 2025
399f9b2
Merge branch 'improvement-text-input' of https://github.com/4ian/GDev…
NeylMahfouf2608 Jan 21, 2025
fbddfa5
update typo and setTextAlign function
NeylMahfouf2608 Jan 21, 2025
3a893e8
update for format
NeylMahfouf2608 Jan 21, 2025
b932c91
updated parser and secured types for pading, maxlength ,and textalign…
NeylMahfouf2608 Jan 22, 2025
9c8eecc
padding cannot be < 0
NeylMahfouf2608 Jan 22, 2025
bb175cc
Update Extensions/TextInput/JsExtension.js
NeylMahfouf2608 Jan 22, 2025
184159d
Update Extensions/TextInput/textinputruntimeobject-pixi-renderer.ts
NeylMahfouf2608 Jan 22, 2025
34b6d36
last formatting
NeylMahfouf2608 Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion Extensions/TextInput/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ module.exports = {
} else if (propertyName === 'disabled') {
objectContent.disabled = newValue === '1';
return true;
} else if (propertyName === 'maxLength') {
objectContent.maxLength = newValue;
return true;
} else if (propertyName === 'padding') {
objectContent.padding = newValue;
return true;
} else if (propertyName === 'textAlign') {
objectContent.textAlign = newValue;
return true;
}

return false;
Expand Down Expand Up @@ -200,6 +209,34 @@ module.exports = {
.setLabel(_('Width'))
.setGroup(_('Border appearance'));

objectProperties
.getOrCreate('padding')
.setValue((objectContent.padding || 0).toString())
NeylMahfouf2608 marked this conversation as resolved.
Show resolved Hide resolved
.setType('number')
.setLabel(_('Padding'))
.setGroup(_('Font'));
objectProperties
.getOrCreate('maxLength')
.setValue((objectContent.maxLength || 0).toString())
.setType('number')
.setLabel(_('Max length'))
NeylMahfouf2608 marked this conversation as resolved.
Show resolved Hide resolved
.setDescription(
_(
'The maximum length of the input value. (this property will be ignored if the input type is a number'
NeylMahfouf2608 marked this conversation as resolved.
Show resolved Hide resolved
)
)
.setAdvanced(true);

objectProperties
.getOrCreate('textAlign')
.setValue(objectContent.textAlign || 'left')
.setType('choice')
.addExtraInfo('left')
.addExtraInfo('center')
NeylMahfouf2608 marked this conversation as resolved.
Show resolved Hide resolved
.addExtraInfo('right')
.setLabel(_('Text alignment'))
.setGroup(_('Font'));

return objectProperties;
};
textInputObject.content = {
Expand All @@ -216,6 +253,9 @@ module.exports = {
borderWidth: 1,
readOnly: false,
disabled: false,
padding: 0,
textAlign: 'left',
maxLength: 0,
};

textInputObject.updateInitialInstanceProperty = function (
Expand Down Expand Up @@ -572,6 +612,22 @@ module.exports = {
.getCodeExtraInformation()
.setFunctionName('isFocused');

object
.addScopedCondition(
'IsInputSubmitted',
_('Input is submitted'),
_(
'Check if the input is submitted, which usually happens when the Enter key is pressed on a keyboard, or a specific button on mobile virtual keyboards.'
),
_('_PARAM0_ value was submitted'),
'',
'res/conditions/surObject24.png',
'res/conditions/surObject.png'
)
.addParameter('object', _('Text input'), 'TextInputObject', false)
.getCodeExtraInformation()
.setFunctionName('isSubmitted');

object
.addScopedAction(
'Focus',
Expand Down Expand Up @@ -755,8 +811,23 @@ module.exports = {
this._pixiTextMask.endFill();

const isTextArea = object.content.inputType === 'text area';
const textAlign = object.content.textAlign
? object.content.textAlign
: 'left';
const padding = object.content.padding
? parseFloat(object.content.padding)
: 0;

if (textAlign === 'left')
this._pixiText.position.x = textOffset + padding;
else if (textAlign === 'right')
this._pixiText.position.x =
0 + width - this._pixiText.width - textOffset - padding;
else if (textAlign === 'center') {
this._pixiText.align = 'center';
this._pixiText.position.x = 0 + width / 2 - this._pixiText.width / 2;
}

this._pixiText.position.x = textOffset;
this._pixiText.position.y = isTextArea
? textOffset
: height / 2 - this._pixiText.height / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
borderWidth: 2,
disabled: false,
readOnly: false,
padding: 0,
textAlign: 'left',
maxLength: 20,
},
});

Expand Down Expand Up @@ -166,33 +169,33 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
object,
} = await setupObjectAndGetDomElementContainer();

const inputElement = gameDomElementContainer.querySelector('input');
if (!inputElement) throw new Error('Expected input element to be found');
const formElement = gameDomElementContainer.querySelector('form');
if (!formElement) throw new Error('Expected form element to be found');

// Check visibility of the DOM element is visible by default, if it should be visible
// on the screen.
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('initial');
expect(formElement.style.display).to.be('initial');

// Check visibility of the DOM element is updated at each frame,
// according to the object visibility.
object.hide(true);
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('none');
expect(formElement.style.display).to.be('none');

object.hide(false);
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('initial');
expect(formElement.style.display).to.be('initial');

// Check visibility of the DOM element is updated at each frame,
// according to the layer visibility.
runtimeScene.getLayer('').show(false);
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('none');
expect(formElement.style.display).to.be('none');

runtimeScene.getLayer('').show(true);
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('initial');
expect(formElement.style.display).to.be('initial');

// Clean up - not mandatory but to avoid overloading the testing browser.
runtimeScene.unloadScene();
Expand All @@ -205,31 +208,31 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
object,
} = await setupObjectAndGetDomElementContainer();

const inputElement = gameDomElementContainer.querySelector('input');
if (!inputElement) throw new Error('Expected input element to be found');
const formElement = gameDomElementContainer.querySelector('form');
if (!formElement) throw new Error('Expected input element to be found');

// Check visibility of the DOM element is visible by default, if it should be visible
// on the screen.
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('initial');
expect(formElement.style.display).to.be('initial');

// Check visibility of the DOM element is updated at each frame,
// according to the object position of screen.
object.setX(-500); // -500 + 300 (object default width) = -200, still outside the camera.
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('none');
expect(formElement.style.display).to.be('none');

object.setWidth(600); // -500 + 600 = 100, inside the camera
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('initial');
expect(formElement.style.display).to.be('initial');

runtimeScene.getLayer('').setCameraX(900);
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('none');
expect(formElement.style.display).to.be('none');

runtimeScene.getLayer('').setCameraX(400);
runtimeScene.renderAndStep(1000 / 60);
expect(inputElement.style.display).to.be('initial');
expect(formElement.style.display).to.be('initial');

// Clean up - not mandatory but to avoid overloading the testing browser.
runtimeScene.unloadScene();
Expand Down
Loading
Loading