From e226bef8253d50db7c1622aacaf5964f1d505359 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 29 Aug 2023 15:41:50 -0400 Subject: guide done for now --- guide-src/outline.txt | 3 +- guide-src/widget-inputs/builtins.html | 21 ++++++++++++-- guide-src/widget-inputs/constants.html | 3 -- guide-src/widget-inputs/syntax.html | 16 +++++++++++ guide-src/widget-inputs/vectors.html | 3 -- pugl.js | 51 +++++++++++++++++++--------------- style.css | 12 ++++++++ 7 files changed, 76 insertions(+), 33 deletions(-) delete mode 100644 guide-src/widget-inputs/constants.html create mode 100644 guide-src/widget-inputs/syntax.html delete mode 100644 guide-src/widget-inputs/vectors.html diff --git a/guide-src/outline.txt b/guide-src/outline.txt index d59b039..5ded64c 100644 --- a/guide-src/outline.txt +++ b/guide-src/outline.txt @@ -1,7 +1,6 @@ widget-inputs: Widget inputs -/constants.html +/syntax.html /builtins.html -/vectors.html development: Development /index.html /js-features.html diff --git a/guide-src/widget-inputs/builtins.html b/guide-src/widget-inputs/builtins.html index 6434921..32cb3b1 100644 --- a/guide-src/widget-inputs/builtins.html +++ b/guide-src/widget-inputs/builtins.html @@ -1,3 +1,20 @@ ---- Built-in values +--- built-in values -

TODO

+all of pugl's built-in values begin with a . to distinguish +them from your widgets. +here they all are. +below, float refers to a plain old number, +vec2 is a 2-component vector, etc. + + + + + + + + + + + + +
built‑intypedescription
.posvec2the position of the pixel, with (−1, −1) being the bottom-left corner, and (+1, +1) being the top-right corner.
.pos01vec2the position of the pixel, with (0, 0) being the bottom-left corner, and (+1, +1) being the top-right corner.
.timefloatthe amount of time that has passed (wraps around every hour to prevent imprecision issues).
.mousevec2the position of the mouse ranging from (−1, −1) to (+1, +1).
.mouse01vec2the position of the mouse ranging from (0, 0) to (+1, +1).
.pifloatπ (3.1415…).
.2pifloat2π (6.2831…).
diff --git a/guide-src/widget-inputs/constants.html b/guide-src/widget-inputs/constants.html deleted file mode 100644 index a2a89ac..0000000 --- a/guide-src/widget-inputs/constants.html +++ /dev/null @@ -1,3 +0,0 @@ ---- Constants - -

TODO

diff --git a/guide-src/widget-inputs/syntax.html b/guide-src/widget-inputs/syntax.html new file mode 100644 index 0000000..8026b33 --- /dev/null +++ b/guide-src/widget-inputs/syntax.html @@ -0,0 +1,16 @@ +--- syntax +

+here are the various ways of specifying widget inputs: +

+ + + + + + + + + + + +
formatexampledescription
<number>5.3a number
#RRGGBB#ff831ca 3-component vector whose values are taken from the given color code. a color picker will be shown next to the input.
#RRGGBBAA#ff831c22a 4-component vector whose values are taken from the color code.
<widget name>add1the output from another widget
<input>,<input>.pos,0a vector composed of a and b (which can themselves be vectors)
<input>.<component>.pos.xextract a single component from a vector
<input>.<swizzle>.pos.yxyreorder vector components (this example is equivalent to .pos.y, .pos.x, .pos.y)
diff --git a/guide-src/widget-inputs/vectors.html b/guide-src/widget-inputs/vectors.html deleted file mode 100644 index 33bbea1..0000000 --- a/guide-src/widget-inputs/vectors.html +++ /dev/null @@ -1,3 +0,0 @@ ---- Vectors - -

TODO

diff --git a/pugl.js b/pugl.js index b182480..c6b63f8 100644 --- a/pugl.js +++ b/pugl.js @@ -1907,12 +1907,35 @@ ${this.code.join('')} } const dot = input.lastIndexOf('.'); - const field = dot === -1 ? 'out' : input.substring(dot + 1); - - if (field.length === 0) { + if (dot === input.length - 1) { return { error: 'inputs should not end in .' }; } + if (dot === 0) { + switch (input) { + case '.pos': + return { code: '_pos', type: 'vec2' }; + case '.pos01': + return { code: '(0.5+0.5*_pos)', type: 'vec2' }; + case '.time': + return { code: '_time', type: 'float' }; + case '.mouse': + return { code: '_mouse', type: 'vec2' }; + case '.mouse01': + return { code: '(0.5+0.5*_mouse)', type: 'vec2' }; + case '.π': + case '.pi': + return { code: '(3.1415927)', type: 'float' }; + case '.2π': + case '.2pi': + return { code: '(6.2831853)', type: 'float' }; + default: + return { error: `no such builtin: ${input}` }; + } + } + + const field = dot === -1 ? '' : input.substring(dot + 1); + if ( field.length >= 1 && field.length <= 4 && @@ -1937,28 +1960,10 @@ ${this.code.join('')} code: `(${vector.code}).${field}`, type: type_vec(base, field.length), }; - } - - if (dot === 0) { - switch (input) { - case '.pos': - return { code: '_pos', type: 'vec2' }; - case '.pos01': - return { code: '(0.5+0.5*_pos)', type: 'vec2' }; - case '.time': - return { code: '_time', type: 'float' }; - case '.mouse': - return { code: '_mouse', type: 'vec2' }; - case '.mouse01': - return { code: '(0.5+0.5*_mouse)', type: 'vec2' }; - default: - return { error: `no such builtin: ${input}` }; - } - } - - if (field !== 'out') { + } else if (field) { return { error: `no such field: ${field}` }; } + const widget = this.widgets.get(input); if (widget === undefined) { return { error: `cannot find widget '${input}'` }; diff --git a/style.css b/style.css index 7697264..816d95d 100644 --- a/style.css +++ b/style.css @@ -301,3 +301,15 @@ input[type='number'] { .overflow-hidden { overflow: hidden; } + +table { + border-collapse: collapse; + margin: 0.5em; +} + +td, +th { + border: 2px solid white; + margin: 0; + padding: 0.2em; +} -- cgit v1.2.3