Skip to content

Commit

Permalink
fixed small issue
Browse files Browse the repository at this point in the history
  • Loading branch information
NeylMahfouf2608 committed Jan 20, 2025
1 parent fb3e8a1 commit ea375f4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 54 deletions.
71 changes: 33 additions & 38 deletions Extensions/TextInput/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,13 @@ module.exports = {
} else if (propertyName === 'disabled') {
objectContent.disabled = newValue === '1';
return true;
}
else if(propertyName === 'maxLength')
{
} else if (propertyName === 'maxLength') {
objectContent.maxLength = newValue;
return true;
}
else if (propertyName === 'padding')
{
} else if (propertyName === 'padding') {
objectContent.padding = newValue;
return true;
}
else if(propertyName === 'textAlign')
{
} else if (propertyName === 'textAlign') {
objectContent.textAlign = newValue;
return true;
}
Expand Down Expand Up @@ -215,21 +209,21 @@ module.exports = {
.setLabel(_('Width'))
.setGroup(_('Border appearance'));

objectProperties
objectProperties
.getOrCreate('padding')
.setValue((objectContent.padding || 0).toString())
.setType('number')
.setLabel(_('Padding'))
.setGroup(_('Border appearance'));

objectProperties
objectProperties
.getOrCreate('maxLength')
.setValue(objectContent.maxLength || 20)
.setType('number')
.setLabel(_('Max length'))
.setGroup(_('Border appearance'));

objectProperties
objectProperties
.getOrCreate('textAlign')
.setValue(objectContent.textAlign || 'left')
.setType('choice')
Expand Down Expand Up @@ -313,6 +307,7 @@ module.exports = {
// Properties expressions/conditions/actions:

// Deprecated, see TextContainerCapability

object
.addExpressionAndConditionAndAction(
'string',
Expand Down Expand Up @@ -614,21 +609,22 @@ module.exports = {
.getCodeExtraInformation()
.setFunctionName('isFocused');

object.addScopedCondition(
'IsInputSubmitted',
_('Input is Submitted (Enter pressed'),
_(
'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_ got input submitted'),
'',
'res/conditions/surObject24.png',
'res/conditions/surObject.png'
)
.addParameter('object', _('Text input'), 'TextInputObject',false)
.getCodeExtraInformation()
.setFunctionName('isSubmitted');

object
.addScopedCondition(
'IsInputSubmitted',
_('Input is Submitted (Enter pressed'),
_(
'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_ got input 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 @@ -800,7 +796,7 @@ module.exports = {
const borderWidth = object.content.borderWidth || 0;

// Draw the mask for the text.
const textOffset = borderWidth + TEXT_MASK_PADDING;// + object.content.padding;
const textOffset = borderWidth + TEXT_MASK_PADDING; // + object.content.padding;
this._pixiTextMask.clear();
this._pixiTextMask.beginFill(0xdddddd, 1);
this._pixiTextMask.drawRect(
Expand All @@ -814,16 +810,15 @@ module.exports = {
const isTextArea = object.content.inputType === 'text area';
const textAlign = object.content.textAlign;
console.log(this._pixiText.width);
if(textAlign === 'left')
this._pixiText.position.x = 0;
else if(textAlign === 'right')
this._pixiText.position.x = 0 + width - this._pixiText.width - textOffset;
else if (textAlign === 'center')
{
this._pixiText.align = 'center';
this._pixiText.position.x = 0 + width/2 - this._pixiText.width/2;
}

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

this._pixiText.position.y = isTextArea
? textOffset
: height / 2 - this._pixiText.height / 2;
Expand Down
28 changes: 12 additions & 16 deletions Extensions/TextInput/textinputruntimeobject-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ namespace gdjs {
search: 'search',
};

const userFriendlyToHtmlAlignement =
{
const userFriendlyToHtmlAlignement = {
left: 'left',
center: 'center',
right: 'right',
}
};

const formatRgbAndOpacityToCssRgba = (
rgbColor: [float, float, float],
Expand All @@ -33,7 +32,6 @@ namespace gdjs {
);
};


class TextInputRuntimeObjectPixiRenderer {
private _object: gdjs.TextInputRuntimeObject;
private _input: HTMLInputElement | HTMLTextAreaElement | null = null;
Expand Down Expand Up @@ -95,7 +93,7 @@ namespace gdjs {
this._form.addEventListener('submit', (event) => {
event.preventDefault();
this._isSubmited = true;
})
});

this.updateString();
this.updateFont();
Expand Down Expand Up @@ -245,9 +243,9 @@ namespace gdjs {
this._form.style.height = heightInContainer + 'px';
this._form.style.transform =
'rotate3d(0,0,1,' + (this._object.getAngle() % 360) + 'deg)';
this._form.style.display = 'initial';
this._form.style.padding = this._object.getPadding() + 'px';
this._form.style.textAlign = this._object.getTextAlign();
this._form.style.display = 'initial';
this._form.style.padding = this._object.getPadding() + 'px';
this._form.style.textAlign = this._object.getTextAlign();

// Automatically adjust the font size to follow the game scale.
this._form.style.fontSize =
Expand Down Expand Up @@ -312,7 +310,6 @@ namespace gdjs {
this._object._getRawFillColor(),
this._object.getFillOpacity()
);

}

updateBorderColorAndOpacity() {
Expand Down Expand Up @@ -340,29 +337,29 @@ namespace gdjs {
}

updateMaxLength() {
if(!this._input) return;
if (!this._input) return;

this._input.maxLength = this._object.getMaxLength();
}

updatePadding() {
if(!this._input) return;
if (!this._input) return;

this._input.style.padding = this._object.getPadding() + 'px';
}

updateTextAlign() {
if (!this._input) return;

const newTextAlign = userFriendlyToHtmlAlignement[this._object.getTextAlign()] || 'left';
const newTextAlign =
userFriendlyToHtmlAlignement[this._object.getTextAlign()] || 'left';
this._input.style.textAlign = newTextAlign;
}

isFocused() {
return this._input === document.activeElement;
}
getSubmitted()
{
getSubmitted() {
return this._isSubmited;
}

Expand All @@ -374,5 +371,4 @@ namespace gdjs {
}
export const TextInputRuntimeObjectRenderer = TextInputRuntimeObjectPixiRenderer;
export type TextInputRuntimeObjectRenderer = TextInputRuntimeObjectPixiRenderer;

}

0 comments on commit ea375f4

Please sign in to comment.