Documentation
¶
Overview ¶
Package rosaline makes small graphical Go applications easy to build.
The package deliberately keeps window setup, the event loop, layout, and the platform backend out of beginner programs. A complete application can be as small as:
rosaline.Run(rosaline.Label("Hello, world!"))
Use RunApp when you want to set the title, initial window size, or theme. TextBox, TextArea, and CheckBox bind directly to ordinary Go variables. Canvas mouse callbacks make drawing programs interactive without exposing platform event types. Images, scroll areas, menus, and file dialogs provide the groundwork for complete desktop applications while ordinary file I/O remains normal Go. App-owned timers support delayed work, repeating updates, and canvas animation without exposing the private event loop.
Index ¶
- Variables
- func Confirm(title, text string) bool
- func Error(title, text string)
- func Message(title, text string)
- func OpenFileDialog(options FileDialogOptions) (path string, ok bool)
- func Quit()
- func Run(content Widget)
- func RunApp(app App)
- func SaveFileDialog(options FileDialogOptions) (path string, ok bool)
- type App
- type AppMenu
- type AppMenuBar
- type Box
- type ButtonWidget
- type CanvasWidget
- func (c *CanvasWidget) Background(color Color) *CanvasWidget
- func (c *CanvasWidget) Expand() *CanvasWidget
- func (c *CanvasWidget) OnMouseDown(handler func(MouseEvent)) *CanvasWidget
- func (c *CanvasWidget) OnMouseMove(handler func(MouseEvent)) *CanvasWidget
- func (c *CanvasWidget) OnMouseUp(handler func(MouseEvent)) *CanvasWidget
- func (c *CanvasWidget) Redraw()
- func (c *CanvasWidget) Size(width, height int) *CanvasWidget
- type CheckBoxWidget
- type Color
- type DrawingCanvas
- func (c *DrawingCanvas) Circle(x, y, radius, stroke float64, color Color)
- func (c *DrawingCanvas) Clear(color Color)
- func (c *DrawingCanvas) FillCircle(x, y, radius float64, color Color)
- func (c *DrawingCanvas) FillRect(x, y, width, height float64, color Color)
- func (c *DrawingCanvas) Line(x1, y1, x2, y2, stroke float64, color Color)
- func (c *DrawingCanvas) Rect(x, y, width, height, stroke float64, color Color)
- func (c *DrawingCanvas) Text(text string, x, y float64, style TextStyle)
- type FileDialogOptions
- type FileFilter
- type ImageWidget
- type LabelWidget
- type MenuAction
- type MenuEntry
- type MouseButton
- type MouseEvent
- type Picture
- type ScrollWidget
- type State
- type TextAreaWidget
- type TextBoxWidget
- func (t *TextBoxWidget) Focus() *TextBoxWidget
- func (t *TextBoxWidget) OnChange(handler func(string)) *TextBoxWidget
- func (t *TextBoxWidget) OnSubmit(handler func(string)) *TextBoxWidget
- func (t *TextBoxWidget) Password() *TextBoxWidget
- func (t *TextBoxWidget) Placeholder(text string) *TextBoxWidget
- func (t *TextBoxWidget) Width(columns int) *TextBoxWidget
- type TextStyle
- type Theme
- type Timer
- type Widget
Constants ¶
This section is empty.
Variables ¶
var ( Black = RGB(0, 0, 0) White = RGB(255, 255, 255) Rose = Hex("#d64f8c") SoftRose = Hex("#f4a6c8") Transparent = RGBA(0, 0, 0, 0) )
var DefaultTheme = Theme{ Background: Hex("#fff8fc"), Surface: Hex("#ffffff"), Primary: Hex("#c43f7a"), Text: Hex("#2a1722"), Muted: Hex("#7d6874"), Border: Hex("#d9b8ca"), Danger: Hex("#b4234d"), Success: Hex("#267a50"), }
DefaultTheme is Rosaline's light rose theme.
Functions ¶
func OpenFileDialog ¶
func OpenFileDialog(options FileDialogOptions) (path string, ok bool)
OpenFileDialog asks the user to choose one existing file. ok is false when the user cancels the dialog.
func Run ¶
func Run(content Widget)
Run opens a window containing content using beginner-friendly defaults.
func SaveFileDialog ¶
func SaveFileDialog(options FileDialogOptions) (path string, ok bool)
SaveFileDialog asks the user where to save a file. ok is false when the user cancels. Existing files require confirmation before they are returned.
Types ¶
type App ¶
type App struct {
Title string
Width int
Height int
Padding int
Theme Theme
Menu *AppMenuBar
Timers []*Timer
Content Widget
}
App describes a Rosaline application window.
type AppMenu ¶
type AppMenu struct {
// contains filtered or unexported fields
}
AppMenu is one named drop-down menu in a menu bar.
type AppMenuBar ¶
type AppMenuBar struct {
// contains filtered or unexported fields
}
AppMenuBar is a window's top-level menu bar.
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box arranges child widgets in a row or column.
type ButtonWidget ¶
type ButtonWidget struct {
// contains filtered or unexported fields
}
ButtonWidget is a clickable button.
func Button ¶
func Button(text string, onClick func()) *ButtonWidget
Button creates a button. onClick runs when the user activates it.
func (*ButtonWidget) Primary ¶
func (b *ButtonWidget) Primary() *ButtonWidget
Primary gives a button the theme's primary color.
type CanvasWidget ¶
type CanvasWidget struct {
// contains filtered or unexported fields
}
CanvasWidget is a custom 2D drawing surface.
func Canvas ¶
func Canvas(draw func(*DrawingCanvas)) *CanvasWidget
Canvas creates a 2D drawing surface.
func (*CanvasWidget) Background ¶
func (c *CanvasWidget) Background(color Color) *CanvasWidget
Background sets the canvas background.
func (*CanvasWidget) Expand ¶
func (c *CanvasWidget) Expand() *CanvasWidget
Expand asks the canvas to use available layout space.
func (*CanvasWidget) OnMouseDown ¶
func (c *CanvasWidget) OnMouseDown(handler func(MouseEvent)) *CanvasWidget
OnMouseDown runs when a mouse button is pressed over the canvas.
func (*CanvasWidget) OnMouseMove ¶
func (c *CanvasWidget) OnMouseMove(handler func(MouseEvent)) *CanvasWidget
OnMouseMove runs when the pointer moves over the canvas. Event Button is MouseNone for normal movement and identifies the held button while dragging.
func (*CanvasWidget) OnMouseUp ¶
func (c *CanvasWidget) OnMouseUp(handler func(MouseEvent)) *CanvasWidget
OnMouseUp runs when a mouse button is released over the canvas.
func (*CanvasWidget) Redraw ¶
func (c *CanvasWidget) Redraw()
Redraw clears the canvas and runs its drawing function again. Call Redraw from Rosaline callbacks after changing drawing state. Mouse callbacks redraw automatically, so they normally do not need to call it themselves.
func (*CanvasWidget) Size ¶
func (c *CanvasWidget) Size(width, height int) *CanvasWidget
Size sets the canvas's initial size in pixels.
type CheckBoxWidget ¶
type CheckBoxWidget struct {
// contains filtered or unexported fields
}
CheckBoxWidget is a labeled checkbox bound to a Go bool.
func CheckBox ¶
func CheckBox(text string, value *bool) *CheckBoxWidget
CheckBox creates a checkbox. It updates value when the user toggles it. Pass a pointer with &, as in CheckBox("Updates", &updates).
func (*CheckBoxWidget) Focus ¶
func (c *CheckBoxWidget) Focus() *CheckBoxWidget
Focus asks Rosaline to give this checkbox focus when the window opens. If several widgets request focus, the first one wins.
func (*CheckBoxWidget) OnChange ¶
func (c *CheckBoxWidget) OnChange(handler func(bool)) *CheckBoxWidget
OnChange runs after the user toggles the checkbox.
type Color ¶
type Color struct {
R, G, B, A uint8
}
Color stores a red, green, blue, and alpha component.
func Hex ¶
Hex parses #RGB, #RRGGBB, or #RRGGBBAA. Invalid values return black. Use ParseHex when an invalid value should be reported as an error.
type DrawingCanvas ¶
type DrawingCanvas struct {
// contains filtered or unexported fields
}
DrawingCanvas provides Rosaline's beginner-friendly 2D drawing operations.
func (*DrawingCanvas) Circle ¶
func (c *DrawingCanvas) Circle(x, y, radius, stroke float64, color Color)
Circle draws the outline of a circle.
func (*DrawingCanvas) Clear ¶
func (c *DrawingCanvas) Clear(color Color)
Clear removes existing shapes and changes the canvas background.
func (*DrawingCanvas) FillCircle ¶
func (c *DrawingCanvas) FillCircle(x, y, radius float64, color Color)
FillCircle draws a filled circle.
func (*DrawingCanvas) FillRect ¶
func (c *DrawingCanvas) FillRect(x, y, width, height float64, color Color)
FillRect draws a filled rectangle.
func (*DrawingCanvas) Line ¶
func (c *DrawingCanvas) Line(x1, y1, x2, y2, stroke float64, color Color)
Line draws a line.
func (*DrawingCanvas) Rect ¶
func (c *DrawingCanvas) Rect(x, y, width, height, stroke float64, color Color)
Rect draws the outline of a rectangle.
type FileDialogOptions ¶
type FileDialogOptions struct {
Title string
InitialDirectory string
InitialFile string
DefaultExtension string
Filters []FileFilter
}
FileDialogOptions customizes an open or save dialog. Every field is optional; Rosaline supplies beginner-friendly defaults.
type FileFilter ¶
FileFilter describes one group of files in an open or save dialog.
type ImageWidget ¶
type ImageWidget struct {
// contains filtered or unexported fields
}
ImageWidget displays a Picture.
func Image ¶
func Image(picture *Picture) *ImageWidget
Image creates a widget that displays picture. A nil picture is allowed and shows a friendly placeholder until SetImage is called.
func (*ImageWidget) Expand ¶
func (i *ImageWidget) Expand() *ImageWidget
Expand asks the image widget to use available layout space.
func (*ImageWidget) Picture ¶
func (i *ImageWidget) Picture() *Picture
Picture returns the picture currently displayed by the widget.
func (*ImageWidget) Placeholder ¶
func (i *ImageWidget) Placeholder(text string) *ImageWidget
Placeholder changes the text shown when no picture is loaded.
func (*ImageWidget) SetImage ¶
func (i *ImageWidget) SetImage(picture *Picture)
SetImage changes the displayed picture. It can be called from Rosaline callbacks after the widget has been mounted.
type LabelWidget ¶
type LabelWidget struct {
// contains filtered or unexported fields
}
LabelWidget displays text.
func LabelFunc ¶
func LabelFunc(text func() string) *LabelWidget
LabelFunc creates a label whose text is recalculated after Rosaline events. It is useful for counters and other small pieces of changing text.
func (*LabelWidget) Color ¶
func (l *LabelWidget) Color(color Color) *LabelWidget
Color sets this label's text color.
type MenuAction ¶
type MenuAction struct {
// contains filtered or unexported fields
}
MenuAction is a clickable command inside a menu.
func MenuItem ¶
func MenuItem(text string, onClick func()) *MenuAction
MenuItem creates a clickable menu command.
func (*MenuAction) Shortcut ¶
func (m *MenuAction) Shortcut(shortcut string) *MenuAction
Shortcut displays and binds a keyboard shortcut such as "Ctrl+O" or "Ctrl+Shift+S".
type MenuEntry ¶
type MenuEntry interface {
// contains filtered or unexported methods
}
MenuEntry is an item or separator accepted by Menu.
func MenuSeparator ¶
func MenuSeparator() MenuEntry
MenuSeparator inserts a dividing line between menu commands.
type MouseButton ¶
type MouseButton uint8
MouseButton identifies a mouse button without exposing platform details.
const ( // MouseNone means that no mouse button is pressed. MouseNone MouseButton = iota // MouseLeft is the primary mouse button. MouseLeft // MouseMiddle is the middle mouse button. MouseMiddle // MouseRight is the secondary mouse button. MouseRight )
type MouseEvent ¶
type MouseEvent struct {
X float64
Y float64
Button MouseButton
Dragging bool
Shift bool
Control bool
Alt bool
}
MouseEvent describes mouse input on a Canvas. X and Y are measured from the canvas's top-left corner.
type Picture ¶
type Picture struct {
// contains filtered or unexported fields
}
Picture contains a decoded image that Rosaline can display.
func LoadImage ¶
LoadImage reads and decodes an image file. PNG, JPEG, GIF, BMP, TIFF, and WebP are supported.
func NewPicture ¶
NewPicture creates a Rosaline picture from Go's standard image.Image type.
type ScrollWidget ¶
type ScrollWidget struct {
// contains filtered or unexported fields
}
ScrollWidget displays content inside a viewport with horizontal and vertical scrollbars.
func Scroll ¶
func Scroll(content Widget) *ScrollWidget
Scroll creates a scrollable viewport around content.
func (*ScrollWidget) Expand ¶
func (s *ScrollWidget) Expand() *ScrollWidget
Expand asks the scroll area to use available layout space.
func (*ScrollWidget) Size ¶
func (s *ScrollWidget) Size(width, height int) *ScrollWidget
Size sets the viewport's preferred size in pixels.
type State ¶
type State[T any] struct { // contains filtered or unexported fields }
State stores a value that can be safely read and changed. LabelFunc and button callbacks are enough for basic reactive interfaces.
type TextAreaWidget ¶
type TextAreaWidget struct {
// contains filtered or unexported fields
}
TextAreaWidget is a multiline text input bound to a Go string.
func TextArea ¶
func TextArea(value *string) *TextAreaWidget
TextArea creates a multiline input. The area updates value as the user types. Pass a pointer with &, as in TextArea(¬es).
func (*TextAreaWidget) Focus ¶
func (t *TextAreaWidget) Focus() *TextAreaWidget
Focus asks Rosaline to give this text area focus when the window opens. If several widgets request focus, the first one wins.
func (*TextAreaWidget) OnChange ¶
func (t *TextAreaWidget) OnChange(handler func(string)) *TextAreaWidget
OnChange runs after the user changes the value.
func (*TextAreaWidget) Size ¶
func (t *TextAreaWidget) Size(columns, lines int) *TextAreaWidget
Size sets the preferred width in text columns and height in text lines.
type TextBoxWidget ¶
type TextBoxWidget struct {
// contains filtered or unexported fields
}
TextBoxWidget is a single-line text input bound to a Go string.
func TextBox ¶
func TextBox(value *string) *TextBoxWidget
TextBox creates a single-line input. The box updates value as the user types. Pass a pointer with &, as in TextBox(&name).
func (*TextBoxWidget) Focus ¶
func (t *TextBoxWidget) Focus() *TextBoxWidget
Focus asks Rosaline to give this text box focus when the window opens. If several widgets request focus, the first one wins.
func (*TextBoxWidget) OnChange ¶
func (t *TextBoxWidget) OnChange(handler func(string)) *TextBoxWidget
OnChange runs after the user changes the value.
func (*TextBoxWidget) OnSubmit ¶
func (t *TextBoxWidget) OnSubmit(handler func(string)) *TextBoxWidget
OnSubmit runs when the user presses Enter while the text box has focus.
func (*TextBoxWidget) Password ¶
func (t *TextBoxWidget) Password() *TextBoxWidget
Password hides typed characters. The bound Go string still contains the real value so the application can validate or submit it.
func (*TextBoxWidget) Placeholder ¶
func (t *TextBoxWidget) Placeholder(text string) *TextBoxWidget
Placeholder shows a hint while the text box is empty.
func (*TextBoxWidget) Width ¶
func (t *TextBoxWidget) Width(columns int) *TextBoxWidget
Width sets the preferred width in text columns.
type Theme ¶
type Theme struct {
Background Color
Surface Color
Primary Color
Text Color
Muted Color
Border Color
Danger Color
Success Color
}
Theme contains semantic colors used by Rosaline widgets.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer runs a callback later or at a regular interval while its App is open. Create timers with Every, After, or Animate, then include them in App.Timers.
func After ¶
After creates a running one-shot timer. It calls callback once after delay, then stops. It begins when its App starts.
func Animate ¶
Animate creates a repeating timer measured in frames per second. Use it to update drawing state, then call CanvasWidget.Redraw from the frame callback. Invalid frame rates use 60 FPS; rates above 1000 FPS are limited to 1000.
func Every ¶
Every creates a running timer that calls callback repeatedly. It begins when its App starts. Durations shorter than one millisecond use one millisecond.
func (*Timer) Restart ¶
func (t *Timer) Restart()
Restart resets the wait and starts the timer again from the beginning.
func (*Timer) Running ¶
Running reports whether the timer is started. Before RunApp, true means the timer is ready to begin as soon as its App opens.