Implementing a chat app user interface
A common example of graphical applications, especially in a mobile context, is the messaging app. Although there are many messaging apps now, they often share the design of colored textboxes scrolling back through time. They are also either left or right aligned (with some padding for emphasis) to show incoming messages as distinct from outgoing. In this example, we will implement the message component to show text in this way and apply a custom theme to give the app an identity.
Creating a message widget
We start with the message widget that is used to display a single message. Each message will have a body of text and the name of the person who sent the message. Using the sender name, we can determine whether the message is outgoing. To begin, we define a custom Widget
type that will hold this data in a new file, message.go
:
- To create a custom widget, we define a new type, named
message
, that extendswidget.BaseWidget
. We add to...