Documentation
¶
Overview ¶
Package FyneCodeEditorWidget provides a powerful, customizable code editor widget for Fyne applications.
This package implements a script editor with syntax highlighting, VS Code-style themes, and comprehensive editing capabilities. It supports multiple programming languages and allows for extensive customization of appearance and behavior.
Key Features:
- Syntax highlighting for Go, Python, JavaScript, Java, C/C++, and more
- VS Code-style color themes with JSON support
- Customizable font size, tab size, and line numbers
- Full keyboard navigation and text editing
- Extensible architecture for adding new languages and themes
Basic Usage:
editor := FyneCodeEditorWidget.NewScriptEditor()
editor.SetLanguage("go")
editor.SetTheme(FyneCodeEditorWidget.GetDefaultTheme())
editor.SetContent("package main\n\nfunc main() {\n\t// Your code here\n}")
The widget follows Fyne's standard architecture with separate Widget and WidgetRenderer interfaces. The lexer provides tokenization for syntax highlighting, while the theme system allows for comprehensive color customization.
For complete examples and documentation, see the README.md file and example.go.
Index ¶
- func Example()
- func GetBuiltinThemes() map[string]*Theme
- func SaveThemeToJSON(theme *Theme, filepath string) error
- type Lexer
- type LexerRule
- type ScriptEditor
- func (e *ScriptEditor) CreateRenderer() fyne.WidgetRenderer
- func (e *ScriptEditor) Focusable() bool
- func (e *ScriptEditor) GetContent() string
- func (e *ScriptEditor) GetFontSize() float32
- func (e *ScriptEditor) GetLanguage() string
- func (e *ScriptEditor) GetShowLineNumbers() bool
- func (e *ScriptEditor) GetTabSize() int
- func (e *ScriptEditor) GetTheme() *Theme
- func (e *ScriptEditor) SetContent(content string)
- func (e *ScriptEditor) SetFontSize(size float32)
- func (e *ScriptEditor) SetLanguage(language string)
- func (e *ScriptEditor) SetOnChanged(callback func(string))
- func (e *ScriptEditor) SetShowLineNumbers(show bool)
- func (e *ScriptEditor) SetTabSize(size int)
- func (e *ScriptEditor) SetTheme(theme *Theme)
- func (e *ScriptEditor) TypedKey(key *fyne.KeyEvent)
- func (e *ScriptEditor) TypedRune(r rune)
- type Theme
- type ThemeDefinition
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBuiltinThemes ¶
GetBuiltinThemes returns all built-in themes
func SaveThemeToJSON ¶
SaveThemeToJSON saves a theme to a JSON file
Types ¶
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer handles tokenization of source code for syntax highlighting
type LexerRule ¶
type LexerRule struct {
Pattern *regexp.Regexp
TokenType TokenType
Priority int // Higher priority rules are checked first
}
LexerRule defines a pattern and token type for lexical analysis
type ScriptEditor ¶
type ScriptEditor struct {
widget.BaseWidget
// contains filtered or unexported fields
}
ScriptEditor is a custom Fyne widget for code editing with syntax highlighting
func CreateCodeEditor ¶
func CreateCodeEditor(language string, theme *Theme) *ScriptEditor
CreateCodeEditor is a convenience function to create a new code editor with default settings
func CreateCodeEditorWithContent ¶
func CreateCodeEditorWithContent(content, language string, theme *Theme) *ScriptEditor
CreateCodeEditorWithContent creates a new code editor with initial content
func NewScriptEditor ¶
func NewScriptEditor() *ScriptEditor
NewScriptEditor creates a new script editor widget
func (*ScriptEditor) CreateRenderer ¶
func (e *ScriptEditor) CreateRenderer() fyne.WidgetRenderer
CreateRenderer creates the custom renderer for the script editor
func (*ScriptEditor) Focusable ¶
func (e *ScriptEditor) Focusable() bool
Focusable makes the editor focusable
func (*ScriptEditor) GetContent ¶
func (e *ScriptEditor) GetContent() string
GetContent returns the current content of the editor
func (*ScriptEditor) GetFontSize ¶
func (e *ScriptEditor) GetFontSize() float32
GetFontSize returns the current font size
func (*ScriptEditor) GetLanguage ¶
func (e *ScriptEditor) GetLanguage() string
GetLanguage returns the current programming language
func (*ScriptEditor) GetShowLineNumbers ¶
func (e *ScriptEditor) GetShowLineNumbers() bool
GetShowLineNumbers returns whether line numbers are shown
func (*ScriptEditor) GetTabSize ¶
func (e *ScriptEditor) GetTabSize() int
GetTabSize returns the current tab size
func (*ScriptEditor) GetTheme ¶
func (e *ScriptEditor) GetTheme() *Theme
GetTheme returns the current theme
func (*ScriptEditor) SetContent ¶
func (e *ScriptEditor) SetContent(content string)
SetContent sets the content of the editor
func (*ScriptEditor) SetFontSize ¶
func (e *ScriptEditor) SetFontSize(size float32)
SetFontSize sets the font size for the editor
func (*ScriptEditor) SetLanguage ¶
func (e *ScriptEditor) SetLanguage(language string)
SetLanguage sets the programming language for syntax highlighting
func (*ScriptEditor) SetOnChanged ¶
func (e *ScriptEditor) SetOnChanged(callback func(string))
SetOnChanged sets the callback function for content changes
func (*ScriptEditor) SetShowLineNumbers ¶
func (e *ScriptEditor) SetShowLineNumbers(show bool)
SetShowLineNumbers enables or disables line number display
func (*ScriptEditor) SetTabSize ¶
func (e *ScriptEditor) SetTabSize(size int)
SetTabSize sets the tab size for indentation
func (*ScriptEditor) SetTheme ¶
func (e *ScriptEditor) SetTheme(theme *Theme)
SetTheme sets the color theme for the editor
func (*ScriptEditor) TypedKey ¶
func (e *ScriptEditor) TypedKey(key *fyne.KeyEvent)
TypedKey handles special key presses
func (*ScriptEditor) TypedRune ¶
func (e *ScriptEditor) TypedRune(r rune)
TypedRune handles typed characters
type Theme ¶
type Theme struct {
Name string
Background color.Color
Foreground color.Color
TokenColors map[TokenType]color.Color
}
Theme represents a color theme for syntax highlighting
func GetDefaultTheme ¶
func GetDefaultTheme() *Theme
GetDefaultTheme returns the default dark theme for the editor
func GetVSCodeDarkTheme ¶
func GetVSCodeDarkTheme() *Theme
GetVSCodeDarkTheme returns a VS Code dark theme
func LoadThemeFromJSON ¶
LoadThemeFromJSON loads a theme from a JSON file
type ThemeDefinition ¶
type ThemeDefinition struct {
Name string `json:"name"`
Background string `json:"background"`
Foreground string `json:"foreground"`
TokenColors map[string]string `json:"tokenColors"`
}
ThemeDefinition represents a theme definition for JSON loading
type TokenType ¶
type TokenType string
TokenType represents different types of syntax tokens
const ( TokenKeyword TokenType = "keyword" TokenString TokenType = "string" TokenComment TokenType = "comment" TokenNumber TokenType = "number" TokenOperator TokenType = "operator" TokenIdentifier TokenType = "identifier" TokenFunction TokenType = "function" TokenType_ TokenType = "type" TokenPlain TokenType = "plain" )