lumi

package module
v0.0.0-...-59afa50 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MPL-2.0 Imports: 23 Imported by: 0

README

Lumi

MPL 2.0 License

Lumi is a versatile, lightweight user interface library that works on any computer.

Example

package main

import (
	_ "embed"
	"strconv"
	"time"

	"github.com/nasOS-official/lumi"
	"golang.org/x/image/font"
	"golang.org/x/image/font/opentype"
)

//go:embed Roboto-Regular.ttf
var Roboto []byte

func main() {
	a := lumi.CreateWindow(400, 200)
	a.Device.SetTitle("hello!!!")

	fnt, _ := opentype.Parse(Roboto)
	face, _ := opentype.NewFace(fnt, &opentype.FaceOptions{
		Size:    20,
		DPI:     72,
		Hinting: font.HintingFull,
	})
	counter := 0
	a.Widgets = append(a.Widgets, lumi.CreateButton(30, 30, 300, 100, "Press me!", &face, 110, 150, 120, func(button *lumi.Button) {
		button.SetLabel("You pressed me " + strconv.Itoa(counter) + " times!")
		counter++

		x, y, w, h := button.GetSize()
		button.Resize(x+1, y+1, w, h)
	}))

	for a.Device.IsOpen() {
		a.Device.GetGeometry().ClearScreen()
		a.ProcessEvents()
		a.Device.Update()
		time.Sleep(time.Millisecond * 16)

	}
}

Documentation

Overview

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

SPDX-License-Identifier: MPL-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResolution

func GetResolution(fbName string) (ResX, ResY int)

Types

type Button

type Button struct {
	OnLeftClick    func(*Button)
	OnRightClick   func(*Button)
	OnCentralClick func(*Button)
	OnPress        func(*Button)
	OnRelease      func(*Button)
	OnHoverEnter   func(*Button)
	OnHoverEscape  func(*Button)
	// contains filtered or unexported fields
}

func CreateButton

func CreateButton(x, y, width, height int, label string, face *font.Face, r, g, b byte, OnLeftClick func(*Button)) (button *Button)

func (*Button) Draw

func (button *Button) Draw(geometry GeometryInterface)

func (*Button) GetColor

func (button *Button) GetColor() (r, g, b byte)

func (*Button) GetSize

func (button *Button) GetSize() (x, y, width, height int)

func (*Button) ProcessMouse

func (button *Button) ProcessMouse(mouseStruct *MouseStruct)

func (*Button) Resize

func (button *Button) Resize(x, y, width, height int)

func (*Button) SetAutoColor

func (button *Button) SetAutoColor(r, g, b byte)

func (*Button) SetLabel

func (button *Button) SetLabel(text string)

type Callback

type Callback func(WidgetInterface, PressState)

type Driver

type Driver interface {
	Init(resX, resY int)
	SetTitle(title string)
	SetFixedDimensions(Width, Height uint)
	SetDimensions(MaxWidth, MaxHeight, MinWidth, MinHeight, CurrentWidth, CurrentHeight uint)
	SetSize(Width, Height uint)
	Update()
	GetGeometry() GeometryInterface
	IsOpen() bool
	GetMouseState() MouseStruct
}

type FbDriver

type FbDriver struct {
	Geometry *GeometryDriver
	// contains filtered or unexported fields
}

func (*FbDriver) GetGeometry

func (fb *FbDriver) GetGeometry() *GeometryDriver

func (*FbDriver) GetPointer

func (fb *FbDriver) GetPointer() (posX, posY int)

func (*FbDriver) Init

func (fb *FbDriver) Init(num, _ int)

func (*FbDriver) IsOpen

func (fb *FbDriver) IsOpen() bool

func (*FbDriver) SetTitle

func (fb *FbDriver) SetTitle(title string)

func (*FbDriver) Update

func (fb *FbDriver) Update()

type GeometryDriver

type GeometryDriver struct {
	ResX       int
	ResY       int
	Buffer     []byte
	BufferSize int
	// contains filtered or unexported fields
}

func (*GeometryDriver) ClearScreen

func (geometry *GeometryDriver) ClearScreen()

func (*GeometryDriver) DrawAlphaBuffer

func (geometry *GeometryDriver) DrawAlphaBuffer(x, y, height, width int, buffer []byte, r, g, b byte)

func (*GeometryDriver) DrawBuffer

func (geometry *GeometryDriver) DrawBuffer(x, y, height, width int, buffer []byte)

func (*GeometryDriver) DrawCircle

func (geometry *GeometryDriver) DrawCircle(yCenter, xCenter, radius int, r, g, b uint8)

func (*GeometryDriver) DrawImage

func (geometry *GeometryDriver) DrawImage(x, y, width, height int, img image.Image)

func (*GeometryDriver) DrawLine

func (geometry *GeometryDriver) DrawLine(x0, x1, y0, y1 int, r, g, b uint8)

func (*GeometryDriver) DrawRectangle

func (geometry *GeometryDriver) DrawRectangle(xstart, xend, ystart, yend int, r, g, b uint8)

func (*GeometryDriver) GetBuffer

func (geometry *GeometryDriver) GetBuffer() *[]byte

func (*GeometryDriver) GetBufferSize

func (geometry *GeometryDriver) GetBufferSize() int

func (*GeometryDriver) GetPoint

func (geometry *GeometryDriver) GetPoint(x, y int) (r, g, b uint8)

func (*GeometryDriver) GetResX

func (geometry *GeometryDriver) GetResX() int

func (*GeometryDriver) GetResY

func (geometry *GeometryDriver) GetResY() int

func (*GeometryDriver) Resize

func (geometry *GeometryDriver) Resize(resX, resY int)

func (*GeometryDriver) SetPoint

func (geometry *GeometryDriver) SetPoint(x, y int, r, g, b uint8)

type GeometryInterface

type GeometryInterface interface {
	ClearScreen()
	// DrawString(x, y, width, height int, face *font.Face, text string, r, g, b uint8)
	DrawBuffer(x, y, height, width int, buffer []byte)
	Resize(resX, resY int)
	SetPoint(x, y int, r, g, b uint8)
	DrawRectangle(xstart, xend, ystart, yend int, r, g, b uint8)
	GetPoint(x, y int) (r, g, b uint8)
	DrawCircle(yCenter, xCenter, radius int, r, g, b uint8)
	DrawAlphaBuffer(x, y, height, width int, buffer []byte, r, g, b byte)
	DrawLine(x0, x1, y0, y1 int, r, g, b uint8)
	DrawImage(x, y, width, height int, img image.Image)
	GetResX() int
	GetResY() int
	GetBufferSize() int
	GetBuffer() *[]byte
}

type Image

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

func CreateJPGImage

func CreateJPGImage(x, y, width, height int, reader io.Reader) *Image

func CreatePNGImage

func CreatePNGImage(x, y, width, height int, reader io.Reader) *Image

func (*Image) Draw

func (image *Image) Draw(geometry GeometryInterface)

func (*Image) Hide

func (image *Image) Hide()

func (*Image) ProcessMouse

func (image *Image) ProcessMouse(mouse *MouseStruct)

func (*Image) SetJPGImage

func (image *Image) SetJPGImage(reader io.Reader)

func (*Image) SetPNGImage

func (image *Image) SetPNGImage(reader io.Reader)

func (*Image) Show

func (image *Image) Show()

type Label

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

func CreateLabel

func CreateLabel(x, y, width, height int, face *font.Face, text string, r, g, b byte) *Label

func (*Label) Draw

func (label *Label) Draw(geometry GeometryInterface)

func (*Label) GetSize

func (label *Label) GetSize() (x, y, width, height int)

func (*Label) ProcessMouse

func (label *Label) ProcessMouse(mousestruct *MouseStruct)

func (*Label) Resize

func (label *Label) Resize(x, y, width, height int)

func (*Label) SetText

func (label *Label) SetText(text string)

type Lumi

type Lumi struct {
	Device   Driver
	Geometry GeometryInterface
	Widgets  []WidgetInterface
}

func CreateWindow

func CreateWindow(resX, resY int) *Lumi

func (*Lumi) ProcessEvents

func (lumi *Lumi) ProcessEvents()

type MouseStruct

type MouseStruct struct {
	X, Y    int
	RButton bool
	LButton bool
	CButton bool
}

type PressState

type PressState uint

type WidgetInterface

type WidgetInterface interface {
	// Remove()
	// Move()
	// Hide()
	// Show()
	ProcessMouse(*MouseStruct) // pointer may create some bugs on window close
	// Create()
	Draw(geometry GeometryInterface)
}

type XDrv

type XDrv struct {
	Geometry GeometryInterface
	// contains filtered or unexported fields
}

func (*XDrv) CreateWindow

func (xdrv *XDrv) CreateWindow(quit bool)

func (*XDrv) GetGeometry

func (xdrv *XDrv) GetGeometry() GeometryInterface

func (*XDrv) GetMouseState

func (xdrv *XDrv) GetMouseState() MouseStruct

func (*XDrv) Init

func (xdrv *XDrv) Init(resX, resY int)

func (*XDrv) IsOpen

func (xdrv *XDrv) IsOpen() bool

func (*XDrv) SetDimensions

func (xdrv *XDrv) SetDimensions(MaxWidth, MaxHeight, MinWidth, MinHeight, CurrentWidth, CurrentHeight uint)

func (*XDrv) SetFixedDimensions

func (xdrv *XDrv) SetFixedDimensions(Width, Height uint)

func (*XDrv) SetSize

func (xdrv *XDrv) SetSize(Width, Height uint)

func (*XDrv) SetTitle

func (xdrv *XDrv) SetTitle(title string)

func (*XDrv) Update

func (xdrv *XDrv) Update()

Jump to

Keyboard shortcuts

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