view

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: BSD-2-Clause-Views Imports: 11 Imported by: 0

README

A view defines a set of drawing things which can be painted as a single unit
into a sketch graphics context (gc). A view file provides a simple mechanism
for describing the collection.

This is a work in progress

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Open_file

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

type Velement

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

View element -- something that can be converted into a drawing thing and painted using the graphics output mechanisms supported by the graphics api. Depending on the element, it could translate into multiple drawing things.

func Mk_velement

func Mk_velement(ename string, xo float64, yo float64, scale float64, etype string, json string, data *data_mgr.Data_group) (ve *Velement, err error)

Mk_velement creates a view element loacted at the current xo,yo corridant using the given json string. The json is expected to be accepted format defined by the drawingthings package.

Scale is passed to the drawing thing maker should it be needed.

func (*Velement) Contains

func (ve *Velement) Contains(x float64, y float64) bool

func (*Velement) Data_update

func (ve *Velement) Data_update(data string)

Data_update accepts a data string which which is passed to the element to update its data. Data varies by element, so the contents of the string are important at the lower level and not looked at here.

func (*Velement) Get_dgroup

func (ve *Velement) Get_dgroup() (dg *data_mgr.Data_group)

Get_ds returns the element's data group or nil if it doesn't exist.

func (*Velement) Get_name

func (ve *Velement) Get_name() string

Get_name returns the element's name.

func (*Velement) Nuke

func (ve *Velement) Nuke(gc sketch.Graphics_api)

Nuke destroys what ever we need to clean up when we're done. Must specifically drive underlying dthing cleanup to eliminate subpages immediately, not when the GC runs.

func (*Velement) Paint

func (ve *Velement) Paint(gc sketch.Graphics_api, scale float64)

Paint causes this element to be rendered on the output device defined by the graphics context (api) passed in.

func (*Velement) Set_iscale

func (ve *Velement) Set_iscale(increment float64)

Set_iscale passes the given scale value to the underlying drawing thing for an incremental scale change. The increment value is added to the current scale setting.

func (*Velement) Set_scale

func (ve *Velement) Set_scale(scale float64)

Set_scale passes the given scale value to the underlying drawing thing.

func (*Velement) Tickle

func (ve *Velement) Tickle(data interface{})
A tickle -- likely a button press on a menu

func (ve *Velement ) Tickle( data string ) {

func (*Velement) Update

func (ve *Velement) Update(jbuf string)

Update causes the passed json string to be used to update the underlying drawing thing. Only the values which need to be changed need to exist in the json. If a value is not supplied in the json, the current value in the underlying drawingthing is unchanged.

type View

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

func MkScaledView added in v1.2.1

func MkScaledView(fname string, scale float64) (v *View, err error)

Read the view file from fname and create a view. We need the scale because some drawing things which create a subpage must scale that outside of the GC.

func Mk_view

func Mk_view(fname string) (v *View, err error)

Deprecated! Original form (prevent scaled support from being breaking change). Defaults to a scale of 1.0. Use MkScaledView( fname, scale)

func (*View) Data_update

func (vp *View) Data_update(elename string, ibuf interface{})

Data_pdate processes a change/addition to an element's data. Elements have different data types:

text - string
meter - single value
graph - data group

We assume the buffer passed is of the form:

data_update element-name "data-value"

The data string is passed to the element for processing and each will liklely have a different expected format.

To change the element's properties (position, size, etc.) use the Update function.

func (*View) Hard_click

func (vp *View) Hard_click(ev *sktools.Interaction)

func (*View) Json_update

func (vp *View) Json_update(elename string, jstr string)

Same as update, but we assume that jstr contains the update json, and elename is the name that we should location. We assume this is invoked when sent a buffer of the form:

jupdate <name> <json information>

func (*View) Paint

func (vp *View) Paint(gc sketch.Graphics_api, scale float64)

Paint renders all view elements, in order, using the graphics context (sketch) passed in. We assume that the underlying graphics medium is double buffered and thus needs to have every element drawn on each call, not just those who think they've changed.

func (*View) Set_scale

func (vp *View) Set_scale(scale float64)

Will set the scale for all elements in the view. Scale for images/graphs does affect size while for most other elements it only affects visibility if an element is painted only when at a certain scale setting.

func (*View) Tickle

func (vp *View) Tickle(elename string, ibuf interface{})

Tickle an element; probably a menu click.

func (*View) Update

func (vp *View) Update(ibuf interface{})

Update processes an update buffer. We expect:

update <element-name> key:["]value["]...

Update is meant to change the dynamics of the dt, size, position, colour, not the data or value. Use Update_data to change the data.

type Vparser

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

func Mk_vparser

func Mk_vparser(scale float64) (vp *Vparser)

Mk_vparser creates the parser struct which is needed to parse or get information about the parsed data.

func (*Vparser) Compute

func (p *Vparser) Compute(vname string, ass_op string, tokens []string)

Compute accepts a variable name, assignment operator, and expression tokens. The expression tokens are evaluated as a reverse polish expression (e.g. 1 2 3 + + or 1 2 * 4 + 6 /) and the result is stored into the named variable using the assignment operator:

 = direct replacement
+= add to current value
-= subtract from current value
*= current value is multipled by result
/= current value is divided by result if result !0

Tokens are expanded, so it is not necessary to expand prior to calling. Any invalid number is treated as a 0. If an expression resulted in zero tokens, then a 0 is applied per the assignment operator.

func (*Vparser) Crunch_rec

func (p *Vparser) Crunch_rec(ibuf interface{}) (rtype string, result interface{})

Crunch a record from the view input. Returns record type and json if it's an element. View record has the format:

<type> <key>:["]value["]

var <vname> <value>
orig <x>,<y>
delta <delta-x>,<delta-y>

Variables are substituted in values using $vname, ${vname} or ${vname:-default}
syntax.

Returns the record type and a pointer to the resuting data struct (Velement, or string) as an interface.

func (*Vparser) Dump_st

func (p *Vparser) Dump_st()

Dump_st spits the parser's symbol table out to standard error.

func (*Vparser) Expand

func (p *Vparser) Expand(buf string) (ebuf string)

Expand searches a string for any $name or ${name} strings and expand with the current value in the symbol tab. We allow the following derefernce syntax:

$vname
${vname}[junk]   (junk not treated as part of the name, and is appended to the expansion
${vname:-default}

Var references s must be separated by space or tab, or the name must be wrapped in curly braces.

func (*Vparser) Expand_tokens

func (p *Vparser) Expand_tokens(tokens []string) string

Expand_tokens ccepts a slice of string pointers and builds an expanded string. Comments (anything after a token with a single hash (#) are removed.

func (*Vparser) Get_origin

func (p *Vparser) Get_origin() (x float64, y float64)

Get origin returns the current x,y coordinates of the origin.

func (*Vparser) Restore

func (p *Vparser) Restore()

Restore will 'pop' the saved state (if one exists) reruning all parser variables, and the symbol table to the state which existed when save was called.

func (*Vparser) Save

func (p *Vparser) Save()

Save will save the current state and push a copy of the parser onto the stack. A "depth" of 64 states may be pushed.

Jump to

Keyboard shortcuts

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