Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improved FlxInputText to core Flixel #3219

Merged
merged 50 commits into from
Aug 6, 2024

Conversation

Starmapo
Copy link
Contributor

@Starmapo Starmapo commented Jul 14, 2024

This is the completed version of #3191 that adds an improved version of FlxInputText from flixel-ui to the base library.

Improvements over the original FlxInputText

  • Multiple characters can now be selected at once, either through holding and dragging the mouse or holding the shift key while moving the selection cursor.
    • Double pressing on the text field will select the closest word at that position.
    • You can select all of the text with Ctrl+A.
    • The currently selected text can be copied or cut with Ctrl+C and Ctrl+X respectively.
    • selectionBeginIndex and selectionEndIndex variables added so you can get the span of the current selection.
    • selectionColor and selectedTextColor variables can be changed to set the selection background and the selected text's color respectively. The custom format for the selected text can be disabled with useSelectedTextFormat.
    • You can set the selection directly with setSelection() and replace the currently selected text with replaceSelectedText().
  • Multiline is now properly supported, with an added multiline variable to dictate whether new lines can be created by the user.
  • The text field can now be scrolled by using the mouse wheel, and is automatically scrolled whenever moving the selection cursor to a character that is out of view.
    • The scroll can be modified with the scrollH and scrollV variables. bottomScrollV, maxScrollH and maxScrollV have also been added as helper read-only variables.
    • mouseWheelEnabled dictates whether or not the text field can be scrolled with the mouse wheel, by default set to true.
  • The selection cursor can now be moved to the start/end of the current line (Home/End or Ctrl+Up/Down) or to the previous/next word (Ctrl+Left/Right).
  • The background variable can now be changed to toggle the background on/off.
  • selectable and editable variables to dictate whether the text field can be selected/edited.
  • Enums have been added for forceCase, filterMode and the callback's action types.
    • The callback is now also dispatched for when the text field is scrolled in some way (SCROLL_ACTION).
  • Other Flixel keybinds will be paused while an input text is active (e.g. volume keys and debugger toggle key).
  • The window's text input rect is now set accordingly so the text field isn't blocked by any keyboard overlays.
  • Touches are now supported.
  • InputTextFrontEnd added (accessible via FlxG.inputText) to allow for easier implementations of other types of input texts.

Things to consider

  • The only variable from the original that wasn't added was lines. From what I could see, this didn't actually dictate the amount of lines that could be added, and was basically just a setter for if the text was multiline or not (which on top of that, multiline wasn't properly implemented in the original input text).
  • Demos should be added to showcase the new input text, but I'm not good at coming up with ideas for those.

- Regenerate text graphic when `passwordMode` changes
- Add `setSelection()` function
- `FlxInputText` variables are now destroyed properly
- Added `scrollH`, `scrollV`, `bottomScrollV`, `maxScrollH` & `maxScrollV` variables
- Return end of text if character isn't found at position
- Selection boxes are now clipped inside the text bounds
- Simplified getting the Y offset of a line
- Fix scrollV not being able to be modified directly
- Selection sprites now just change their color instead of making new graphics
- scrollH can now be modified properly as well
- Word wrap no longer changes with multiline (multiline only affects adding new lines)
- Caret is now positioned properly with different alignments
- Caret is now clipped inside the text bounds
- Caret is now automatically resized when changing `bold`, `font`, `italic`, `size` or `systemFont` variables
- Fixed crash when pressing down a key while there isn't a focused input text
- Fixed selected text format overwriting the border color
- Fixed caret not being visible when text is empty
- Fixed selection boxes sometimes not being updated immediately
- Added `useSelectedTextFormat` variable
- Double press check is now when the mouse is released (same as OpenFL)
- Moved action callback types to an enum abstract
- Added `focusGained` and `focusLost` callbacks
- Fixed selection boxes not being clipped properly when they're compeletely out of bounds
- Added bounds check while changing `caretIndex`, `caretWidth`, `fieldBorderThickness` and `maxLength`
- FlxInputText is now single-line by default
- Fixed text scroll being reset while moving selection with mouse
- Caret index now starts at the end of the text if focus is enabled through code
- Background now gets regenerated in `regenGraphic` instead of instantly after changing a related variable
- Added change and scroll action callbacks
- Made `replaceSelectedText()` public
- Fixed text going out of bounds when enabling multiline without a field height set
- Last click time for double click now resets if the mouse clicked on something else
… now)

- Fixed untypeable characters being added to text input on Flash
- Fixed text selection and caret positioning on Flash
- Copy, cut, paste and select all commands now work on Flash
- Fixed horizontal scroll not being set automatically on Flash
- Moved to using Flash's `TextEvent.TEXT_INPUT` event (does not dispatch with invalid characters)
- Now uses `window.setTextInputRect()` to prevent keyboard overlay from blocking the text field
- Fixed pointer position being inaccurate with camera scrolling
- Fixed `getCharBoundaries()` not giving the correct Y position
- Fixed not being able to add text if the field starts out empty
- Fixed the caret being the wrong size if the text field is empty
- Fixed the background not being resized when auto size is enabled
- Changing `customFilterPattern` now automatically sets `filterMode` to `CUSTOM_FILTER`
- Renamed `_lastClickTime` to `_lastPressTime`
- Remove setting `_autoHeight` to false after setting multiline to true as its no longer needed
- Remove unneeded `selectable` comment
…IGHT`

- Ctrl + Up/Down now dispatches `LINE_LEFT` or `LINE_RIGHT` instead of `HOME` or `END`
- Renamed `LINE_BEGINNING` and `LINE_END` to `LINE_LEFT` and `LINE_RIGHT`
- Clip rect should now work properly
- Fixed caret showing up after changing `text` through code
- Focus will not be removed due to clicking outside of the text field if it has been granted via code in the same frame
- Caret will no longer be visible if the text field isn't editable
- Fixed some html5 tests not compiling on CI
@Geokureli
Copy link
Member

Geokureli commented Jul 19, 2024

there should be a destroy(), btw

Edit: didn't mean to close, sorry

@Geokureli Geokureli closed this Jul 19, 2024
@Geokureli Geokureli reopened this Jul 19, 2024
@Starmapo
Copy link
Contributor Author

there should be a destroy(), btw

You mean for the FlxInputTextManager?

@Geokureli
Copy link
Member

there should be a destroy(), btw

You mean for the FlxInputTextManager?

yes

- Add `unregisterAll()` to FlxInputTextManager
@DetectiveBaldi
Copy link
Contributor

DetectiveBaldi commented Jul 21, 2024

@Starmapo iirc your text library is used in haxeui-flixel for better text management. once 5.9.0 releases/when this is merged, will you be able to migrate haxeui to using the now standard flixel input text instead?

@Starmapo
Copy link
Contributor Author

@Starmapo iirc your text library is used in haxeui-flixel for better text management. once 5.9.0 releases/when this is merged, will you be able to migrate haxeui to using the now standard flixel input text instead?

Yes, I already have the necessary modifications on my local repository, once 5.9.0 is released I will open the PR for haxeui-flixel.

@Geokureli
Copy link
Member

Geokureli commented Jul 24, 2024

Some changes:

  • added onTypingAction to the manager, so anything can listen for events
  • allow custom input managers and inputText.setManager(mng)
  • remove set_focus for setFocus. (not a fan of setters that do more than set some converted value)
  • make _registeredInputTexts final, simplifying init/destroy, improving null safety
  • fix error with removing inputs while looping through (causing missed removals)
  • change case FOO: if (condition) {foo;} to case FOO if (condition): foo;
  • recreate mac cursor movement behavior via modifier keys
  • rename HOME and END move commands to TOP and BOTTOM (make distinct from key names, which behave differently on mac)
  • fix the issue where select dragging from right to left causes the selection to be left to right

I need to test this on my windows machine, too

@Geokureli
Copy link
Member

I'm seeing more heavy overuse of setters for handling huge portions of code, in my experience this is a recipe for fragile code, especially when different setters set each other recursively.

I see more instances of unneeded complexity that I'd like to deal with now

@Geokureli
Copy link
Member

I see more instances of unneeded complexity that I'd like to deal with now

I realize that many of these things are copied from the old FlxInputText, and don't need to be corrected now

@Geokureli Geokureli merged commit 94dbde5 into HaxeFlixel:dev Aug 6, 2024
11 checks passed
@Geokureli
Copy link
Member

Sorry this took so long, I think I was a little nervous since it's fuckin huge, also dealing with some family stuff atm

Thanks a ton!

@Geokureli Geokureli changed the title Improved FlxInputText Add improved FlxInputText to core flixel Aug 6, 2024
@Geokureli Geokureli changed the title Add improved FlxInputText to core flixel Add improved FlxInputText to core Flixel Aug 6, 2024
@Starmapo
Copy link
Contributor Author

Starmapo commented Aug 6, 2024

Sorry this took so long, I think I was a little nervous since it's fuckin huge, also dealing with some family stuff atm

Don't worry about it, I wasn't in a rush or anything, and I agree its pretty huge. Thank you for accepting it ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants