Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 9 additions & 8 deletions Paper/ElementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,8 @@ private TextInputState LoadTextInputState(string initialValue, bool isMultiLine)
{
var defaultState = new TextInputState
{
Value = initialValue ?? "",
CursorPosition = (initialValue ?? "").Length,
Value = initialValue,
CursorPosition = initialValue.Length,
SelectionStart = -1,
SelectionEnd = -1,
ScrollOffsetX = 0.0,
Expand All @@ -1333,6 +1333,7 @@ private TextInputState LoadTextInputState(string initialValue, bool isMultiLine)
};

var state = _paper.GetElementStorage(_handle, "TextInputState", defaultState);
state.Value = initialValue;
state.IsFocused = _paper.IsElementFocused(_handle.Data.ID);
state.IsMultiLine = isMultiLine; // Ensure consistency
state.ClampValues();
Expand Down Expand Up @@ -1708,7 +1709,7 @@ private bool ProcessKeyCommand(ref TextInputState state, PaperKey key, TextInput
public ElementBuilder TextField(
string value,
TextInputSettings settings,
Action<string> onChange = null,
Action<string> onChange,
[System.Runtime.CompilerServices.CallerLineNumber] int intID = 0)
{
return CreateTextInput(value, settings, onChange, false, intID);
Expand All @@ -1729,7 +1730,7 @@ public ElementBuilder TextField(
public ElementBuilder TextField(
string value,
FontFile font,
Action<string> onChange = null,
Action<string> onChange,
Color? textColor = null,
string placeholder = "",
Color? placeholderColor = null,
Expand All @@ -1755,7 +1756,7 @@ public ElementBuilder TextField(
public ElementBuilder TextArea(
string value,
TextInputSettings settings,
Action<string> onChange = null,
Action<string> onChange,
[System.Runtime.CompilerServices.CallerLineNumber] int intID = 0)
{
return CreateTextInput(value, settings, onChange, true, intID);
Expand All @@ -1776,7 +1777,7 @@ public ElementBuilder TextArea(
public ElementBuilder TextArea(
string value,
FontFile font,
Action<string> onChange = null,
Action<string> onChange,
string placeholder = "",
Color? textColor = null,
Color? placeholderColor = null,
Expand Down Expand Up @@ -1958,7 +1959,7 @@ private ElementBuilder CreateTextInput(
SaveTextInputState(currentState);

if (valueChanged)
onChange?.Invoke(currentState.Value);
onChange.Invoke(currentState.Value);
});

// Handle character input
Expand All @@ -1982,7 +1983,7 @@ private ElementBuilder CreateTextInput(

EnsureCursorVisible(ref currentState, settings, isMultiLine);
SaveTextInputState(currentState);
onChange?.Invoke(currentState.Value);
onChange.Invoke(currentState.Value);
});

// Render cursor and selection
Expand Down
2 changes: 1 addition & 1 deletion Samples/Shared/PaperDemo.Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static void DefineStyles()
.Register();
}

public static ElementBuilder Secondary(string stringID, string value, Action<string> onChange = null, string placeholder = "", int intID = 0, [CallerLineNumber] int lineID = 0)
public static ElementBuilder Secondary(string stringID, string value, Action<string> onChange, string placeholder = "", int intID = 0, [CallerLineNumber] int lineID = 0)
{
ElementBuilder parent = PaperDemo.Gui.Box(stringID, intID, lineID).Style("shadcs-text-field-secondary").TabIndex(0);
using (parent.Enter())
Expand Down