CrabUI
Loading...
Searching...
No Matches
CrabUI.CUITextInput Class Reference

Text input. More...

Inheritance diagram for CrabUI.CUITextInput:
CrabUI.CUIComponent CrabUI.ICUIComponent CrabUI.ISimpleProps CrabUI.IListProps CrabUI.ISerializationProps

Public Member Functions

void ReceiveSpecialInput (Keys key)
 From IKeyboardSubscriber, don't use it directly.
 
void ReceiveTextInput (char inputChar)
 From IKeyboardSubscriber, don't use it directly.
 
void ReceiveTextInput (string text)
 From IKeyboardSubscriber, don't use it directly.
 
void ReceiveCommandInput (char command)
 From IKeyboardSubscriber, don't use it directly.
 
void ReceiveEditingInput (string text, int start, int length)
 From IKeyboardSubscriber, don't use it directly.
 
void SelectAll ()
 
void Copy ()
 
void Paste ()
 
void AddText (string text)
 
void MoveLeft ()
 
void MoveRight ()
 
void Back ()
 
void Delete ()
 
void CutSelection ()
 
bool IsValidText (string text)
 
void Select (int start, int end)
 
void UpdateBorderColor ()
 
override void Draw (SpriteBatch spriteBatch)
 Here component should be drawn.
 
 CUITextInput (string text)
 
- Public Member Functions inherited from CrabUI.CUIComponent
void AddAnimation (string name, CUIAnimation animation)
 
void BlockChildrenAnimations ()
 
void AttachTo (Item item, Action< Item, CUIComponent > callback=null)
 
void AddCommand (string name, Action< object > action)
 Manually adds command.
 
void RemoveCommand (string name)
 
void DispatchUp (CUICommand command)
 Dispathes command up the component tree until someone consumes it.
 
void DispatchDown (CUIData data)
 Dispathes command down the component tree until someone consumes it.
 
void Execute (CUICommand command)
 Will execute action corresponding to this command.
 
virtual partial void DrawFront (SpriteBatch spriteBatch)
 Method for drawing something that should always be on top, e.g. resize handles.
 
virtual partial void DrawFront (SpriteBatch spriteBatch)
 
 CUIComponent (float? x=null, float? y=null, float? w=null, float? h=null)
 
void Dispose ()
 
virtual void CleanUp ()
 
override string ToString ()
 
void PrintTree (string offset="")
 
void Info (object msg, [CallerFilePath] string source="", [CallerLineNumber] int lineNumber=0)
 Prints component and then message.
 
CUIComponent Remember (CUIComponent c, string name)
 
CUIComponent Remember (CUIComponent c)
 If it already has AKA.
 
CUIComponent Forget (string name)
 
CUIComponent Forget (CUIComponent c)
 If it already has AKA.
 
virtual CUIComponent Get (string name)
 Returns memorized component by name.
 
Get< T > (string name)
 
void CascadeRefresh ()
 
virtual bool IsPointOnTransparentPixel (Vector2 point)
 
virtual bool ShouldInvoke (CUIInput e)
 
void InvokeOnLayoutUpdated ()
 
record CompareResult (bool equal, string firstMismatch="")
 
CUIComponent Clone ()
 
void SaveStateAs (string name)
 
void LoadState (string name)
 
void ForgetState (string name)
 
void ApplyState (CUIComponent state)
 
virtual XElement ToXML (CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
virtual void FromXML (XElement element, string baseFolder=null)
 
string Serialize (CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
void LoadSelfFromFile (string path, bool searchForSpritesInTheSameFolder=true, bool saveAfterLoad=false)
 
void LoadFromTheSameFile ()
 
void SaveToTheSamePath ()
 
void SaveToFile (string path, CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
virtual void Hydrate ()
 Experimental method
Here you can add data/ callbacks/ save stuff to variables
after loading a xml skeletom.
 
virtual CUIComponent Append (CUIComponent child, string name=null, [CallerMemberName] string memberName="")
 Adds children to the end of the list.
 
virtual CUIComponent Prepend (CUIComponent child, string name=null, [CallerMemberName] string memberName="")
 Adds children to the begining of the list.
 
virtual CUIComponent Insert (CUIComponent child, int index, string name=null, [CallerMemberName] string memberName="")
 
void RemoveSelf ()
 
CUIComponent RemoveChild (CUIComponent child, [CallerMemberName] string memberName="")
 
void RemoveAllChildren ([CallerMemberName] string memberName="")
 
void MoveToFront ()
 Moves component to front in Parent.Children which makes it render after other childs.
 

Properties

bool Selected [get, set]
 From IKeyboardSubscriber, don't use it directly.
 
bool Valid [get, set]
 
Type VatidationType [get, set]
 
string Text [get, set]
 
IntRange Selection [get, set]
 
bool CaretIndicatorVisible [get, set]
 
double CaretBlinkInterval = 0.5 [get, set]
 
int CaretPos [get, set]
 
float TextScale [get, set]
 
Color TextColor [get, set]
 
Action< string > AddOnTextChanged [set]
 
Action< string > AddOnTextAdded [set]
 
- Properties inherited from CrabUI.CUIComponent
AttachedItemHandle AttachedItemHandle [get, set]
 
string Command [get, set]
 This command will be dispatched up when some component specific event happens.
 
string Consumes [get, set]
 Will consume data with this name.
 
bool ReflectCommands [get, set]
 
bool RetranslateCommands [get, set]
 
ObservableCollection< string > Emits [get, set]
 Optimization to data flow
If not empty component will search for consumers of the data and pass it directly to them instead of broadcasting it.
 
Dictionary< string, Action< object > > Commands = new() [get, set]
 All commands.
 
static IEnumerable< CUIComponentAllComponents [get]
 
bool Debug [get, set]
 
bool IgnoreDebug [get, set]
 
string AKA [get, set]
 Parent can memorize it's children by their names, AKA.
 
Dictionary< string, CUIComponentNamedComponents = new() [get, set]
 All memorized components.
 
CUIComponent this[string name] [get, set]
 You can access NamedComponents with this indexer.
 
bool ConsumeMouseClicks [get, set]
 
bool ConsumeDragAndDrop [get, set]
 
bool ConsumeSwipe [get, set]
 
bool ConsumeMouseScroll [get, set]
 
Action< double > AddOnUpdate [set]
 
Action< CUIInputAddOnMouseLeave [set]
 
Action< CUIInputAddOnMouseEnter [set]
 
Action< CUIInputAddOnMouseDown [set]
 
Action< CUIInputAddOnMouseUp [set]
 
Action< CUIInputAddOnMouseMove [set]
 
Action< CUIInputAddOnMouseOn [set]
 
Action< CUIInputAddOnMouseOff [set]
 
Action< CUIInputAddOnClick [set]
 
Action< CUIInputAddOnDClick [set]
 
Action< CUIInputAddOnScroll [set]
 
Action< float, float > AddOnDrag [set]
 
Action< float, float > AddOnSwipe [set]
 
Action< CUIInputAddOnKeyDown [set]
 
Action< CUIInputAddOnKeyUp [set]
 
Action< CUIInputAddOnTextInput [set]
 
Action AddOnFocus [set]
 
Action AddOnFocusLost [set]
 
bool Draggable [get, set]
 
bool Focusable [get, set]
 
bool Resizible [get, set]
 
bool ResizibleLeft [get, set]
 
bool ResizibleRight [get, set]
 
CUIBool2 ResizeDirection [get, set]
 
bool Swipeable [get, set]
 
virtual CUILayout Layout [get, set]
 
Dictionary< string, CUIComponentStates = new() [get, set]
 State is just a clone component with copies of all props.
 
string SavePath [get, set]
 
int ID [get, set]
 Global ID, unique for component.
 
CUIMainComponent MainComponent [get, set]
 Link to CUIMainComponent, passed to children.
 
bool Focused [get, set]
 
bool BackgroundVisible [get, set]
 BackgroundColor != Color.Transparent.
 
bool OutlineVisible [get, set]
 
bool MouseOver [get, set]
 
bool MousePressed [get, set]
 
CUINullVector2 ForcedMinSize [get, set]
 This is used by text to prevent resizing beyond that and works as AbsoluteMin.
 
float Scale [get, set]
 This is set by ChildrenOffset when zooming, and iirc consumed by text to adjust text scale.
 
CUIRect BorderBox [get, set]
 Calculated Prop, Real + BorderThickness.
 
CUIRect OutlineBox [get, set]
 
CUIRect Real [get, set]
 Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent.Update.
 
CUIStyle Style [get, set]
 Allows you to assing parsable string or link to CUIPalette to any prop
It's indexable, so you can access it like this: component.Style["BackgroundColor"] = "cyan"
if value starts with "CUIPalette." it will extract the value from palette
e.g. component.Style["BackgroundColor"] = "CUIPalette.DarkBlue.Secondary.On"

 
CUIStyle ResolvedStyle [get, set]
 
List< CUIComponentChildren = new() [get, set]
 
CUIComponentParent [get, set]
 
IEnumerable< CUIComponentAddChildren [set]
 Allows you to add array of children.
 
CUIComponentProps CUIProps = new() [get, set]
 Just a wrapper for CUIProps idk how to separate them better.
 
Vector2 Padding [get, set]
 Used for text, should be in CUITextBlock really.
 
CUISprite BorderSprite = CUISprite.Default [get, set]
 Should be one texture, not sprite sheet
Or there would be no way to wrap it
Top side will always point outwards.
 
CUIBorder Border = new CUIBorder() [get, set]
 Container for Color and Thickness
Border is drawn inside the component and will eat space from content
If "by side" border prop != null then it'll take presidence.
 
CUIBorder TopBorder [get, set]
 
CUIBorder RigthBorder [get, set]
 
CUIBorder BottomBorder [get, set]
 
CUIBorder LeftBorder [get, set]
 
float OutlineThickness = 1f [get, set]
 
Color OutlineColor [get, set]
 Outline is like a border, but on the outside of the component.
 
CUISprite BackgroundSprite [get, set]
 Will be drawn in background with BackgroundColor
Default is solid white 1x1 texture.
 
bool IgnoreTransparent [get, set]
 If true, mouse events on transparent pixels will be ignored
Note: this will buffer texture data and potentially consume a lot of memory so use wisely.
 
Color BackgroundColor [get, set]
 Color of BackgroundSprite, default is black
If you're using custom sprite and don't see it make sure this color is not black.
 
float Transparency [get, set]
 
PaletteOrder Palette [get, set]
 This palette will be used to resolve palette styles
Primary, Secondary, Tertiary, Quaternary.
 
PaletteOrder DeepPalette [set]
 
Color ResizeHandleColor = Color.White [get, set]
 Had to expose resize handle props, because it's not a real component and can't really use styles.
 
Color ResizeHandleGrabbedColor = Color.Cyan [get, set]
 
SamplerState SamplerState [get, set]
 don't
 
bool HideChildrenOutsideFrame [get, set]
 Should children be cut off by scissor rect, this is just visual, it's not the same as culling.
 
bool CullChildren [get, set]
 if child rect doesn't intersect with parent it won't be drawn and won't consume fps
It also sets HideChildrenOutsideFrame
 
bool UnCullable [get, set]
 It shouldn't be culled off even outside of parent bounds and even if parent demands so.
 
CUI3DOffset ChildrenOffset [get, set]
 Will shift all children by this much, e.g. this is how scroll works It's also 3D.
 
Func< CUIRect, CUIBoundariesChildrenBoundaries [get, set]
 Limits to children positions.
 
bool Fixed [get, set]
 Should it ignore child offset?
 
Vector2 Anchor [get, set]
 this point of this component
 
Vector2? ParentAnchor [get, set]
 will be attached to this point of parent
 
CUIBool2 Ghost [get, set]
 Ghost components don't affect layout.
 
int? ZIndex [get, set]
 Components are drawn in order of their ZIndex
Normally it's derived from component position in the tree, but this will override it.
 
bool ResizeToSprite [get, set]
 If true component will set it's Absolute size to sprite texture size.
 
CUIBool2 FillEmptySpace [get, set]
 Will be resized to fill empty space in list components.
 
CUIBool2 FitContent [get, set]
 Will resize itself to fit components with absolute size, e.g. text.
 
CUINullRect Absolute [get, set]
 Absolute size and position in pixels.
 
CUINullRect AbsoluteMin [get, set]
 
CUINullRect AbsoluteMax [get, set]
 
CUINullRect Relative [get, set]
 Relative to parent size and position, [0..1].
 
CUINullRect RelativeMin [get, set]
 
CUINullRect RelativeMax [get, set]
 
CUINullRect CrossRelative [get, set]
 It's like Relative, but to the opposite dimension
E.g. Real.Width = CrossRelative.Width * Parent.Real.Height
Handy for creating square things.
 
string GridTemplateRows [get, set]
 Used in Grid, space separated Row sizes, either in pixels (123) or in % (123%)
 
string GridTemplateColumns [get, set]
 Used in Grid, space separated Columns sizes, either in pixels (123) or in % (123%)
 
Point? GridStartCell [get, set]
 Component will be placed in this cell in the grid component.
 
Point? GridEndCell [get, set]
 And resized to fit cells from GridStartCell to GridEndCell.
 
Point? GridCell [get, set]
 Sets both GridStartCell and GridEndCell at once.
 
object Data [get, set]
 Arbitrary data.
 
virtual bool Disabled [get, set]
 Usually means - non interactable, e.g. unclickable gray button.
 
bool ShouldPassPropsToChildren = true [get, set]
 Some props (like visible) are autopassed to all new childs see PassPropsToChild.
 
bool IgnoreParentVisibility [get, set]
 Don't inherit parent Visibility.
 
bool IgnoreParentEventIgnorance [get, set]
 Don't inherit parent IgnoreEvents.
 
bool IgnoreParentZIndex [get, set]
 Don't inherit parent ZIndex.
 
bool IgnoreParentTransparency [get, set]
 
bool Visible [get, set]
 Invisible components are not drawn, but still can be interacted with.
 
bool IgnoreEvents [get, set]
 Won't react to mouse events.
 
bool Revealed [get, set]
 Visible + !IgnoreEvents.
 
bool Serializable = true [get, set]
 If false then this component and its children won't be serialized.
 
bool SerializeChildren = true [get, set]
 Is this a serialization cutoff point
Parent will serialize children down to this component and stop.
 
bool MergeSerialization = false [get, set]
 If true it won't be deserialized,
Instead its children will be detached and attached to the component with matching AKA on the parent.
 
bool ReplaceSerialization = false [get, set]
 If true, deserialized component will replace existing component with the same AKA instead of creating a duplicate.
 
static bool ForceSaveAllProps = false [get, set]
 
- Properties inherited from CrabUI.ISimpleProps
- Properties inherited from CrabUI.IListProps
- Properties inherited from CrabUI.ISerializationProps

Events

Action< string > OnTextChanged
 
Action< string > OnTextAdded
 
- Events inherited from CrabUI.CUIComponent
Action< CUICommandOnAnyCommand
 this will be executed on any command
 
Action< CUIDataOnAnyData
 Will be executed when receiving any data.
 
Action< Object > OnConsume
 Happens when appropriate data is received.
 
Action OnTreeChanged
 
Action< double > OnUpdate
 
Action< CUIInputOnMouseLeave
 
Action< CUIInputOnMouseEnter
 
Action< CUIInputOnMouseDown
 
Action< CUIInputOnMouseUp
 
Action< CUIInputOnMouseMove
 
Action< CUIInputOnMouseOn
 
Action< CUIInputOnMouseOff
 
Action< CUIInputOnClick
 
Action< CUIInputOnDClick
 
Action< CUIInputOnScroll
 
Action< float, float > OnDrag
 
Action< float, float > OnSwipe
 
Action< CUIInputOnKeyDown
 
Action< CUIInputOnKeyUp
 
Action< CUIInputOnTextInput
 
Action OnFocus
 
Action OnFocusLost
 
Action OnLayoutUpdated
 
Action OnStyleApplied
 Use it to e.g. update component color.
 
Action< CUIComponentOnChildAdded
 
Action< CUIComponentOnChildRemoved
 

Additional Inherited Members

- Static Public Member Functions inherited from CrabUI.CUIComponent
static void RunRecursiveOn (CUIComponent component, Action< CUIComponent > action)
 designed to be versatile, in fact never used
 
static void ForEach (Action< CUIComponent > action)
 
static IEnumerable< Type > GetClassHierarchy (Type type)
 
static IEnumerable< Type > GetReverseClassHierarchy (Type type)
 
static bool DeepCompareVerbose (CUIComponent a, CUIComponent b)
 
static CompareResult DeepCompare (CUIComponent a, CUIComponent b)
 
static CUIComponent Deserialize (string raw, string baseFolder=null)
 
static CUIComponent Deserialize (XElement e, string baseFolder=null)
 
static CUIComponent LoadFromFile (string path, bool searchForSpritesInTheSameFolder=true, bool saveAfterLoad=false)
 
static T LoadFromFile< T > (string path, bool searchForSpritesInTheSameFolder=true, bool saveAfterLoad=false)
 
- Public Attributes inherited from CrabUI.CUIComponent
Indexer< string, CUIAnimationAnimations
 
Dictionary< string, List< CUIComponent > > DataTargets = new()
 Consumers of emmited data, updates on tree change.
 
bool Disposed
 
bool ignoreDebug
 For debug frame itself.
 
CUIResizeHandle LeftResizeHandle = new CUIResizeHandle(new Vector2(0, 1), new CUIBool2(false, false))
 
CUIResizeHandle RightResizeHandle = new CUIResizeHandle(new Vector2(1, 1), new CUIBool2(true, false))
 
- Static Public Attributes inherited from CrabUI.CUIComponent
static Dictionary< int, WeakReference< CUIComponent > > ComponentsById = new()
 
static WeakCatalog< Type, CUIComponentComponentsByType = new()
 
static GUIButton dummyComponent
 This is used to trick vanilla GUI into believing that mouse is hovering some component and block clicks.
 
- Protected Member Functions inherited from CrabUI.CUIComponent
void ExtractProps (XElement element, string baseFolder=null)
 
void PackProps (XElement element, CUIAttribute propAttribute=CUIAttribute.CUISerializable)
 
virtual void PassPropsToChild (CUIComponent child)
 Pass props like ZIndex, Visible to a new child.
 
- Protected Attributes inherited from CrabUI.CUIComponent
CUILayout layout
 
CUINullVector2 forsedSize
 
float scale = 1f
 
Color[] TextureData
 Buffer for texture data, for IgnoreTransparent checks.
 
bool disabled
 
- Package Functions inherited from CrabUI.CUIComponent
- Static Package Functions inherited from CrabUI.CUIComponent
- Package Attributes inherited from CrabUI.CUIComponent
- Static Package Attributes inherited from CrabUI.CUIComponent

Detailed Description

Text input.

Definition at line 19 of file CUITextInput.cs.

Constructor & Destructor Documentation

◆ CUITextInput() [1/2]

CrabUI.CUITextInput.CUITextInput ( string text)

Definition at line 380 of file CUITextInput.cs.

380 : this()
381 {
382 Text = text;
383 }

◆ CUITextInput() [2/2]

CrabUI.CUITextInput.CUITextInput ( )

Definition at line 384 of file CUITextInput.cs.

384 : base()
385 {
386 AbsoluteMin = new CUINullRect(w: 50, h: 22);
387 FitContent = new CUIBool2(true, true);
388 Focusable = true;
389 Border.Thickness = 2;
391 ConsumeMouseClicks = true;
392 ConsumeDragAndDrop = true;
393 ConsumeSwipe = true;
394 SerializeChildren = false;
395
396 this["TextComponent"] = TextComponent = new CUITextBlock()
397 {
398 Text = "",
399 Relative = new CUINullRect(0, 0, 1, 1),
400 TextAlign = CUIAnchor.CenterLeft,
401 Style = new CUIStyle(){
402 {"Padding", "[2,2]"},
403 {"TextColor", "CUIPalette.Input.Text"},
404 },
405 };
406
407 this["SelectionOverlay"] = SelectionOverlay = new CUIComponent()
408 {
409 Style = new CUIStyle(){
410 {"BackgroundColor", "CUIPalette.Input.Selection"},
411 {"Border", "Transparent"},
412 },
413 Relative = new CUINullRect(h: 1),
414 Ghost = new CUIBool2(true, true),
416 };
417
418 this["CaretIndicator"] = CaretIndicator = new CUIComponent()
419 {
420 Style = new CUIStyle(){
421 {"BackgroundColor", "CUIPalette.Input.Caret"},
422 {"Border", "Transparent"},
423 },
424 Relative = new CUINullRect(y: 0.1f, h: 0.8f),
425 Absolute = new CUINullRect(w: 1),
426 Ghost = new CUIBool2(true, true),
427 Visible = false,
429 };
430
431 OnConsume += (o) =>
432 {
433 string value = o.ToString();
434 State = new TextInputState(value, State.Selection, State.CaretPos);
435 Valid = IsValidText(value);
436 };
437
438
439
440 OnFocus += () =>
441 {
442 UpdateBorderColor();
443 CaretIndicator.Visible = true;
444 };
445
446 OnFocusLost += () =>
447 {
448 UpdateBorderColor();
449 Selection = IntRange.Zero;
450 CaretIndicator.Visible = false;
451 };
452
453 OnMouseDown += (e) =>
454 {
455 int newCaretPos = SetCaretPos(e.MousePosition - Real.Position);
456 Selection = IntRange.Zero;
457 selectionHandle.lastSelectedPos = newCaretPos;
458 selectionHandle.Grabbed = true;
459 };
460
461 OnMouseMove += (e) =>
462 {
463 if (selectionHandle.Grabbed)
464 {
465 int nextCaretPos = SetCaretPos(e.MousePosition - Real.Position);
466 Selection = new IntRange(selectionHandle.lastSelectedPos, nextCaretPos);
467 }
468 };
469
470 OnDClick += (e) => SelectAll();
471
472 if (CUI.Main is not null)
473 {
474 CUI.Main.Global.OnMouseUp += (e) => selectionHandle.Grabbed = false;
475 }
476 }
CUINullRect Relative
Relative to parent size and position, [0..1].
CUIStyle Style
Allows you to assing parsable string or link to CUIPalette to any prop It's indexable,...
bool HideChildrenOutsideFrame
Should children be cut off by scissor rect, this is just visual, it's not the same as culling.
CUIBool2 FitContent
Will resize itself to fit components with absolute size, e.g. text.
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
bool SerializeChildren
Is this a serialization cutoff point Parent will serialize children down to this component and stop...
bool IgnoreParentVisibility
Don't inherit parent Visibility.
Action< Object > OnConsume
Happens when appropriate data is received.
CUIBool2 Ghost
Ghost components don't affect layout.
bool Visible
Invisible components are not drawn, but still can be interacted with.
CUINullRect Absolute
Absolute size and position in pixels.

Member Function Documentation

◆ Back()

void CrabUI.CUITextInput.Back ( )

Definition at line 141 of file CUITextInput.cs.

142 {
143 TextInputState oldState = State;
144 if (!Selection.IsEmpty) CutSelection();
145 else
146 {
147 string s1 = oldState.Text.SubstringSafe(0, oldState.CaretPos - 1);
148 string s2 = oldState.Text.SubstringSafe(oldState.CaretPos);
149 Text = s1 + s2;
150 CaretPos = oldState.CaretPos - 1;
151 if (Command != null) DispatchUp(new CUICommand(Command, State.Text));
152 }
153 }
string Command
This command will be dispatched up when some component specific event happens.
void DispatchUp(CUICommand command)
Dispathes command up the component tree until someone consumes it.
record CUICommand(string Name, object Data=null)
Can be dispatched up the component tree to notify parent about something add pass some event data wit...

◆ Copy()

void CrabUI.CUITextInput.Copy ( )

Definition at line 105 of file CUITextInput.cs.

106 {
107 if (Selection.IsEmpty) return;
108 selectionHandle.Grabbed = false;
109 Clipboard.SetText(Text.SubstringSafe(Selection.Start, Selection.End));
110 }

◆ CutSelection()

void CrabUI.CUITextInput.CutSelection ( )

Definition at line 169 of file CUITextInput.cs.

170 {
171 if (Selection.IsEmpty) return;
172 selectionHandle.Grabbed = false;
173 string s1 = Text.SubstringSafe(0, Selection.Start);
174 string s2 = Text.SubstringSafe(Selection.End);
175 Text = s1 + s2;
176 CaretPos = Selection.Start;
177 Selection = IntRange.Zero;
178 if (Command != null) DispatchUp(new CUICommand(Command, State.Text));
179 }

◆ Delete()

void CrabUI.CUITextInput.Delete ( )

Definition at line 155 of file CUITextInput.cs.

156 {
157 TextInputState oldState = State;
158 if (!Selection.IsEmpty) CutSelection();
159 else
160 {
161 string s1 = oldState.Text.SubstringSafe(0, oldState.CaretPos);
162 string s2 = oldState.Text.SubstringSafe(oldState.CaretPos + 1);
163 Text = s1 + s2;
164 if (Command != null) DispatchUp(new CUICommand(Command, State.Text));
165 //CaretPos = oldState.CaretPos;
166 }
167 }

◆ Draw()

override void CrabUI.CUITextInput.Draw ( SpriteBatch spriteBatch)
virtual

Here component should be drawn.

Parameters
spriteBatch

Reimplemented from CrabUI.CUIComponent.

Definition at line 367 of file CUITextInput.cs.

368 {
369 if (Focused)
370 {
371 CaretIndicator.Visible = CaretIndicatorVisible && Timing.TotalTime % CaretBlinkInterval > CaretBlinkInterval / 2;
372 }
373
374
375 base.Draw(spriteBatch);
376 }

◆ IsValidText()

bool CrabUI.CUITextInput.IsValidText ( string text)

Definition at line 263 of file CUITextInput.cs.

264 {
265 if (VatidationType == null) return true;
266
267 if (VatidationType == typeof(string)) return true;
268 if (VatidationType == typeof(Color)) return true;
269 if (VatidationType == typeof(bool)) return bool.TryParse(text, out _);
270 if (VatidationType == typeof(int)) return int.TryParse(text, out _);
271 if (VatidationType == typeof(float)) return float.TryParse(text, out _);
272 if (VatidationType == typeof(double)) return double.TryParse(text, out _);
273
274 return false;
275 }

◆ MoveLeft()

void CrabUI.CUITextInput.MoveLeft ( )

Definition at line 117 of file CUITextInput.cs.

118 {
119 CaretPos--;
120 Selection = IntRange.Zero;
121 }

◆ MoveRight()

void CrabUI.CUITextInput.MoveRight ( )

Definition at line 122 of file CUITextInput.cs.

123 {
124 CaretPos++;
125 Selection = IntRange.Zero;
126 }

◆ Paste()

void CrabUI.CUITextInput.Paste ( )

Definition at line 111 of file CUITextInput.cs.

112 {
113 ReceiveTextInput(Clipboard.GetText());
114 }
void ReceiveTextInput(char inputChar)
From IKeyboardSubscriber, don't use it directly.

◆ ReceiveCommandInput()

void CrabUI.CUITextInput.ReceiveCommandInput ( char command)

From IKeyboardSubscriber, don't use it directly.

Definition at line 71 of file CUITextInput.cs.

72 {
73 try
74 {
75 if (pressedKey == Keys.A) SelectAll();
76 if (pressedKey == Keys.C) Copy();
77 if (pressedKey == Keys.V) Paste();
78 }
79 catch (Exception e)
80 {
81 CUI.Warning(e);
82 }
83 //CUI.Log($"ReceiveCommandInput {command}");
84 }

◆ ReceiveEditingInput()

void CrabUI.CUITextInput.ReceiveEditingInput ( string text,
int start,
int length )

From IKeyboardSubscriber, don't use it directly.

Definition at line 90 of file CUITextInput.cs.

91 {
92 //CUI.Log($"ReceiveEditingInput {text} {start} {length}");
93 }

◆ ReceiveSpecialInput()

void CrabUI.CUITextInput.ReceiveSpecialInput ( Keys key)

From IKeyboardSubscriber, don't use it directly.

Definition at line 29 of file CUITextInput.cs.

30 {
31 try
32 {
33 pressedKey = key;
34 if (key == Keys.Back) Back();
35 if (key == Keys.Delete) Delete();
36 if (key == Keys.Left) MoveLeft();
37 if (key == Keys.Right) MoveRight();
38 }
39 catch (Exception e)
40 {
41 CUI.Warning(e);
42 }
43 }

◆ ReceiveTextInput()

void CrabUI.CUITextInput.ReceiveTextInput ( string text)

From IKeyboardSubscriber, don't use it directly.

Definition at line 51 of file CUITextInput.cs.

52 {
53 try
54 {
55 CutSelection();
56 Text = Text.Insert(CaretPos, text);
57 CaretPos = CaretPos + 1;
58 OnTextAdded?.Invoke(text);
59 if (Command != null) DispatchUp(new CUICommand(Command, State.Text));
60 //CUI.Log($"ReceiveTextInput {text}");
61 }
62 catch (Exception e)
63 {
64 CUI.Log(e);
65 }
66
67 }

◆ UpdateBorderColor()

void CrabUI.CUITextInput.UpdateBorderColor ( )

Definition at line 326 of file CUITextInput.cs.

327 {
328 if (Valid)
329 {
330 if (Focused)
331 {
332 Style["Border"] = "CUIPalette.Input.Focused";
333 }
334 else
335 {
336 Style["Border"] = "CUIPalette.Input.Border";
337 }
338 }
339 else
340 {
341 Style["Border"] = "CUIPalette.Input.Invalid";
342 }
343 }

Property Documentation

◆ AddOnTextAdded

Action<string> CrabUI.CUITextInput.AddOnTextAdded
set

Definition at line 365 of file CUITextInput.cs.

365{ set => OnTextAdded += value; }

◆ AddOnTextChanged

Action<string> CrabUI.CUITextInput.AddOnTextChanged
set

Definition at line 363 of file CUITextInput.cs.

363{ set => OnTextChanged += value; }

◆ CaretBlinkInterval

double CrabUI.CUITextInput.CaretBlinkInterval = 0.5
getset

Definition at line 314 of file CUITextInput.cs.

314{ get; set; } = 0.5;

◆ CaretIndicatorVisible

bool CrabUI.CUITextInput.CaretIndicatorVisible
getset

Definition at line 313 of file CUITextInput.cs.

313{ get; set; }

◆ CaretPos

int CrabUI.CUITextInput.CaretPos
getset

Definition at line 316 of file CUITextInput.cs.

317 {
318 get => State.CaretPos;
319 set => State = new TextInputState(State.Text, State.Selection, value);
320 }

◆ Selected

bool CrabUI.CUITextInput.Selected
getset

From IKeyboardSubscriber, don't use it directly.

Definition at line 99 of file CUITextInput.cs.

99{ get; set; }

◆ Selection

IntRange CrabUI.CUITextInput.Selection
getset

Definition at line 305 of file CUITextInput.cs.

306 {
307 get => State.Selection;
308 set => State = new TextInputState(State.Text, value, State.CaretPos);
309 }

◆ Text

string CrabUI.CUITextInput.Text
getset

Definition at line 286 of file CUITextInput.cs.

287 {
288 get => State.Text;
289 set
290 {
291 if (Disabled) return;
292
293 State = new TextInputState(value, State.Selection, State.CaretPos);
294
295 bool isvalid = IsValidText(value);
296 if (isvalid)
297 {
298 OnTextChanged?.Invoke(State.Text);
299 }
300 Valid = isvalid;
301 }
302 }
virtual bool Disabled
Usually means - non interactable, e.g. unclickable gray button.

◆ TextColor

Color CrabUI.CUITextInput.TextColor
getset

Definition at line 350 of file CUITextInput.cs.

351 {
352 get => TextComponent?.TextColor ?? Color.White;
353 set
354 {
355 if (TextComponent != null)
356 {
357 TextComponent.TextColor = value;
358 }
359 }
360 }

◆ TextScale

float CrabUI.CUITextInput.TextScale
getset

Definition at line 345 of file CUITextInput.cs.

346 {
347 get => TextComponent?.TextScale ?? 0;
348 set => TextComponent.TextScale = value;
349 }

◆ Valid

bool CrabUI.CUITextInput.Valid
getset

Definition at line 251 of file CUITextInput.cs.

252 {
253 get => valid;
254 set
255 {
256 if (valid == value) return;
257 valid = value;
258 UpdateBorderColor();
259 }
260 }

◆ VatidationType

Type CrabUI.CUITextInput.VatidationType
getset

Definition at line 262 of file CUITextInput.cs.

262{ get; set; }

Event Documentation

◆ OnTextAdded

Action<string> CrabUI.CUITextInput.OnTextAdded

Definition at line 364 of file CUITextInput.cs.

◆ OnTextChanged

Action<string> CrabUI.CUITextInput.OnTextChanged

Definition at line 362 of file CUITextInput.cs.


The documentation for this class was generated from the following file: