raywin

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScrollBoth       = ScrollHorizontal | ScrollVertical
	ScrollHorizontal = 1
	ScrollVertical   = 2
)
View Source
const (
	// TPStateNA indicates that no points on the touchpad are currently pressed.
	TPStateNA = iota

	// TPStatePressed indicates that the touchpad is pressed at a specific position,
	// and the position has not changed since the event. If the point is moved and then
	// stops without being released, the state will transition to TPStateMoving and
	// will not return to TPStatePressed.
	TPStatePressed

	// TPStateMoving indicates that the touchpad is pressed and the position has moved
	// (but the touchpad is not yet released). Even if the finger moves (or not), but remains pressed,
	// this state will be reported instead of TPStatePressed.
	TPStateMoving

	// TPStateReleased reports the position where the touchpad was released.
	TPStateReleased
)
View Source
const (
	// OnTPSResultNA tells that the TPState is not handled and another
	// component may be notified about the event
	OnTPSResultNA = OnTPSResult(0)

	// OnTPSResultLocked indicates that the component has locked focus
	// and will handle all further touchpad events. These events will
	// be sent exclusively to the component until it returns a different
	// result or is closed. During this time, other components will not
	// receive touchpad event notifications.
	OnTPSResultLocked = OnTPSResult(1)

	// OnTPSResultStop indicates that the component does not hold focus,
	// but the touchpad event should not be passed to other components.
	// This signals raywin to stop the cycle and refrain from notifying
	// other components about the touchpad events BUT ONLY FOR THE CURRENT FRAME!
	//
	// The difference between this state and OnTPSResultLocked is as follows:
	// OnTPSResultStop terminates only the current cycle of notifications,
	// whereas OnTPSResultLocked prevents the cycle from starting in future
	// frames. In the locked state, only the locked component is notified
	// until it indicates otherwise.
	OnTPSResultStop = OnTPSResult(2)
)

Variables

This section is empty.

Functions

func DefaultInternalScrollerDeceleration

func DefaultInternalScrollerDeceleration() rl.Vector2

DefaultInternalScrollerDeceleration returns the default InternalScroller deceleration. The parameters are adjusted for 60FPS and the 800x600 screen size. To decelerate faster, put lower (bigger absolute) values

func GetIcon

func GetIcon(in string) (rl.Texture2D, error)

GetIcon returns the icon by its name without the extension. If the file name is "picture.png" it can be obtained by "picture". See Config

func Init

func Init(cfg Config) error

Init should be called before the Run() to initialize the raywin-go

func IsEmpty

func IsEmpty[T rl.Vector2 | Vector2Int32 | Number](v T) bool

func IsPointInRegionInt32

func IsPointInRegionInt32(x, y int32, r rl.RectangleInt32) bool

func RectangleInt32ToString

func RectangleInt32ToString(r rl.RectangleInt32) string

RectangleInt32ToString is the helper function to stringify `r`

func Run

func Run(ctx context.Context) error

Run runs the drawing cycle and rendering the main window. It will be stopped when the context ctx is closed

func SystemFont

func SystemFont() rl.Font

SystmeFont returns the default system font

func SystemItalicFont

func SystemItalicFont() rl.Font

SystemItalicFont returns the Italic version of the system font

func VectorDiff

func VectorDiff(v1, v2 rl.Vector2) rl.Vector2

Types

type BaseComponent

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

BaseComponent provides the fundamental implementation of all components. It means that any component should embed the struct. So as the Component interface has the package private baseComponent() function, it is not possible to implement a Component without embedding the BaseComponent.

BaseComponent supports any component life-cycle: - Init() - the function initializes BaseComponent - Close() - the Component termination In addition, the implementation also provides implementation for the component visibility, to avoid some boilerplate code in the derived components

func (*BaseComponent) AssertInitialized

func (bc *BaseComponent) AssertInitialized() error

AssertInitialized returns an error if the component is not initialized

func (*BaseComponent) Bounds

func (bc *BaseComponent) Bounds() rl.RectangleInt32

Bounds returns the component position on its owner coordinates, and its size as rl.RectangleInt32

func (*BaseComponent) Close

func (bc *BaseComponent) Close()

Close allows to close the BaseComponent

func (*BaseComponent) Draw

func (bc *BaseComponent) Draw(cc *CanvasContext)

Draw is the BaseComponent drawing procedure which does nothing. It is here to support the Component interface, should be re-defined in the derived structure

func (*BaseComponent) Init

func (bc *BaseComponent) Init(owner Container, this Component) error

Init initializes BaseComponent. owner should be non-nil the owner of the Component, `this` contains the final struct, which implements Component, but which embed the bc

Init must be called for any instance as first thing after its creation.

func (*BaseComponent) IsVisible

func (bc *BaseComponent) IsVisible() bool

IsVisible returns whether the component is visible or not

func (*BaseComponent) SetBounds

func (bc *BaseComponent) SetBounds(r rl.RectangleInt32)

SetBounds allows to assing the comonent position and dimensions by the `r`

func (*BaseComponent) SetVisible

func (bc *BaseComponent) SetVisible(visible bool)

SetVisible allows to specify the component visibility

func (*BaseComponent) String

func (bc *BaseComponent) String() string

String returns the `bc` description

type BaseContainer

type BaseContainer struct {
	BaseComponent
	// contains filtered or unexported fields
}

BaseContainer struct offers a basic implementation of Container interface. Complex components, that suppose to own other components, may use the BaseContainer for the basic Container implementation.

func (*BaseContainer) Children

func (bc *BaseContainer) Children() []Component

Children returns list of owned components

func (*BaseContainer) Close

func (bc *BaseContainer) Close()

Close terminates the Container and all its children

func (*BaseContainer) Init

func (bc *BaseContainer) Init(owner Container, this Component) error

Init initializes BaseContainer, returns nil if the component initialized successfully

func (*BaseContainer) OnAddChild

func (bc *BaseContainer) OnAddChild(c Component, children []Component) ([]Component, error)

OnAddChild is the default implementation, please see Container interface

func (*BaseContainer) String

func (bc *BaseContainer) String() string

String returns the BaseContainer string representation

type CanvasContext

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

CanvasContext struct allows to track the stack of regions, so that one includes another. The struct allows to find the physical basis (the position of (0,0) of a Component pixel in the physical display coordinates)

func (*CanvasContext) IsVisible

func (cc *CanvasContext) IsVisible(r rl.RectangleInt32) bool

IsVisible returns whether the region r is visible on the stack of regions

func (*CanvasContext) PhysicalPointXY

func (cc *CanvasContext) PhysicalPointXY(x, y int32) (int32, int32)

PhysicalPointXY returns the coordinates for a Component's point (x,y) on the physical display.

func (*CanvasContext) PhysicalRegion

func (cc *CanvasContext) PhysicalRegion() rl.RectangleInt32

PhysicalRegion returns the region for the physical screen

type Component

type Component interface {
	// Draw renders the component within the specified physical region, as defined by the cc parameter.
	// The implementation utilizes Raylib functions, such as rl.Rectangle(), to draw the component on
	// the display. The cc parameter specifies the position of the component on the physical display.
	//
	// By default, Draw() is invoked for the physical region where the component is defined. Raywin
	// uses scissors to constrain the drawing area. The implementation can adjust the drawing area
	// by calling rl.BeginScissorMode() if the region need to be changed.
	//
	// Raywin invokes Draw() for all visible components in each frame. A component is considered visible
	// if IsVisible() returns true and its Bounds() intersect with the visible region defined by its
	// parent Component (see Container).
	Draw(cc *CanvasContext)

	// IsVisible returns whether the component is visible or not
	IsVisible() bool

	// SetVisible sets the component visibility
	SetVisible(b bool)

	// Close closes the component and frees all resources
	Close()

	// SetBounds defines the Component position on the parent's component region and its size.
	SetBounds(r rl.RectangleInt32)

	// Bounds returns the position and size of the component. The position is defined relative to the region
	// of the parent component.
	Bounds() rl.RectangleInt32
	// contains filtered or unexported methods
}

Component defines an interface for a drawable box. All structs that implement the interface must have BaseComponent embedded into the structs (please see below)

type Config

type Config struct {
	// ResourceDir specify the path to dir with the library resources(wallpaper, icons, fonts etc.)
	ResourceDir string

	// WallpaperFileName provides the name to .png file the file should be in the current dir or in the
	// ResourceDir, if it is not find in the current directory. The field may be empty.
	WallpaperFileName string

	// RegularFontFileName provides the name to .ttf file with the default system font.
	// The file should be in the current dir or in the ResourceDir, if it is not find
	// in the current directory. The field may be empty.
	RegularFontFileName string

	// ItalicFontFileName provides the name to .ttf file containing italic system font.
	// The file should be in the current dir or in the ResourceDir, if it is not find
	// in the current directory. The field may be empty.
	ItalicFontFileName string

	// DisplayConfig contains the display physical characteristics
	DisplayConfig DisplayConfig

	// IconsDir provides the name of the directory where the icon images (in PNG) are stored.
	// The directory should be in the current dir or in the ResourceDir, if it is not find
	// in the current directory. The field may be empty.
	//
	// All icons will be read into memory during Init() and they will be available via
	// GetIcon() call. The file name (without the extension) is used as the icon name.
	IconsDir string
}

Config struct describes the raywin-go configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default Config

func (Config) String

func (c Config) String() string

String - Config's implementation of fmt.Stringer

type Container

type Container interface {
	// Children returns the list of components owned by the container. The components in the list
	// are drawn in the order they appear. The first component is drawn first, followed by the second,
	// third, and so on. As a result, the last component is drawn on top and will cover all previous
	// components if they overlap.
	//
	// The Draw function for the Container is called before the Draw functions of its children,
	// ensuring that the children are drawn on top of the container's drawings.
	Children() []Component

	// OnAddChild is called to update the list of children by adding the child `c` to it.
	// It must return the updated collection of children with `c` added, or an error if the operation is not possible.
	//
	// OnAddChild is a special public function that is called while holding the internal lock of `bc`.
	// Therefore, if this function is overridden, no calls to `bc` should be made within the override,
	// as it may lead to deadlock.
	//
	// Even the function is implemented in BaseContainer and the default implementation may be good enough,
	// users may override this function to customize the order in which children are stored.
	// The default implementation simply adds `c` to the end of the children slice, or adds to the end
	// it if it already exists.
	OnAddChild(c Component, children []Component) ([]Component, error)
	// contains filtered or unexported methods
}

Container is a Component which may contain children components. The drawing area for the Container's children is limited by the Container's region

func RootContainer

func RootContainer() Container

RootContainer returns the container for the display

type DisplayConfig

type DisplayConfig struct {
	// Width of the display area in number of pixels
	Width uint32
	// Height of the display area in number of pixels
	Height uint32
	// FPS - frames per second. The number of the display updates the library
	// will try to support.
	FPS int
	// BackgroundColor contains the default color for display area
	BackgroundColor rl.Color
}

DisplayConfig contain the basic display configuration

func DefaultDisplayConfig

func DefaultDisplayConfig() DisplayConfig

DefaultDisplayConfig returns the default DisplayConfig

func (DisplayConfig) String

func (dc DisplayConfig) String() string

String - DisplayConfig's implementation of fmt.Stringer

type FrameListener

type FrameListener interface {
	// OnNewFrame is called for each component that implements the interface on every new frame.
	// The `millis` timestamp is monotonically increasing and can be used to measure the time elapsed
	// between different frames renderings. It is also used in various notification calls to identify the frame's
	// timestamp, effectively serving as a unique identifier for the frame.
	//
	// the `millis` may be related to the clock and may be not, so it cannot be used to identify
	// the current time, but for measuring the time intervals between frames only.
	OnNewFrame(millis int64)
}

FrameListener interface allows components to be notified about each new frame

type InertialScroller

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

InertialScroller is a helper structure that facilitates scrolling with an inertia effect over a virtual area.

The struct implements three interfaces: FrameListener, Scrollable, and Touchpadable. A Component can either embed this structure to add scrolling functionality or decorate the interfaces to include additional processing within the Component.

Refer to the inertial_scroller example for usage instructions.

func (*InertialScroller) InitScroller

func (s *InertialScroller) InitScroller(owner Component, virtBounds rl.RectangleInt32, decel rl.Vector2, flags uint8) error

func (*InertialScroller) IsTPLocked

func (s *InertialScroller) IsTPLocked() bool

IsLocked returns whether the InertialScroller holds touchpad control or not

func (*InertialScroller) Offset

func (s *InertialScroller) Offset() Vector2Int32

Offset provides an implementation of Scrollable interface.

func (*InertialScroller) OnNewFrame

func (s *InertialScroller) OnNewFrame(millis int64)

OnNewFrame provides the FrameListener interface. The function must be called by raywin only

func (*InertialScroller) OnTPState

func (s *InertialScroller) OnTPState(tps TPState) OnTPSResult

OnTPState implements the Touchpadable interface. The function must be called by raywin only

func (*InertialScroller) SetVirtualBounds

func (s *InertialScroller) SetVirtualBounds(bounds rl.RectangleInt32)

SetVirtualBounds allows to specify the virtual size for the scroller

func (*InertialScroller) VirtualBounds

func (s *InertialScroller) VirtualBounds() rl.RectangleInt32

VirtualBounds returns the VirtualBounds (the offset point and the area size) as rl.RectangleInt32

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type OnTPSResult

type OnTPSResult int

OnTPSResult the result which will be returned by the OnTPState by the Touchpadable component. Please see the results descriptions in the constants below

type Scrollable

type Scrollable interface {
	// Offset defines the position of the component's top-left corner relative to the
	// drawing grid's origin (0,0). By default, the top-left corner is at position (0,0).
	// Negative offsets indicate that the grid's origin has shifted to the right and downward.
	// For example, an offset of (-5, -10) moves the grid's origin 5 pixels to the right and
	// 10 pixels down from the top-left corner of the component's drawing area.
	// Conversely, positive offset values move the grid's origin upward and to the left
	// relative to the component's top-left corner.
	//
	// Components that support scrolling of their drawing area expose the interface to let
	// the raywin properly define the drawing context.
	Offset() Vector2Int32
}

Scrollable interface applied to the components that support scrolling of their drawing area.

type TPState

type TPState struct {
	// State contains the state of the touchpad
	State int
	// Pos defines the position of the first touched point (if any)
	Pos rl.Vector2
	// Millis contains the timestamp when the state is read last time
	// (latest time, not the time when the state is set!)
	Millis int64
	// Sequence is the state unique identifier. Every new state
	// has a new monotonically increasing sequence
	Sequence int64
}

TPState describes the current touchpad state. The event describes most relevant state for the touchpad. The Millis field contains the timestamp when the state is observed (not when the touchpad switched to the state!)

func (TPState) PosXY

func (tps TPState) PosXY() (int32, int32)

type Touchpadable

type Touchpadable interface {
	// OnTPState is called every frame with the current touchpad State
	// if any. The method must return OnTPSResult value(see below).
	OnTPState(tps TPState) OnTPSResult
}

Touchpadable interface maybe implemented by a component to let raywin-go know that the component wants to react on the touchpad events.

type Vector2Int32

type Vector2Int32 struct {
	X int32
	Y int32
}

Vector2Int32 is the similar to rl.Vector2, but with int32 coordinates

func ToVector2Int32

func ToVector2Int32(v rl.Vector2) Vector2Int32

func (Vector2Int32) ToVector2

func (v Vector2Int32) ToVector2() rl.Vector2

Jump to

Keyboard shortcuts

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