Skip to content

Commit 2614db4

Browse files
committed
feat(lineinput): add secret field
1 parent 7859a48 commit 2614db4

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

SharpEngine.Core/Widget/LineInput.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ namespace SharpEngine.Core.Widget;
1818
/// <param name="font">Line Edit Font ("")</param>
1919
/// <param name="size">Line Edit Size (Vec2(300, 50))</param>
2020
/// <param name="fontSize">Line Edit Font Size (null)</param>
21+
/// <param name="secret">If Line Edit is Secret (false)</param>
2122
/// <param name="zLayer">Z Layer</param>
2223
public class LineInput(
2324
Vec2 position,
2425
string text = "",
2526
string font = "",
2627
Vec2? size = null,
2728
int? fontSize = null,
29+
bool secret = false,
2830
int zLayer = 0
2931
) : Widget(position, zLayer)
3032
{
@@ -53,6 +55,11 @@ public class LineInput(
5355
/// </summary>
5456
public int? FontSize { get; set; } = fontSize;
5557

58+
/// <summary>
59+
/// If Line Input is Secret
60+
/// </summary>
61+
public bool Secret { get; set; } = secret;
62+
5663
/// <summary>
5764
/// Event trigger when value is changed
5865
/// </summary>
@@ -145,11 +152,12 @@ public override void Draw()
145152
if (Font.Length <= 0 || finalFont == null)
146153
return;
147154

155+
var text = Secret ? new string('*', Text.Length) : Text;
148156
var finalFontSize = FontSize ?? finalFont.Value.BaseSize;
149-
var textSize = Raylib.MeasureTextEx(finalFont.Value, Text, finalFontSize, 2);
157+
var textSize = Raylib.MeasureTextEx(finalFont.Value, text, finalFontSize, 2);
150158
var offset = textSize.X - (Size.X - 20);
151159

152-
if (Text.Length > 0)
160+
if (text.Length > 0)
153161
{
154162
var finalPosition = new Vec2(RealPosition.X - Size.X / 2 + 4, RealPosition.Y - textSize.Y / 2);
155163

@@ -164,7 +172,7 @@ public override void Draw()
164172
{
165173
SERender.DrawText(
166174
finalFont.Value,
167-
Text,
175+
text,
168176
new Vec2(finalPosition.X - (offset > 0 ? offset : 0), finalPosition.Y),
169177
finalFontSize,
170178
2,

SharpEngine.Core/Widget/MultiLineInput.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using SharpEngine.Core.Utils.EventArgs;
88
using MouseButton = SharpEngine.Core.Input.MouseButton;
99
using Color = SharpEngine.Core.Utils.Color;
10+
using Microsoft.Win32.SafeHandles;
1011

1112
namespace SharpEngine.Core.Widget;
1213

@@ -18,15 +19,17 @@ namespace SharpEngine.Core.Widget;
1819
/// <param name="font">Multi Line Edit Font ("")</param>
1920
/// <param name="size">Multi Line Edit Size (Vec2(500, 200))</param>
2021
/// <param name="fontSize">Multi Line Edit Font Size (null)</param>
22+
/// <param name="secret">If Multi Line Edit is Secret (false)</param>
2123
/// <param name="zLayer">Z Layer</param>
2224
public class MultiLineInput(
2325
Vec2 position,
2426
string text = "",
2527
string font = "",
2628
Vec2? size = null,
2729
int? fontSize = null,
30+
bool secret = false,
2831
int zLayer = 0
29-
) : LineInput(position, text, font, size, fontSize, zLayer)
32+
) : LineInput(position, text, font, size, fontSize, secret, zLayer)
3033
{
3134
/// <inheritdoc />
3235
public override void Update(float delta)
@@ -112,18 +115,19 @@ public override void Draw()
112115
);
113116
}
114117

115-
private static void DrawLines(Font finalFont, int finalFontSize, Vec2 finalPosition, string[] lines, float offsetX, float offsetY)
118+
private void DrawLines(Font finalFont, int finalFontSize, Vec2 finalPosition, string[] lines, float offsetX, float offsetY)
116119
{
117120
for (var i = 0; i < lines.Length; i++)
118121
{
119-
var lineSize = Raylib.MeasureTextEx(finalFont, lines[i], finalFontSize, 2);
122+
var text = Secret ? new string('*', lines[i].Length) : lines[i];
123+
var lineSize = Raylib.MeasureTextEx(finalFont, text, finalFontSize, 2);
120124
var pos = new Vec2(
121125
finalPosition.X - (offsetX > 0 ? offsetX : 0),
122126
finalPosition.Y + i * lineSize.Y - (offsetY > 0 ? offsetY : 0)
123127
);
124128
SERender.DrawText(
125129
finalFont,
126-
lines[i],
130+
text,
127131
pos,
128132
finalFontSize,
129133
2,

0 commit comments

Comments
 (0)