jsondocument

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package jsondocument contains the logic for rendering a Fyne tree from a JSON document.

Index

Constants

This section is empty.

Variables

View Source
var Empty = struct{}{}

This singleton represents an empty value in a Node.

View Source
var ErrCallerCanceled = errors.New("process canceled by caller")
View Source
var ErrNotFound = errors.New("not found")

Functions

func MakeURIReadCloser

func MakeURIReadCloser(r io.Reader, name string) uriReadCloser

Creates and returns an URIReadCloser from a reader.

Types

type JSONDocument

type JSONDocument struct {
	// How often progress info is updated
	ProgressUpdateTick int32
	// contains filtered or unexported fields
}

JSONDocument represents a JSON document which can be rendered by a Fyne tree widget.

func New

func New() *JSONDocument

Returns a new JSONDocument object.

func (*JSONDocument) ChildUIDs

func (j *JSONDocument) ChildUIDs(uid widget.TreeNodeID) []widget.TreeNodeID

ChildUIDs returns the child UIDs for a given node. This can be used directly in the tree widget childUIDs() function.

func (*JSONDocument) Extract

func (j *JSONDocument) Extract(uid widget.TreeNodeID) ([]byte, error)

Extract returns a segment of the JSON document, with the given UID as new root container. Note that only arrays and objects can be extracted

func (*JSONDocument) IsBranch

func (j *JSONDocument) IsBranch(uid widget.TreeNodeID) bool

IsBranch reports wether a node is a branch. This can be used directly in the tree widget isBranch() function.

func (*JSONDocument) Load

func (j *JSONDocument) Load(ctx context.Context, reader fyne.URIReadCloser, progressInfo binding.Untyped) error

Load loads JSON data from a reader and builds a new JSON document from it. It reports it's current progress to the caller via updates to progressInfo. Closes the reader.

func (*JSONDocument) Parent

Parent returns the UID of the parent node.

func (*JSONDocument) Path

Path returns the path of a node in the tree.

func (*JSONDocument) Reset

func (j *JSONDocument) Reset()

Size returns the number of nodes.

func (*JSONDocument) Search

func (j *JSONDocument) Search(ctx context.Context, uid widget.TreeNodeID, search string, typ SearchType) (widget.TreeNodeID, error)

Search returns the next node with a matching key or an error if not found or canceled. The starting node will be ignored, so that is is possible to find successive nodes with the same key. The search direction is from top to bottom.

func (*JSONDocument) Size

func (j *JSONDocument) Size() int

Size returns the number of nodes.

func (*JSONDocument) Value

func (j *JSONDocument) Value(uid widget.TreeNodeID) Node

Value returns the value of a node

type JSONTreeSizer

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

JSONTreeSizer is an object for calculating the number of nodes in a tree structure. It is specialized for data produced by un-marshalling a JSON document.

func (*JSONTreeSizer) Calculate

func (t *JSONTreeSizer) Calculate(data any) (int, error)

Calculate returns the number of nodes in a tree structure.

type JSONType

type JSONType uint8

JSONType represents the type of a JSON value.

const (
	Undefined JSONType = iota
	Array
	Boolean
	Null
	Number
	Object
	String
	Unknown
)

func (JSONType) String

func (t JSONType) String() string

type Node

type Node struct {
	Key   string
	Value any
	Type  JSONType
}

Node represents a node in the JSON data tree.

type ProgressInfo

type ProgressInfo struct {
	CurrentStep int
	Progress    float64
	Size        int
	TotalSteps  int
}

ProgressInfo represents the current progress while loading a document and is used to communicate the the UI.

type SearchType

type SearchType uint

SearchType represents the type of search to perform.

const (
	SearchKey SearchType = iota
	SearchString
	SearchNumber
	SearchKeyword
)

Jump to

Keyboard shortcuts

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