rlnicex

package module
v0.0.0-...-9e8c3a4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

RlNiceX

RlNiceX is a Raylib library for creating and styling interactive GUI and HUD widgets.

License

GPL 3

Usage

Example usages for all widgets + styling

import (
  rl "github.com/gen2brain/raylib-go/raylib"
  rlx "github.com/manen/rlnicex"
)

(You'll need a correctly initialized Raylib window)

Styles

Styles can be read from a JSON file. An example can be found here

Load style:

err := rlx.LoadStyle("./path/to/style.json")
if err != nil {
  // Handle error
}

NOTE: You can create manual styles too. Not recommended though.

sc := rlx.StyleConfig{
  Base: rlx.Style{
    Background: rl.Black,
  },
  Held: rlx.Style{
    BorderWidth: 4,
  },
}
err := sc.Apply()
if err != nil {
  // Handle error
}

If you've done this, all widgets will use the respected theme.

Offset
r := rlx.NewOffset(0, 0) // Why 'r'? I don't know, lol
Render any widget
for !rl.WindowShouldClose() {
  widget.Render(r)
}
Label
lbl := rlx.NewLabel("Label here!", false, 4, 4)
Button
btn := rlx.NewButton(rlx.NewLabelSimple("Click me!"), 10, 10, 140, 40)

Check if clicked:

if btn.IsClicked(r) {
  log.Println("Clicked!")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawBorder

func DrawBorder(pos rl.RectangleInt32, style Style)

func LoadStyle

func LoadStyle(fileName string) error

Types

type Button

type Button struct {
	Label Label
	Pos   rl.Rectangle
}

func NewButton

func NewButton(label Label, x, y, w, h float64) Button

func (Button) IsClicked

func (b Button) IsClicked(r Offset) bool

func (Button) IsHeld

func (b Button) IsHeld(r Offset) bool

func (Button) IsHovered

func (b Button) IsHovered(r Offset) bool

func (Button) Render

func (b Button) Render(r Offset)

type Hoverable

type Hoverable interface {
	IsHovered(r Offset) bool
	IsHeld(r Offset) bool
}

type Label

type Label struct {
	Label    string
	Centered bool
	Pos      rl.Vector2
}

func NewLabel

func NewLabel(label string, centered bool, x, y float64) Label

func NewLabelSimple

func NewLabelSimple(label string) Label

func (Label) Render

func (l Label) Render(r Offset)

func (Label) RenderWithStyle

func (l Label) RenderWithStyle(r Offset, style Style)

type Offset

type Offset rl.Vector2

func NewOffset

func NewOffset(x, y float64) Offset

func (Offset) Sub

func (r Offset) Sub(x, y float64) Offset

type Style

type Style struct {
	// BackgroundColor is the color of the background of all widgets.
	BackgroundColor rl.Color `json:"backgroundColor"`

	// FontColor
	FontColor rl.Color `json:"fontColor"`
	// FontSize is the... font size.
	FontSize float64 `json:"fontSize"`
	// FontSpacing is the space between the letters. It might be called letter
	// spacing in other places
	FontSpacing float64 `json:"fontSpacing"`

	// BorderWidth is the... Width of the borders. It's not that hard
	BorderWidth float64 `json:"borderWidth"`
	// BorderColor is the color of the borders. I wish they were all this easy.
	BorderColor rl.Color `json:"borderColor"`
}

func (Style) String

func (s Style) String() string

func (Style) ToMap

func (s Style) ToMap() map[string]interface{}

type StyleConfig

type StyleConfig struct {
	Base    Style `json:"base"`
	Hovered Style `json:"hover"`
	Held    Style `json:"held"`
}

func (StyleConfig) Apply

func (sc StyleConfig) Apply() error

type Widget

type Widget interface {
	Render(Offset)
}

Jump to

Keyboard shortcuts

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