Documentation
¶
Overview ¶
Package texteditor provides widgets and helpers shared by the text-editing example applications.
Index ¶
- func Hotkey(context *guigui.Context, key string) string
- func HotkeyShift(context *guigui.Context, key string) string
- func OpenFileAsync(filter *FileFilter) <-chan FileResult
- func SaveFileAsync(suggested string) <-chan FileResult
- func ShortcutModifierPressed(context *guigui.Context) bool
- type ConfirmDialog
- func (c *ConfirmDialog) Build(context *guigui.Context, adder *guigui.ChildAdder) error
- func (c *ConfirmDialog) IsOpen() bool
- func (c *ConfirmDialog) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, ...)
- func (c *ConfirmDialog) OnClose(fn func(context *guigui.Context, result ConfirmResult))
- func (c *ConfirmDialog) SetMessage(message string)
- func (c *ConfirmDialog) SetOpen(open bool)
- func (c *ConfirmDialog) SetSaveEnabled(enabled bool)
- type ConfirmResult
- type Document
- func (d *Document) DisplayName() string
- func (d *Document) IsDirty() bool
- func (d *Document) LoadInto(path string, dst io.ReaderFrom) error
- func (d *Document) MarkDirty()
- func (d *Document) New()
- func (d *Document) Path() string
- func (d *Document) Save(src io.WriterTo) error
- func (d *Document) SaveAs(path string, src io.WriterTo) error
- type Editor
- type ExtraMenu
- type FileFilter
- type FileResult
- type FindDialog
- func (f *FindDialog) Build(context *guigui.Context, adder *guigui.ChildAdder) error
- func (f *FindDialog) FindNext(e *Editor, query string)
- func (f *FindDialog) FindPrev(e *Editor, query string)
- func (f *FindDialog) IsOpen() bool
- func (f *FindDialog) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, ...)
- func (f *FindDialog) OnClose(fn func(context *guigui.Context))
- func (f *FindDialog) OnFindNext(fn func(context *guigui.Context, query string))
- func (f *FindDialog) OnFindPrev(fn func(context *guigui.Context, query string))
- func (f *FindDialog) OnQueryChanged(fn func(context *guigui.Context, query string))
- func (f *FindDialog) Query() string
- func (f *FindDialog) SetCount(current, total int)
- func (f *FindDialog) SetOpen(open bool)
- func (f *FindDialog) UpdateCount(e *Editor)
- type Menubar
- func (m *Menubar) Build(context *guigui.Context, adder *guigui.ChildAdder) error
- func (m *Menubar) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, ...)
- func (m *Menubar) Measure(context *guigui.Context, constraints guigui.Constraints) image.Point
- func (m *Menubar) OnCopy(fn func(context *guigui.Context))
- func (m *Menubar) OnCut(fn func(context *guigui.Context))
- func (m *Menubar) OnExtraItemSelected(fn func(context *guigui.Context, value string))
- func (m *Menubar) OnFind(fn func(context *guigui.Context))
- func (m *Menubar) OnNew(fn func(context *guigui.Context))
- func (m *Menubar) OnOpen(fn func(context *guigui.Context))
- func (m *Menubar) OnPaste(fn func(context *guigui.Context))
- func (m *Menubar) OnPasteWithoutStyles(fn func(context *guigui.Context))
- func (m *Menubar) OnRedo(fn func(context *guigui.Context))
- func (m *Menubar) OnSave(fn func(context *guigui.Context))
- func (m *Menubar) OnSaveAs(fn func(context *guigui.Context))
- func (m *Menubar) OnSelectAll(fn func(context *guigui.Context))
- func (m *Menubar) OnUndo(fn func(context *guigui.Context))
- func (m *Menubar) SetCanCopy(b bool)
- func (m *Menubar) SetCanCut(b bool)
- func (m *Menubar) SetCanPaste(b bool)
- func (m *Menubar) SetCanRedo(b bool)
- func (m *Menubar) SetCanSave(b bool)
- func (m *Menubar) SetCanSaveAs(b bool)
- func (m *Menubar) SetCanUndo(b bool)
- func (m *Menubar) SetExtraMenus(menus []ExtraMenu)
- func (m *Menubar) SetPasteWithoutStylesVisible(visible bool)
- type StatusBar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HotkeyShift ¶
HotkeyShift returns the display label of a shortcut with the Shift and the shortcut modifier.
func OpenFileAsync ¶
func OpenFileAsync(filter *FileFilter) <-chan FileResult
OpenFileAsync shows a native open dialog on a new goroutine and delivers the result on the returned channel. A nil filter offers all files.
func SaveFileAsync ¶
func SaveFileAsync(suggested string) <-chan FileResult
SaveFileAsync shows a native save dialog on a new goroutine and delivers the result on the returned channel. A non-empty suggested is the pre-filled file name.
func ShortcutModifierPressed ¶
ShortcutModifierPressed reports whether the modifier key that carries application shortcuts is pressed.
Types ¶
type ConfirmDialog ¶
type ConfirmDialog struct {
guigui.DefaultWidget
// contains filtered or unexported fields
}
ConfirmDialog is the in-app modal "you have unsaved changes" prompt with the standard Save / Don't save / Cancel triad. Using Guigui widgets keeps everything on the main goroutine, sidestepping the macOS dispatch-queue timing issue that affects native dialogs called from a non-main goroutine.
func (*ConfirmDialog) Build ¶
func (c *ConfirmDialog) Build(context *guigui.Context, adder *guigui.ChildAdder) error
func (*ConfirmDialog) IsOpen ¶
func (c *ConfirmDialog) IsOpen() bool
IsOpen reports whether the dialog is currently shown.
func (*ConfirmDialog) Layout ¶
func (c *ConfirmDialog) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)
func (*ConfirmDialog) OnClose ¶
func (c *ConfirmDialog) OnClose(fn func(context *guigui.Context, result ConfirmResult))
OnClose registers the handler that fires whenever the dialog closes, reporting which button the user picked.
func (*ConfirmDialog) SetMessage ¶
func (c *ConfirmDialog) SetMessage(message string)
SetMessage sets the prompt text shown above the buttons.
func (*ConfirmDialog) SetOpen ¶
func (c *ConfirmDialog) SetOpen(open bool)
SetOpen shows or hides the dialog. Opening also resets the pending result to Cancel so a previous selection that didn't get dispatched can't leak.
func (*ConfirmDialog) SetSaveEnabled ¶
func (c *ConfirmDialog) SetSaveEnabled(enabled bool)
SetSaveEnabled sets whether the save choice can be chosen.
type ConfirmResult ¶
type ConfirmResult int
ConfirmResult identifies how the user dismissed a ConfirmDialog. The zero value is ConfirmResultCancel so that an outside click or any close path that doesn't go through a button reports as cancellation.
const ( ConfirmResultCancel ConfirmResult = iota ConfirmResultSave ConfirmResultDontSave )
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document tracks the file path and the dirty state of an edited file.
func (*Document) DisplayName ¶
DisplayName returns the file name, or "Untitled" for an untitled document.
func (*Document) LoadInto ¶
func (d *Document) LoadInto(path string, dst io.ReaderFrom) error
LoadInto opens the file at path and streams its contents into dst. On success the document's path is updated and dirty is cleared.
func (*Document) MarkDirty ¶
func (d *Document) MarkDirty()
MarkDirty marks the document as having unsaved changes.
type Editor ¶
type Editor struct {
basicwidget.TextInput
}
Editor wraps basicwidget.TextInput so that *Editor satisfies io.WriterTo and io.ReaderFrom. The document layer can then stream through stdlib interfaces without basicwidget itself having to use those names.
type ExtraMenu ¶
type ExtraMenu struct {
// Text is the menu's title in the menubar.
Text string
// Items are the menu's popup items. Their values are reported as-is by
// the handler set by [Menubar.OnExtraItemSelected].
Items []basicwidget.PopupMenuItem[string]
// ReservesCheckmarkSpace indents the items so that toggling a checkmark
// does not shift their texts.
ReservesCheckmarkSpace bool
}
ExtraMenu is an application-specific menu shown after the built-in menus.
type FileFilter ¶
type FileFilter struct {
// Description is the human-readable name of the filter.
Description string
// Extensions is the list of file extensions without the leading dot.
Extensions []string
}
FileFilter restricts the files an open dialog offers.
type FileResult ¶
type FileResult struct {
// Path is the selected file path when the dialog was confirmed.
Path string
// Cancelled reports whether the user dismissed the dialog.
Cancelled bool
// Err is the error the dialog failed with, if any.
Err error
}
FileResult is the outcome of an asynchronous file dialog.
type FindDialog ¶
type FindDialog struct {
guigui.DefaultWidget
// contains filtered or unexported fields
}
FindDialog is the non-modal find popup docked to the top-end corner, with a query input, a match-count display, previous/next buttons, and a close button.
func (*FindDialog) Build ¶
func (f *FindDialog) Build(context *guigui.Context, adder *guigui.ChildAdder) error
func (*FindDialog) FindNext ¶
func (f *FindDialog) FindNext(e *Editor, query string)
FindNext selects the occurrence of query in e that follows the current selection, wrapping around to the first occurrence, and updates the count display.
func (*FindDialog) FindPrev ¶
func (f *FindDialog) FindPrev(e *Editor, query string)
FindPrev selects the occurrence of query in e that precedes the current selection, wrapping around to the last occurrence, and updates the count display.
func (*FindDialog) IsOpen ¶
func (f *FindDialog) IsOpen() bool
IsOpen reports whether the dialog is currently shown.
func (*FindDialog) Layout ¶
func (f *FindDialog) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)
func (*FindDialog) OnClose ¶
func (f *FindDialog) OnClose(fn func(context *guigui.Context))
OnClose registers the handler that fires after the popup closes.
func (*FindDialog) OnFindNext ¶
func (f *FindDialog) OnFindNext(fn func(context *guigui.Context, query string))
OnFindNext registers the handler for the down-arrow button (and Enter on the query input). The handler receives the current query string.
func (*FindDialog) OnFindPrev ¶
func (f *FindDialog) OnFindPrev(fn func(context *guigui.Context, query string))
OnFindPrev registers the handler for the up-arrow button (and Shift+Enter on the query input).
func (*FindDialog) OnQueryChanged ¶
func (f *FindDialog) OnQueryChanged(fn func(context *guigui.Context, query string))
OnQueryChanged registers the handler that fires whenever the query input changes value, even mid-typing.
func (*FindDialog) Query ¶
func (f *FindDialog) Query() string
Query returns the current query string.
func (*FindDialog) SetCount ¶
func (f *FindDialog) SetCount(current, total int)
SetCount displays the current match index (1-based) and the total number of matches. Pass total = 0 to clear the count display.
func (*FindDialog) SetOpen ¶
func (f *FindDialog) SetOpen(open bool)
SetOpen shows or hides the dialog. Showing it also moves the focus to the query input.
func (*FindDialog) UpdateCount ¶
func (f *FindDialog) UpdateCount(e *Editor)
UpdateCount recomputes the "n of total" display from the dialog's current query and e's current selection.
type Menubar ¶
type Menubar struct {
guigui.DefaultWidget
// contains filtered or unexported fields
}
Menubar is an editor application's menubar widget. It wraps basicwidget.Menubar with the File and Edit menus common to the editor examples and exposes typed event handlers (OnNew, OnOpen, ...) so that an application can register actions without dealing with menu/item indices.
func (*Menubar) Layout ¶
func (m *Menubar) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)
func (*Menubar) OnExtraItemSelected ¶
OnExtraItemSelected sets the event handler invoked when an item of a menu set by Menubar.SetExtraMenus is selected. value is the selected item's value.
func (*Menubar) OnPasteWithoutStyles ¶
OnPasteWithoutStyles sets the event handler invoked when the Paste Without Styles item is selected.
func (*Menubar) OnSaveAs ¶
OnSaveAs sets the event handler invoked when the Save As item is selected.
func (*Menubar) OnSelectAll ¶
OnSelectAll sets the event handler invoked when the Select All item is selected.
func (*Menubar) SetCanCopy ¶
SetCanCopy enables or disables the Copy item.
func (*Menubar) SetCanPaste ¶
SetCanPaste enables or disables the Paste item.
func (*Menubar) SetCanRedo ¶
SetCanRedo enables or disables the Redo item.
func (*Menubar) SetCanSave ¶
SetCanSave enables or disables the Save item.
func (*Menubar) SetCanSaveAs ¶
SetCanSaveAs enables or disables the Save As item.
func (*Menubar) SetCanUndo ¶
SetCanUndo enables or disables the Undo item.
func (*Menubar) SetExtraMenus ¶
SetExtraMenus sets the application-specific menus shown after the built-in menus.
func (*Menubar) SetPasteWithoutStylesVisible ¶
SetPasteWithoutStylesVisible sets whether the Edit menu has a Paste Without Styles item. The item is absent by default.
type StatusBar ¶
type StatusBar struct {
guigui.DefaultWidget
// contains filtered or unexported fields
}
StatusBar displays the caret position of an editor.
func (*StatusBar) Layout ¶
func (s *StatusBar) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)
func (*StatusBar) SetPosition ¶
SetPosition sets the displayed caret position. line and column are 1-based display values; the column unit is the caller's choice.