Chat Control - relu91/nifty-gui GitHub Wiki
The Nifty Chat Control demonstrates how you can combine multiple controls to form a new one. The Chat Control was created by Nifty User ractoc and represents a typical chat window. There is a scrollable area for the chat history, an area for the chat members (called Players in the control) as well as a textfield and a button to send a message.
The Chat Control is supposed to be used with some form of network protocol to send the messages (this is not included).
A Eventbus event is being generated when the user has entered a new text line. A single chat line can contain an optional icon as well.
The Chat Java API is used to:
- add/remove players and
- add a new line to the chat area.
The following tables describe all of the parameters that you can apply to the control when they are being created.
Name | Datatype | Default | Description |
lines | Integer | 10 | The maximum number of lines visible in the history area of the chat without the need to scroll. This parameter directly influences the height of the control. |
sendLabel | String | "Send" | The send button text. |
chatLineIconWidth | SizeValue | 25px | Every chat line consists of an icon and a text. The chatLineIconWidth parameter determines the width of the chat line icon. |
chatLineIconHeight | SizeValue | 25px | Every chat line consists of an icon and a text. The chatLineIconHeight parameter determines the width of the chat line icon. |
chatLineHeight | SizeValue | 25px | Every chat line consists of an icon and a text. The chatLineHeight parameter determines the height of a chat line. |
The ChatTextSendEvent is published on the EventBus when the user has entered a new line of text.
// create the chat control allocating room to display 14 lines and change the send button text to "Send Message"
control(new ChatBuilder("chatId", 14) {{
sendLabel("Send Message");
}});
// create a chat control
<control id="chatId" name="nifty-chat" width="100%" height="100%" lines="14" sendLabel="Send Message" />
Complete examples can be found in the new nifty-default-controls-example (using JavaBuilder only).