views

package
v1.4.1-0...-335c73b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

tcell views

This package provides some enhanced functionality on top of base tcell. In particular, support for logical views, and a few different kinds of widgets like title bars, and scrollable areas, are provided.

These make up a higher level interface than tcell itself.

Documentation

Index

Constants

View Source
const (
	// AlignBegin indicates alignment at the top left corner.
	AlignBegin = HAlignLeft | VAlignTop

	// AlignEnd indicates alignment at the bottom right corner.
	AlignEnd = HAlignRight | VAlignBottom

	// AlignMiddle indicates full centering.
	AlignMiddle = HAlignCenter | VAlignCenter
)
View Source
const (
	// Horizontal indicates left to right orientation.
	Horizontal = iota

	// Vertical indicates top to bottom orientation.
	Vertical
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment represents the alignment of an object, and consists of either or both of horizontal and vertical alignment.

const (
	// HAlignLeft indicates alignment on the left edge.
	HAlignLeft Alignment = 1 << iota

	// HAlignCenter indicates horizontally centered.
	HAlignCenter

	// HAlignRight indicates alignment on the right edge.
	HAlignRight

	// VAlignTop indicates alignment on the top edge.
	VAlignTop

	// VAlignCenter indicates vertically centered.
	VAlignCenter

	// VAlignBottom indicates alignment on the bottom edge.
	VAlignBottom
)

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application represents an event-driven application running on a screen.

func (*Application) PostFunc

func (app *Application) PostFunc(fn func())

PostFunc posts a function to be executed in the context of the application's event loop. Functions that need to update displayed state, etc. can do this to avoid holding locks.

func (*Application) Quit

func (app *Application) Quit()

Quit causes the application to shutdown gracefully. It does not wait for the application to exit, but returns immediately.

func (*Application) Refresh

func (app *Application) Refresh()

Refresh causes the application forcibly redraw everything. Use this to clear up screen corruption, etc.

func (*Application) Run

func (app *Application) Run() error

Run runs the application, waiting until the application loop exits. It is equivalent to app.Start() followed by app.Wait()

func (*Application) SetRootWidget

func (app *Application) SetRootWidget(widget Widget)

SetRootWidget sets the primary (root, main) Widget to be displayed.

func (*Application) SetScreen

func (app *Application) SetScreen(scr tcell.Screen)

SetScreen sets the screen to use for the application. This must be done before the application starts to run or is initialized.

func (*Application) SetStyle

func (app *Application) SetStyle(style tcell.Style)

SetStyle sets the default style (background) to be used for Widgets that have not specified any other style.

func (*Application) Start

func (app *Application) Start()

Start starts the application loop, initializing the screen and starting the Event loop. The application will run in a goroutine until Quit is called.

func (*Application) Update

func (app *Application) Update()

Update asks the application to draw any screen updates that have not been drawn yet.

func (*Application) Wait

func (app *Application) Wait() error

Wait waits until the application finishes.

type BoxLayout

type BoxLayout struct {
	WidgetWatchers
	// contains filtered or unexported fields
}

BoxLayout is a container Widget that lays out its child widgets in either a horizontal row or a vertical column.

func NewBoxLayout

func NewBoxLayout(orient Orientation) *BoxLayout

NewBoxLayout creates an empty BoxLayout.

func (*BoxLayout) AddWidget

func (b *BoxLayout) AddWidget(widget Widget, fill float64)

AddWidget adds a widget to the end of the BoxLayout.

func (*BoxLayout) Draw

func (b *BoxLayout) Draw()

Draw is called to update the displayed content.

func (*BoxLayout) HandleEvent

func (b *BoxLayout) HandleEvent(ev tcell.Event) bool

HandleEvent implements a tcell.EventHandler. The only events we care about are Widget change events from our children. We watch for those so that if the child changes, we can arrange to update our layout.

func (*BoxLayout) InsertWidget

func (b *BoxLayout) InsertWidget(index int, widget Widget, fill float64)

InsertWidget inserts a widget at the given offset. Offset 0 is the front. If the index is longer than the number of widgets, then it just gets appended to the end.

func (*BoxLayout) RemoveWidget

func (b *BoxLayout) RemoveWidget(widget Widget)

RemoveWidget removes a Widget from the layout.

func (*BoxLayout) Resize

func (b *BoxLayout) Resize()

Resize adjusts the layout when the underlying View changes size.

func (*BoxLayout) SetOrientation

func (b *BoxLayout) SetOrientation(orient Orientation)

SetOrientation sets the orientation as either Horizontal or Vertical.

func (*BoxLayout) SetStyle

func (b *BoxLayout) SetStyle(style tcell.Style)

SetStyle sets the style used.

func (*BoxLayout) SetView

func (b *BoxLayout) SetView(view View)

SetView sets the View object used for the text bar.

func (*BoxLayout) Size

func (b *BoxLayout) Size() (int, int)

Size returns the preferred size in character cells (width, height).

func (*BoxLayout) Widgets

func (b *BoxLayout) Widgets() []Widget

Widgets returns the list of Widgets for this BoxLayout.

type CellModel

type CellModel interface {
	GetCell(x, y int) (rune, tcell.Style, []rune, int)
	GetBounds() (int, int)
	SetCursor(int, int)
	GetCursor() (int, int, bool, bool)
	MoveCursor(offx, offy int)
}

CellModel models the content of a CellView. The dimensions used within a CellModel are always logical, and have origin 0, 0.

type CellView

type CellView struct {
	WidgetWatchers
	// contains filtered or unexported fields
}

CellView is a flexible view of a CellModel, offering both cursor management and a panning.

func NewCellView

func NewCellView() *CellView

NewCellView creates a CellView.

func (*CellView) Draw

func (a *CellView) Draw()

Draw draws the content.

func (*CellView) GetModel

func (a *CellView) GetModel() CellModel

GetModel gets the model for this CellView

func (*CellView) HandleEvent

func (a *CellView) HandleEvent(e tcell.Event) bool

HandleEvent handles events. In particular, it handles certain key events to move the cursor or pan the view.

func (*CellView) Init

func (a *CellView) Init()

Init initializes a new CellView for use.

func (*CellView) MakeCursorVisible

func (a *CellView) MakeCursorVisible()

MakeCursorVisible ensures that the cursor is visible, panning the ViewPort as necessary, if the cursor is enabled.

func (*CellView) MakeVisible

func (a *CellView) MakeVisible(x, y int)

MakeVisible makes the given coordinates visible, if they are not already. It does this by moving the ViewPort for the CellView.

func (*CellView) Resize

func (a *CellView) Resize()

Resize is called when the View is resized. It will ensure that the cursor is visible, if present.

func (*CellView) SetCursor

func (a *CellView) SetCursor(x, y int)

SetCursor sets the the cursor position.

func (*CellView) SetCursorX

func (a *CellView) SetCursorX(x int)

SetCursorX sets the the cursor column.

func (*CellView) SetCursorY

func (a *CellView) SetCursorY(y int)

SetCursorY sets the the cursor row.

func (*CellView) SetModel

func (a *CellView) SetModel(model CellModel)

SetModel sets the model for this CellView.

func (*CellView) SetStyle

func (a *CellView) SetStyle(s tcell.Style)

SetStyle sets the the default fill style.

func (*CellView) SetView

func (a *CellView) SetView(view View)

SetView sets the View context.

func (*CellView) Size

func (a *CellView) Size() (int, int)

Size returns the content size, based on the model.

type EventWidget

type EventWidget interface {
	Widget() Widget
	tcell.Event
}

EventWidget is an event delivered by a specific widget.

type EventWidgetContent

type EventWidgetContent struct {
	// contains filtered or unexported fields
}

EventWidgetContent is fired whenever a widget's content changes.

func (*EventWidgetContent) SetWidget

func (wev *EventWidgetContent) SetWidget(widget Widget)

func (*EventWidgetContent) Widget

func (wev *EventWidgetContent) Widget() Widget

type EventWidgetMove

type EventWidgetMove struct {
	// contains filtered or unexported fields
}

EventWidgetMove is fired whenver a widget changes location.

func (*EventWidgetMove) SetWidget

func (wev *EventWidgetMove) SetWidget(widget Widget)

func (*EventWidgetMove) Widget

func (wev *EventWidgetMove) Widget() Widget

type EventWidgetResize

type EventWidgetResize struct {
	// contains filtered or unexported fields
}

EventWidgetResize is fired whenever a widget is resized.

func (*EventWidgetResize) SetWidget

func (wev *EventWidgetResize) SetWidget(widget Widget)

func (*EventWidgetResize) Widget

func (wev *EventWidgetResize) Widget() Widget

type Orientation

type Orientation int

Orientation represents the direction of a widget or layout.

type Panel

type Panel struct {
	BoxLayout
	// contains filtered or unexported fields
}

Panel is a modified Layout that includes a primary content pane, prefixed with an optional title, and an optional menubar, and then suffixed by an optional status.

Only the content pane is resizable. The panel will be formatted like this:

+----------
| title
| menu
| content....
| <padding>
| status
+----------

Each of these components may be any valid widget; their names are only meant to be indicative of conventional use, not prescriptive.

func NewPanel

func NewPanel() *Panel

NewPanel creates a new Panel. A zero valued panel can be created too.

func (*Panel) Draw

func (p *Panel) Draw()

Draw draws the Panel.

func (*Panel) SetContent

func (p *Panel) SetContent(w Widget)

SetContent sets the Widget to display in the content area.

func (*Panel) SetMenu

func (p *Panel) SetMenu(w Widget)

SetMenu sets the Widget to display in the menu area, which is just below the title.

func (*Panel) SetStatus

func (p *Panel) SetStatus(w Widget)

SetStatus sets the Widget to display in the status area, which is at the bottom of the panel.

func (*Panel) SetTitle

func (p *Panel) SetTitle(w Widget)

SetTitle sets the Widget to display in the title area.

type SimpleStyledText

type SimpleStyledText struct {
	Text
	// contains filtered or unexported fields
}

SimpleStyledText is a form of Text that offers highlighting of the text using simple in-line markup. Its intention is to make it easier to mark up hot // keys for menubars, etc.

func NewSimpleStyledText

func NewSimpleStyledText() *SimpleStyledText

NewSimpleStyledText creates an empty Text.

func (*SimpleStyledText) LookupStyle

func (t *SimpleStyledText) LookupStyle(r rune) tcell.Style

LookupStyle returns the style registered for the given rune. Returns tcell.StyleDefault if no style was previously registered for the rune.

func (*SimpleStyledText) Markup

func (t *SimpleStyledText) Markup() string

Markup returns the text that was set, including markup.

func (*SimpleStyledText) RegisterStyle

func (t *SimpleStyledText) RegisterStyle(r rune, style tcell.Style)

Registers a style for the given rune. This style will be used for text marked with %<r>. See SetMarkup() for more detail. Note that this must be done before using any of the styles with SetMarkup(). Only letters may be used when registering styles, and be advised that the system may have predefined uses for upper case letters.

func (*SimpleStyledText) SetMarkup

func (t *SimpleStyledText) SetMarkup(s string)

SetMarkup sets the text used for the string. It applies markup as follows (modeled on tcsh style prompt markup):

* %% - emit a single % in current style * %N - normal style * %A - alternate style * %S - start standout (reverse) style * %B - start bold style * %U - start underline style

Other styles can be set using %<rune>, if styles are registered. Upper case characters and punctuation are reserved for use by the system. Lower case are available for use by the user. (Users may define mappings for upper case letters to override system defined styles.)

Note that for simplicity, combining styles is not supported. By default the alternate style is the same as standout (reverse) mode.

Arguably we could have used Markdown syntax instead, but properly doing all of Markdown is not trivial, and these escape sequences make it clearer that we are not even attempting to do that.

type SimpleStyledTextBar

type SimpleStyledTextBar struct {
	BoxLayout
	// contains filtered or unexported fields
}

SimpleStyledTextBar is a Widget that provides a single line of text, but with distinct left, center, and right areas. Each of the areas can be styled differently, and can contain internal style markup. They align to the left, center, and right respectively. This is basically a convenience type on top SimpleStyledText and BoxLayout.

func NewSimpleStyledTextBar

func NewSimpleStyledTextBar() *SimpleStyledTextBar

NewSimpleStyledTextBar creates an empty, initialized TextBar.

func (*SimpleStyledTextBar) Init

func (s *SimpleStyledTextBar) Init()

Init prepares the widget for use, ensuring resources needed are allocated, etc.

func (*SimpleStyledTextBar) RegisterCenterStyle

func (s *SimpleStyledTextBar) RegisterCenterStyle(r rune, style tcell.Style)

func (*SimpleStyledTextBar) RegisterLeftStyle

func (s *SimpleStyledTextBar) RegisterLeftStyle(r rune, style tcell.Style)

func (*SimpleStyledTextBar) RegisterRightStyle

func (s *SimpleStyledTextBar) RegisterRightStyle(r rune, style tcell.Style)

func (*SimpleStyledTextBar) SetCenter

func (s *SimpleStyledTextBar) SetCenter(m string)

SetCenter sets the center text for the textbar. It is always centered.

func (*SimpleStyledTextBar) SetLeft

func (s *SimpleStyledTextBar) SetLeft(m string)

SetLeft sets the left text for the textbar. It is always left-aligned.

func (*SimpleStyledTextBar) SetRight

func (s *SimpleStyledTextBar) SetRight(m string)

SetRight sets the right text for the textbar. It is always right-aligned.

func (*SimpleStyledTextBar) Size

func (s *SimpleStyledTextBar) Size() (int, int)

type Spacer

type Spacer struct {
	WidgetWatchers
}

Spacer is a Widget that occupies no visible real-estate. It is useful to add this to layouts when expansion space is required. It expands as needed with blank space.

func NewSpacer

func NewSpacer() *Spacer

NewSpacer creates an empty Spacer. It's probably easier just to declare it directly.

func (*Spacer) Draw

func (*Spacer) Draw()

Draw is called to update the displayed content.

func (*Spacer) HandleEvent

func (*Spacer) HandleEvent(tcell.Event) bool

HandleEvent implements a tcell.EventHandler, but does nothing.

func (*Spacer) Resize

func (s *Spacer) Resize()

Resize is called when our View changes sizes.

func (*Spacer) SetView

func (*Spacer) SetView(View)

SetView sets the View object used for the text bar.

func (*Spacer) Size

func (*Spacer) Size() (int, int)

Size always returns 0, 0, since no size is ever *requird* to display nothing.

type Text

type Text struct {
	WidgetWatchers
	// contains filtered or unexported fields
}

Text is a Widget with containing a block of text, which can optionally be styled.

func NewText

func NewText() *Text

NewText creates an empty Text.

func (*Text) Alignment

func (t *Text) Alignment() Alignment

Alignment returns the alignment of the Text.

func (*Text) Draw

func (t *Text) Draw()

Draw draws the Text.

func (*Text) HandleEvent

func (t *Text) HandleEvent(tcell.Event) bool

HandleEvent implements a tcell.EventHandler, but does nothing.

func (*Text) Resize

func (t *Text) Resize()

Resize is called when our View changes sizes.

func (*Text) SetAlignment

func (t *Text) SetAlignment(align Alignment)

SetAlignment sets the alignment. Negative values indicate right justification, positive values are left, and zero indicates center aligned.

func (*Text) SetStyle

func (t *Text) SetStyle(style tcell.Style)

SetStyle sets the style used. This applies to every cell in the in the text.

func (*Text) SetStyleAt

func (t *Text) SetStyleAt(pos int, style tcell.Style)

SetStyleAt sets the style at the given rune index. Note that for strings containing combining characters, it is not possible to change the style at the position of the combining character, but those positions *do* count for calculating the index. A lot of complexity can be avoided by avoiding the use of combining characters.

func (*Text) SetText

func (t *Text) SetText(s string)

SetText sets the text used for the string. Any previously set styles on individual rune indices are reset, and the default style for the widget is set.

func (*Text) SetView

func (t *Text) SetView(view View)

SetView sets the View object used for the text bar.

func (*Text) Size

func (t *Text) Size() (int, int)

Size returns the width and height in character cells of the Text.

func (*Text) Style

func (t *Text) Style() tcell.Style

Style returns the previously set default style. Note that individual characters may have different styles.

func (*Text) StyleAt

func (t *Text) StyleAt(pos int) tcell.Style

StyleAt gets the style at the given rune index. If an invalid index is given, or the index is a combining character, then tcell.StyleDefault is returned.

func (*Text) Text

func (t *Text) Text() string

Text returns the text that was set.

type TextArea

type TextArea struct {
	CellView
	// contains filtered or unexported fields
}

TextArea is a pannable 2 dimensional text widget. It wraps both the view and the model for text in a single, convenient widget. Text is provided as an array of strings, each of which represents a single line to display. All text in the TextArea has the same style. An optional soft cursor is available.

func NewTextArea

func NewTextArea() *TextArea

NewTextArea creates a blank TextArea.

func (*TextArea) EnableCursor

func (ta *TextArea) EnableCursor(on bool)

EnableCursor enables a soft cursor in the TextArea.

func (*TextArea) HideCursor

func (ta *TextArea) HideCursor(on bool)

HideCursor hides or shows the cursor in the TextArea. If on is true, the cursor is hidden. Note that a cursor is only shown if it is enabled.

func (*TextArea) Init

func (ta *TextArea) Init()

Init initializes the TextArea.

func (*TextArea) SetContent

func (ta *TextArea) SetContent(text string)

SetContent is used to set the textual content, passed as a single string. Lines within the string are delimited by newlines.

func (*TextArea) SetLines

func (ta *TextArea) SetLines(lines []string)

SetLines sets the content text to display.

func (*TextArea) SetStyle

func (ta *TextArea) SetStyle(style tcell.Style)

type TextBar

type TextBar struct {
	WidgetWatchers
	// contains filtered or unexported fields
}

TextBar is a Widget that provides a single line of text, but with distinct left, center, and right areas. Each of the areas can be styled differently, and they align to the left, center, and right respectively. This is basically a convenience type on top Text and BoxLayout.

func NewTextBar

func NewTextBar() *TextBar

NewTextBar creates an empty, initialized TextBar.

func (*TextBar) Draw

func (t *TextBar) Draw()

Draw draws the TextBar into its View context.

func (*TextBar) HandleEvent

func (t *TextBar) HandleEvent(ev tcell.Event) bool

HandleEvent handles incoming events. The only events handled are those for the Text objects; when those change, the TextBar adjusts the layout to accommodate.

func (*TextBar) Resize

func (t *TextBar) Resize()

Resize is called when the TextBar's View changes size, and updates the layout.

func (*TextBar) SetCenter

func (t *TextBar) SetCenter(s string, style tcell.Style)

SetCenter sets the center text for the textbar. The text is always center aligned.

func (*TextBar) SetLeft

func (t *TextBar) SetLeft(s string, style tcell.Style)

SetLeft sets the left text for the textbar. It is always left-aligned.

func (*TextBar) SetRight

func (t *TextBar) SetRight(s string, style tcell.Style)

SetRight sets the right text for the textbar. It is always right-aligned.

func (*TextBar) SetStyle

func (t *TextBar) SetStyle(style tcell.Style)

SetStyle is used to set a default style to use for the textbar, including areas where no text is present. Note that this will not change the text already displayed, so call this before changing or setting text.

func (*TextBar) SetView

func (t *TextBar) SetView(view View)

SetView sets the View drawing context for this TextBar.

func (*TextBar) Size

func (t *TextBar) Size() (int, int)

Size implements the Size method for Widget, returning the width and height in character cells.

type View

type View interface {
	// SetContent is used to update the content of the View at the given
	// location.  This will generally be called by the Draw() method of
	// a Widget.
	SetContent(x int, y int, ch rune, comb []rune, style tcell.Style)

	// Size represents the visible size.  The actual content may be
	// larger or smaller.
	Size() (int, int)

	// Resize tells the View that its visible dimensions have changed.
	// It also tells it that it has a new offset relative to any parent
	// view.
	Resize(x, y, width, height int)

	// Fill fills the displayed content with the given rune and style.
	Fill(rune, tcell.Style)

	// Clear clears the content.  Often just Fill(' ', tcell.StyleDefault)
	Clear()
}

View represents a logical view on an area. It will have some underlying physical area as well, generally. Views are operated on by Widgets.

type ViewPort

type ViewPort struct {
	// contains filtered or unexported fields
}

ViewPort is an implementation of a View, that provides a smaller logical view of larger content area. For example, a scrollable window of text, the visible window would be the ViewPort, on the underlying content. ViewPorts have a two dimensional size, and a two dimensional offset.

In some ways, as the underlying content is not kept persistently by the view port, it can be thought perhaps a little more precisely as a clipping region.

func NewViewPort

func NewViewPort(view View, x, y, width, height int) *ViewPort

NewViewPort returns a new ViewPort (and hence also a View). The x and y coordinates are an offset relative to the parent. The origin 0,0 represents the upper left. The width and height indicate a width and height. If the value -1 is supplied, then the dimension is calculated from the parent.

func (*ViewPort) Center

func (v *ViewPort) Center(x, y int)

Center centers the point, if possible, in the View.

func (*ViewPort) Clear

func (v *ViewPort) Clear()

Clear clears the displayed content, filling it with spaces of default text attributes.

func (*ViewPort) Fill

func (v *ViewPort) Fill(ch rune, style tcell.Style)

Fill fills the displayed view port with the given character and style.

func (*ViewPort) GetContentSize

func (v *ViewPort) GetContentSize() (int, int)

GetContentSize returns the size of content as width, height in character cells.

func (*ViewPort) GetPhysical

func (v *ViewPort) GetPhysical() (int, int, int, int)

GetPhysical returns the upper left and lower right coordinates of the visible content in the coordinate space of the parent. This is may be the physical coordinates of the screen, if the screen is the view's parent.

func (*ViewPort) GetVisible

func (v *ViewPort) GetVisible() (int, int, int, int)

GetVisible returns the upper left and lower right coordinates of the visible content. That is, it will return x1, y1, x2, y2 where the upper left cell is position x1, y1, and the lower right is x2, y2. These coordinates are in the space of the content, that is the content area uses coordinate 0,0 as its first cell position.

func (*ViewPort) MakeVisible

func (v *ViewPort) MakeVisible(x, y int)

MakeVisible moves the ViewPort the minimum necessary to make the given point visible. This should be called before any content is changed with SetContent, since otherwise it may be possible to move the location onto a region whose contents have been discarded.

func (*ViewPort) Reset

func (v *ViewPort) Reset()

Reset resets the record of content, and also resets the offset back to the origin. It doesn't alter the dimensions of the view port, nor the physical location relative to its parent.

func (*ViewPort) Resize

func (v *ViewPort) Resize(x, y, width, height int)

Resize is called by the enclosing view to change the size of the ViewPort, usually in response to a window resize event. The x, y refer are the ViewPort's location relative to the parent View. A negative value for either width or height will cause the ViewPort to expand to fill to the end of parent View in the relevant dimension.

func (*ViewPort) ScrollDown

func (v *ViewPort) ScrollDown(rows int)

ScrollDown moves the view down, showingh higher numbered rows of content.

func (*ViewPort) ScrollLeft

func (v *ViewPort) ScrollLeft(cols int)

ScrollLeft moves the view to the left.

func (*ViewPort) ScrollRight

func (v *ViewPort) ScrollRight(cols int)

ScrollRight moves the view to the left.

func (*ViewPort) ScrollUp

func (v *ViewPort) ScrollUp(rows int)

ScrollUp moves the view up, showing lower numbered rows of content.

func (*ViewPort) SetContent

func (v *ViewPort) SetContent(x, y int, ch rune, comb []rune, s tcell.Style)

SetContent is used to place data at the given cell location. Note that since the ViewPort doesn't retain this data, if the location is outside of the visible area, it is simply discarded.

Generally, this is called during the Draw() phase by the object that represents the content.

func (*ViewPort) SetContentSize

func (v *ViewPort) SetContentSize(width, height int, locked bool)

SetContentSize sets the size of the content area; this is used to limit scrolling and view moment. If locked is true, then the content size will not automatically grow even if content is placed outside of this area with the SetContent() method. If false, and content is drawn outside of the existing size, then the size will automatically grow to include the new content.

func (*ViewPort) SetSize

func (v *ViewPort) SetSize(width, height int)

SetSize is used to set the visible size of the view. Enclosing views or layout managers can use this to inform the View of its correct visible size.

func (*ViewPort) SetView

func (v *ViewPort) SetView(view View)

SetView is called during setup, to provide the parent View.

func (*ViewPort) Size

func (v *ViewPort) Size() (int, int)

Size returns the visible size of the ViewPort in character cells.

func (*ViewPort) ValidateView

func (v *ViewPort) ValidateView()

ValidateView does both ValidateViewX and ValidateViewY, ensuring both offsets are valid.

func (*ViewPort) ValidateViewX

func (v *ViewPort) ValidateViewX()

ValidateViewX ensures that the X offset of the view port is limited so that it cannot scroll away from the content.

func (*ViewPort) ValidateViewY

func (v *ViewPort) ValidateViewY()

ValidateViewY ensures that the Y offset of the view port is limited so that it cannot scroll away from the content.

type Widget

type Widget interface {
	// Draw is called to inform the widget to draw itself.  A containing
	// Widget will generally call this during the application draw loop.
	Draw()

	// Resize is called in response to a resize of the View.  Unlike with
	// other events, Resize performed by parents first, and they must
	// then call their children.  This is because the children need to
	// see the updated sizes from the parents before they are called.
	// In general this is done *after* the views have updated.
	Resize()

	// HandleEvent is called to ask the widget to handle any events.
	// If the widget has consumed the event, it should return true.
	// Generally, events are handled by the lower layers first, that
	// is for example, a button may have a chance to handle an event
	// before the enclosing window or panel.
	//
	// Its expected that Resize events are consumed by the outermost
	// Widget, and the turned into a Resize() call.
	HandleEvent(ev tcell.Event) bool

	// SetView is used by callers to set the visual context of the
	// Widget.  The Widget should use the View as a context for
	// drawing.
	SetView(view View)

	// Size returns the size of the widget (content size) as width, height
	// in columns.  Layout managers should attempt to ensure that at least
	// this much space is made available to the View for this Widget.  Extra
	// space may be allocated on as an needed basis.
	Size() (int, int)

	// Watch is used to register an interest in this widget's events.
	// The handler will receive EventWidget events for this widget.
	// The order of event delivery when there are multiple watchers is
	// not specified, and may change from one event to the next.
	Watch(handler tcell.EventHandler)

	// Unwatch is used to urnegister an interest in this widget's events.
	Unwatch(handler tcell.EventHandler)
}

Widget is the base object that all onscreen elements implement.

type WidgetWatchers

type WidgetWatchers struct {
	// contains filtered or unexported fields
}

WidgetWatchers provides a common implementation for base Widget Watch and Unwatch interfaces, suitable for embedding in more concrete widget implementations.

func (*WidgetWatchers) PostEvent

func (ww *WidgetWatchers) PostEvent(wev EventWidget)

PostEvent delivers the EventWidget to all registered watchers. It is to be called by the Widget implementation.

func (*WidgetWatchers) PostEventWidgetContent

func (ww *WidgetWatchers) PostEventWidgetContent(w Widget)

PostEventWidgetContent is called by the Widget when its content is changed, delivering EventWidgetContent to all watchers.

func (*WidgetWatchers) PostEventWidgetMove

func (ww *WidgetWatchers) PostEventWidgetMove(w Widget)

PostEventWidgetMove is called by the Widget when it is moved to a new location, delivering EventWidgetMove to all watchers.

func (*WidgetWatchers) PostEventWidgetResize

func (ww *WidgetWatchers) PostEventWidgetResize(w Widget)

PostEventWidgetResize is called by the Widget when the underlying View has resized, delivering EventWidgetResize to all watchers.

func (*WidgetWatchers) Unwatch

func (ww *WidgetWatchers) Unwatch(handler tcell.EventHandler)

Unwatch stops monitoring this WidgetWatcher. The handler will no longer be fired for Widget events.

func (*WidgetWatchers) Watch

func (ww *WidgetWatchers) Watch(handler tcell.EventHandler)

Watch monitors this WidgetWatcher, causing the handler to be fired with EventWidget as they are occur on the watched Widget.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL