-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tutorial for UI Text Input (#453)
Co-authored-by: Steven Yau <[email protected]>
- Loading branch information
1 parent
9fa8a4c
commit 84365c4
Showing
10 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: User Interface - Text Input | ||
layout: tutorial-page.hbs | ||
tags: ui | ||
thumb: https://s3-eu-west-1.amazonaws.com/images.playcanvas.com/projects/12/1005906/36C2AF-image-75.jpg | ||
--- | ||
|
||
<iframe loading="lazy" src="https://playcanv.as/p/8ZQaDGf8/" title="User Interface - Text Input"></iframe> | ||
|
||
[Click here to see the project][project-link]. | ||
|
||
## Overview | ||
|
||
Text input can be done many ways in PlayCanvas and this tutorial shares a library that aims to be flexible enough to cover the most common cases. | ||
|
||
It uses a HTML input element that is overlaid on top of the PlayCanvas rendering canvas and is positioned depending on whether mouse or touch is used to interact with the input element. | ||
|
||
Using a HTML input element allows all the OS level operations that an user would expect on a webpage including copy and paste and password managers. | ||
|
||
If touch is used, there is an assumption that a virtual keyboard would be shown and the HTML input element is positioned accordingly. | ||
|
||
Here are examples of it being used on desktop: | ||
|
||
![][desktop-preview] | ||
|
||
And on mobile: | ||
|
||
<div class="centered"><video height="360" controls src="/images/tutorials/ui-text-input/mobile-preview.mp4"></div> | ||
|
||
<div class="alert alert-info"> | ||
Note: This doesn't support 3D elements</a>. | ||
</div> | ||
|
||
## How to install | ||
|
||
Open the [example project][project-link], right click on the folder 'ui-input' and click on 'Copy'. | ||
![][copy-folder] | ||
|
||
Open your project, right click in the assets panel and click on 'Paste' | ||
![][paste-folder] | ||
|
||
## Adding your first text input | ||
|
||
Create an UI Image/Group Element Entity as a child of a UI 2D Screen and size it accordingly. Make sure to enable 'Use Input' on the Element component. This defines the input area for the user to click on and start inputting text. | ||
|
||
![][create-image-element] | ||
|
||
Add a Script Component to the Element Entity and add the Script Type 'uiInputField'. | ||
|
||
![][add-script-component] | ||
|
||
Create a UI Text Element Entity as a child of the Element Entity that we just created. The text in the element will updated by the Script Type 'uiInputField' based on the user input and the script attributes data. | ||
|
||
![][create-text-element] | ||
|
||
Go back to the Script Type 'uiInputField' that added earlier, reference the Text Element Entity and change the script attributes data to your use case. Hover over each attribute to see the tooltip and description. | ||
|
||
![][update-script-type] | ||
|
||
Finally, launch the scene to test. | ||
|
||
![][launch-scene] | ||
|
||
## Advanced: How to style | ||
|
||
The library uses a neutral color style for the HTML input element. If you want to change the style to better suit your application, you can modify the CSS in 'ui-input-library.js' in function `createInputDom`. | ||
|
||
[desktop-preview]: /images/tutorials/ui-text-input/desktop-preview.gif | ||
[project-link]: https://playcanvas.com/project/1005906/overview/ui-text-input | ||
[copy-folder]: /images/tutorials/ui-text-input/copy-folder.gif | ||
[paste-folder]: /images/tutorials/ui-text-input/paste-folder.gif | ||
[create-image-element]: /images/tutorials/ui-text-input/create-image-element.gif | ||
[add-script-component]: /images/tutorials/ui-text-input/add-script-component.gif | ||
[create-text-element]: /images/tutorials/ui-text-input/create-text-element.gif | ||
[update-script-type]: /images/tutorials/ui-text-input/update-script-type.gif | ||
[launch-scene]: /images/tutorials/ui-text-input/launch-scene.gif |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.