Skip to content

Commit

Permalink
[merge] Merged PR #2 from WebFreak001
Browse files Browse the repository at this point in the history
[add] Added passwordChar property to LineInputWidget.
  • Loading branch information
WebFreak001 authored and KanzakiKino committed Aug 12, 2018
1 parent e116529 commit e962ca7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
19 changes: 19 additions & 0 deletions example/demo/src/widget/root.d
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ class DemoRootWidget : RootWidget
input2.lock();
line.addChild( input2 );
}
{
auto line = new PanelWidget;
line.setLayout!HorizontalMonospacedSplitLayout;
page.addChild( line );

auto input1 = new LineInputWidget;
input1.style.box.margins = Rect(1.mm); // TODO
input1.loadText( "password - LineInputWidget"d, face );
input1.passwordChar = '*';
line.addChild( input1 );

auto input2 = new LineInputWidget;
input2.style.box.margins = Rect(1.mm); // TODO
input2.loadText( input1.text, face );
input2.lock();
line.addChild( input2 );

input1.onTextChange = ((input2) => (dstring text) { input2.loadText(text); })(input2);
}
{
auto line = new PanelWidget;
line.setLayout!HorizontalSplitLayout;
Expand Down
12 changes: 10 additions & 2 deletions src/w4d/widget/input/line.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import g4d.element.shape.rect,
g4d.shader.base;
import std.algorithm,
std.conv,
std.math;
std.math,
std.range;

alias TextChangeHandler = EventHandler!( void, dstring );

Expand All @@ -28,6 +29,7 @@ class LineInputWidget : TextWidget
protected float _cursorPos;
protected float _scrollLength;
protected float _selectionLength;
protected dchar _passwordChar;

protected RectElement _cursorElm;
protected RectElement _selectionElm;
Expand Down Expand Up @@ -188,7 +190,7 @@ class LineInputWidget : TextWidget

override void loadText ( dstring v, FontFace font = null )
{
super.loadText( v, font );
super.loadText( isPasswordField ? passwordChar.repeat(v.length).to!dstring : v, font );

_line.setText( v );
onTextChange.call( v );
Expand Down Expand Up @@ -284,4 +286,10 @@ class LineInputWidget : TextWidget

override @property bool trackable () { return true; }
override @property bool focusable () { return true; }

@property auto passwordChar () const { return _passwordChar; }
@property void passwordChar (dchar c) { _passwordChar = c; loadText(text); }
@property auto isPasswordField () const { return _passwordChar != dchar.init; }

override @property dstring text () { return _line.text; }
}
4 changes: 2 additions & 2 deletions src/w4d/widget/text.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TextWidget : Widget

@property ref textOriginRate () { return _textElm.originRate; }

@property text () { return _text; }
@property font () { return _font; }
@property dstring text () { return _text; }
@property FontFace font () { return _font; }

vec2 textPosRate;

Expand Down

0 comments on commit e962ca7

Please sign in to comment.