Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff188f5a6c |
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
groups:
|
||||||
|
github-actions:
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
@@ -88,7 +88,7 @@ jobs:
|
|||||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@6f5948dfacef28e207b48d0905cf90c03365536d # v3
|
uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v3
|
||||||
with:
|
with:
|
||||||
languages: c-cpp
|
languages: c-cpp
|
||||||
build-mode: manual
|
build-mode: manual
|
||||||
@@ -99,4 +99,4 @@ jobs:
|
|||||||
run: make build
|
run: make build
|
||||||
|
|
||||||
- name: Analyze
|
- name: Analyze
|
||||||
uses: github/codeql-action/analyze@6f5948dfacef28e207b48d0905cf90c03365536d # v3
|
uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v3
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
# workbook
|
|
||||||
|
|
||||||
A native spreadsheet editor written in Ziran with Kryon. It opens, edits and
|
|
||||||
saves `.gnumeric` and CSV documents; `geld` is the finance profile. README.md
|
|
||||||
documents usage, dependencies and the test tooling.
|
|
||||||
|
|
||||||
## Layout
|
|
||||||
|
|
||||||
| Path | Contents |
|
|
||||||
| --- | --- |
|
|
||||||
| `src/editor.zi` | Editor state, input and spreadsheet actions |
|
|
||||||
| `src/editor_api.zi` | Embeddable editor exported as `workbook/editor` (handle, frame, save) |
|
|
||||||
| `src/editor_view.tsx`, `src/grid_view.tsx` | Editor and cell composition |
|
|
||||||
| `src/desktop.tsx`, `src/app.zi`, `src/app_view.tsx` | Desktop and Werkzeug document hosts, menus and application layout |
|
|
||||||
| `src/geld_profile.zi` | The geld profile's sheet styling and one rate refresh at open |
|
|
||||||
| `src/engine.zi` | Spreadsheet engine for new workbooks and CSV |
|
|
||||||
| `src/cell.zi` | Headless engine driver (`cell eval FILE`) |
|
|
||||||
| `src/gnumeric.zi` | Imported-document support through the installed gnumeric library |
|
|
||||||
| `previews/host.tsx`, `previews/host_state.zi` | Minimal host with a sidebar around the embedded editor |
|
|
||||||
| `tests/` | Structure, conversion, desktop, host, menu and parity tests |
|
|
||||||
| `docs/GNUMERIC_PARITY.md` | Document-format notes and the function inventory |
|
|
||||||
|
|
||||||
## Commands
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make # build ./build/workbook-desktop and ./build/cell
|
|
||||||
make check # type-check app, driver and tests
|
|
||||||
make test # full suite; desktop and host tests on private displays, parity
|
|
||||||
make test-ci # CI suite without parity
|
|
||||||
make host-test # the exported editor inside a minimal host, private display
|
|
||||||
make parity # compare against gnumeric ssconvert
|
|
||||||
make fuzz REFERENCE=PATH # compare against another cell build
|
|
||||||
make install # install workbook, cell and geld under ~/.local
|
|
||||||
```
|
|
||||||
|
|
||||||
## Pins
|
|
||||||
|
|
||||||
- Ziran toolchain: `101b3d2f4e40278cbde18821a097765488bd32d8`
|
|
||||||
- Kryon: `81ade4bb49db8cc2b02a48b437b7db1db09b895e`
|
|
||||||
- mingcute: `9cc6872f75447c3a24c16764f9829d0f58751cb0`
|
|
||||||
|
|
||||||
Commit as Waozi <waozi@proton.me>; ordinary changes stay in CHANGELOG's
|
|
||||||
`Unreleased` section.
|
|
||||||
@@ -2,96 +2,6 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- Keep default and unfilled spreadsheet cells white in dark desktop themes,
|
|
||||||
preserving authored section fills and readable text while editing.
|
|
||||||
- Recalculate only dirty native formula dependencies after cell edits, refresh
|
|
||||||
only the edited sheet's extent, and avoid duplicate recalculation. Debounce
|
|
||||||
autosave by 500 ms and flush pending changes on normal desktop exit.
|
|
||||||
- Initialize native TSX records explicitly for the current compiler and separate
|
|
||||||
chart composition from editor state to avoid a native header import cycle.
|
|
||||||
|
|
||||||
- Copy imported cells with their complete native styles and formulas, including blank styled cells and ranges larger than 8 KiB. Keep the clipboard snapshot alive through undo and document replacement. Use icons for bold, italic, text color and cell fill controls.
|
|
||||||
|
|
||||||
- Keep large imported workbooks responsive during row/column deletion and hiding: load cell values on demand, retain lightweight undo snapshots, avoid duplicate recalculation and perform ODS autosave in a managed writer process. Delete selected row or column ranges together and report native failures.
|
|
||||||
- Add visible text color and cell fill toolbar controls. Refresh owned pension security quotes together with Geld startup exchange rates.
|
|
||||||
|
|
||||||
- Scroll past the last populated row without snapping back. Add column-header context actions for inserting and deleting columns, plus Format, Font and Color menus that preserve formulas and other cell styles when saved.
|
|
||||||
|
|
||||||
- Preserve optional ODS decimal places, including inherited column formats, across opening and saving. Display quantities without trailing decimal zeros while preserving explicit money formats.
|
|
||||||
|
|
||||||
- Open the canonical Geld portfolio by default and refresh its exchange rates at
|
|
||||||
startup. Let ordinary ODS cells follow the desktop theme while retaining colored
|
|
||||||
section formatting. Compact empty ODS grid tails before
|
|
||||||
loading and after saving to prevent excessive memory use on large sheets.
|
|
||||||
|
|
||||||
- Align the standalone and hosted editors with published Ziran `52aa4063`
|
|
||||||
and Kryon `5a08a314`.
|
|
||||||
|
|
||||||
- Give the geld finance profile its sheet presentation and its rate refresh:
|
|
||||||
section rows draw as navy bands with white bold text and total rows as
|
|
||||||
light blue bands with dark bold text, written through native sheet styles
|
|
||||||
and saved with the document, and the rates its rows name refresh once at
|
|
||||||
open — coingecko for crypto ids, `open.er-api.com` with `frankfurter.app`
|
|
||||||
as fallback for fiat — with the pct column set against each row's previous
|
|
||||||
rate, never fetched again while the window stays open; a rate cell that
|
|
||||||
holds a formula keeps its own rate.
|
|
||||||
|
|
||||||
- Write native sheet styles through `Engine.WorkbookStyleRange`, binding the
|
|
||||||
gnumeric ABI's `gnm_style_*` and `sheet_style_apply_range`, which merges a
|
|
||||||
partial style onto the region's existing elements the way imported styles
|
|
||||||
survive.
|
|
||||||
|
|
||||||
- Use the compiler fix that stores TS and TSX exports as checked `.zir` modules
|
|
||||||
in published ZX libraries.
|
|
||||||
|
|
||||||
- Snapshot sheet names before hosted metadata requests so tab labels remain
|
|
||||||
distinct and formula-reference actions keep valid text.
|
|
||||||
|
|
||||||
- Pin Ziran bbaac5e4 and Kryon de391af5 so the standalone and hosted editors
|
|
||||||
share the published TSX runtime and native project build helpers with owned fingerprint scratch. Keep widget
|
|
||||||
and container composition package-private behind the typed TSX component
|
|
||||||
boundary that Workbook already uses.
|
|
||||||
|
|
||||||
- Use public Kryon TSX components throughout the editor, read-only grid and
|
|
||||||
menus, retaining native chart rendering and the embedded editor API. Use TSX
|
|
||||||
application and preview entries with the published renderer/compiler, and
|
|
||||||
remove the unused CSS dependency.
|
|
||||||
|
|
||||||
- Compose Workbook's hosted document menus and spreadsheet editor in native
|
|
||||||
TSX. The `Main` bundle entry and `workbook/editor` API keep their signatures.
|
|
||||||
|
|
||||||
- Build on Kryon 58c3aed9 and Css 46a3396a (Css now pins Kryon 58c3aed9; the previous Css 095874a1 pinned a Kryon revision the mirror does not serve).
|
|
||||||
- Build with Ziran c041afb6 and Kryon 09664f07: the desktop app and the preview host declare `main` and run `App.Run` like every Kryon program now that the program-export program entry is gone; the Werkzeug hosted `Main` protocol keeps its C-ABI export.
|
|
||||||
- Full OpenDocument Spreadsheet (`.ods`) support via Gnumeric's OpenCalc
|
|
||||||
engine: open, evaluate, edit, undo/redo, and save `.ods` workbooks directly
|
|
||||||
in Workbook, embedded `workbook/editor`, and `cell`, including file picker
|
|
||||||
filters, drag-and-drop, and `application/vnd.oasis.opendocument.spreadsheet`
|
|
||||||
MIME registration.
|
|
||||||
- Render embedded ODS/Gnumeric charts (`SheetObjectGraph` / `GogGraph`) live
|
|
||||||
over the grid via Cairo at their anchor coordinates with viewport clipping,
|
|
||||||
texture caching, smooth scrolling, and automatic refresh on cell edits.
|
|
||||||
- Support rich spreadsheet layout and formatting: merged cells, exact ODS cell
|
|
||||||
backgrounds, text colors (including number-format color rules and evaluated
|
|
||||||
conditional formatting overlays), per-edge border colors and weights, ODS
|
|
||||||
paper canvas and subtle gridlines, colored sheet tabs (`table:tab-color`),
|
|
||||||
bold/italic/font-size styles, horizontal alignment, custom column widths and
|
|
||||||
row heights, hidden columns, collapsed multi-row hidden spans, hidden sheet
|
|
||||||
filtering on the tab bar (`View → Show hidden sheets`), and scrollable sheet
|
|
||||||
tabs for workbooks with more than 16 sheets.
|
|
||||||
- Export the full editor as `workbook/editor` for other Kryon apps:
|
|
||||||
`EditorOpen`/`EditorNew` return a handle, `EditorFrame` draws and handles one
|
|
||||||
frame in a host region, `EditorSave`/`EditorSaveAs` save it, and
|
|
||||||
`EditorClose` releases it. Undo, autosave, focus and the per-document change
|
|
||||||
and save counters belong to the handle; `EditorSample` passes input without
|
|
||||||
taking the keyboard from an unfocused host. `make host-test` embeds it in a
|
|
||||||
minimal host on a private display.
|
|
||||||
- The standalone app and the Werkzeug bundle use that same editor; `src/app.zi`
|
|
||||||
keeps profiles, documents, the window title, menus and the theme.
|
|
||||||
- Build the Werkzeug bundle from the project's exports with
|
|
||||||
`ziran bundle --project`.
|
|
||||||
- Pin Kryon `facaace3`, CSS `7dd9fff2` and Ziran `9432a110` to share the
|
|
||||||
Autotrade, plot and data_views build graph.
|
|
||||||
- Build the editor and embedded grid against Kryon's public widget modules.
|
|
||||||
- Other Kryon apps embed Workbook's own grid with `workbook/grid` and
|
- Other Kryon apps embed Workbook's own grid with `workbook/grid` and
|
||||||
`workbook/engine`: real cells and formulas, sheet tabs, column widths and
|
`workbook/engine`: real cells and formulas, sheet tabs, column widths and
|
||||||
count or money formats. The editor paints with the same grid squares. It
|
count or money formats. The editor paints with the same grid squares. It
|
||||||
|
|||||||
@@ -11,17 +11,16 @@ DIST_DIR ?= dist
|
|||||||
|
|
||||||
APP := build/workbook-desktop
|
APP := build/workbook-desktop
|
||||||
CELL := build/cell
|
CELL := build/cell
|
||||||
HOST_APP := build/preview/desktop/host/workbook-desktop
|
TESTS := gnumeric_test source_audit_test structure_test conversion_test differential_fuzz desktop_test parity_test service_test grid_test
|
||||||
TESTS := gnumeric_test source_audit_test structure_test conversion_test differential_fuzz desktop_test parity_test service_test grid_test host_test
|
|
||||||
TEST_PROGRAMS := $(TESTS:%=build/%)
|
TEST_PROGRAMS := $(TESTS:%=build/%)
|
||||||
SOURCES := $(wildcard src/*.zi src/*.tsx) ziran.toml ziran.lock
|
SOURCES := $(wildcard src/*.zi) ziran.toml ziran.lock
|
||||||
|
|
||||||
# Programs that read their arguments from main(argc, argv) build without
|
# Programs that read their arguments from main(argc, argv) build without
|
||||||
# -pedantic-errors: C wants that signature spelled with char, and signed char
|
# -pedantic-errors: C wants that signature spelled with char, and signed char
|
||||||
# has the same layout.
|
# has the same layout.
|
||||||
NATIVE_FLAGS := -std=c99 -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections
|
NATIVE_FLAGS := -std=c99 -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections
|
||||||
|
|
||||||
.PHONY: build cell check run test test-ci grid-test structure-test conversion-test gnumeric-test desktop-test hidden-rows-test host-test parity fuzz audit install deb clean
|
.PHONY: build cell check run test test-ci grid-test structure-test conversion-test gnumeric-test desktop-test hidden-rows-test parity fuzz audit install deb clean
|
||||||
|
|
||||||
build: $(APP) $(CELL)
|
build: $(APP) $(CELL)
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ $(APP): $(SOURCES)
|
|||||||
define program
|
define program
|
||||||
@$(ZIRAN) build --project --target=c --entry $(1):main -o $(3)-c $(2)
|
@$(ZIRAN) build --project --target=c --entry $(1):main -o $(3)-c $(2)
|
||||||
@$(CC) $(NATIVE_FLAGS) -I$(shell $(ZIRAN) pkg path ziran)/include -I$(3)-c \
|
@$(CC) $(NATIVE_FLAGS) -I$(shell $(ZIRAN) pkg path ziran)/include -I$(3)-c \
|
||||||
$(3)-c/*.c -lm $(if $(filter desktop_test host_test,$(1)),-lX11) -o $(3)
|
$(3)-c/*.c -lm $(if $(filter desktop_test,$(1)),-lX11) -o $(3)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# The engine driver, and the test programs, which are Ziran too.
|
# The engine driver, and the test programs, which are Ziran too.
|
||||||
@@ -49,7 +48,6 @@ $(TEST_PROGRAMS): build/%: tests/%.zi $(SOURCES) $(wildcard tests/*.zi)
|
|||||||
check:
|
check:
|
||||||
@$(ZIRAN) check
|
@$(ZIRAN) check
|
||||||
@$(ZIRAN) check --project src/cell.zi
|
@$(ZIRAN) check --project src/cell.zi
|
||||||
@$(ZIRAN) check --project previews/host.tsx
|
|
||||||
@for test in $(TESTS); do $(ZIRAN) check --project tests/$$test.zi || exit 1; done
|
@for test in $(TESTS); do $(ZIRAN) check --project tests/$$test.zi || exit 1; done
|
||||||
|
|
||||||
run:
|
run:
|
||||||
@@ -69,15 +67,7 @@ desktop-test: build build/desktop_test
|
|||||||
hidden-rows-test: build build/desktop_test
|
hidden-rows-test: build build/desktop_test
|
||||||
@env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS YUE_DESKTOP_RECOVERY=0 GSETTINGS_BACKEND=memory build/desktop_test --hidden-only
|
@env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS YUE_DESKTOP_RECOVERY=0 GSETTINGS_BACKEND=memory build/desktop_test --hidden-only
|
||||||
|
|
||||||
# The host app is a preview fixture that embeds the exported editor beside
|
test-ci: build service-test grid-test audit structure-test conversion-test gnumeric-test desktop-test
|
||||||
# host-owned UI. It is built with Kryon's test driver so host_test can drive it.
|
|
||||||
host-test: $(HOST_APP) build/host_test
|
|
||||||
@build/host_test
|
|
||||||
|
|
||||||
$(HOST_APP): $(SOURCES) previews/host.tsx
|
|
||||||
@KRYON_TEST_DRIVER=1 $(ZIRAN) tool kryon preview host --output build/host-preview.png --width 960 --height 640 --theme light
|
|
||||||
|
|
||||||
test-ci: build service-test grid-test audit structure-test conversion-test gnumeric-test desktop-test host-test
|
|
||||||
|
|
||||||
test: test-ci parity
|
test: test-ci parity
|
||||||
|
|
||||||
@@ -169,7 +159,7 @@ gnumeric-test: build/gnumeric_test
|
|||||||
bundle: build/workbook.zib
|
bundle: build/workbook.zib
|
||||||
build/workbook.zib: $(SOURCES)
|
build/workbook.zib: $(SOURCES)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@$(ZIRAN) bundle --project --define KRYON_HOSTED_UI --entry app:Main -o $@ src/app.zi
|
@$(ZIRAN) bundle --root . --module-path src --module-path $(shell $(ZIRAN) pkg path ziran)/std --module-path kryon=$(shell $(ZIRAN) pkg path kryon)/src/ui --module-path kryon=$(shell $(ZIRAN) pkg path kryon)/src/backend --module-path $(shell $(ZIRAN) pkg path kryon)/src/ui --module-path $(shell $(ZIRAN) pkg path kryon)/src/backend --module-path $(shell $(ZIRAN) pkg path mingcute)/src --define KRYON_HOSTED_UI --entry app:Main -o $@ src/app.zi
|
||||||
|
|
||||||
.PHONY: service-test
|
.PHONY: service-test
|
||||||
service-test: build/service_test
|
service-test: build/service_test
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# workbook
|
# workbook
|
||||||
|
|
||||||
Native spreadsheet editor written in [Ziran](https://git.waozi.xyz/ziranlang/ziran)
|
Native spreadsheet editor written in [Ziran](https://github.com/ziranlang/ziran)
|
||||||
with [Kryon](https://git.waozi.xyz/kryonlabs/kryon). Open a document from your file
|
with [Kryon](https://github.com/kryonlabs/kryon). Open a document from your file
|
||||||
manager, drop it onto Workbook, or pass its path directly:
|
manager, drop it onto Workbook, or pass its path directly:
|
||||||
|
|
||||||
workbook /path/to/file.gnumeric
|
workbook /path/to/file.gnumeric
|
||||||
@@ -10,10 +10,8 @@ The window title shows the document's filename. Edits save back to that file;
|
|||||||
when you drop another document, Workbook saves the current edit before opening
|
when you drop another document, Workbook saves the current edit before opening
|
||||||
it. Launching without a file uses the profile described below.
|
it. Launching without a file uses the profile described below.
|
||||||
|
|
||||||
The document host, editor and read-only grid compose their interface in native
|
Everything in the repository is Ziran (`.zi`) apart from the Makefile and
|
||||||
TSX using Kryon's public components. `src/desktop.tsx` is the desktop entry;
|
configuration. `src/app.zi` is the desktop application, `src/engine.zi` is the
|
||||||
`src/app.zi` handles profiles and documents,
|
|
||||||
`src/editor.zi` handles editor state and actions, `src/engine.zi` is the
|
|
||||||
spreadsheet engine, and `src/cell.zi` is the headless driver. Imported documents
|
spreadsheet engine, and `src/cell.zi` is the headless driver. Imported documents
|
||||||
use the installed `gnumeric` library for loading, calculation and saving.
|
use the installed `gnumeric` library for loading, calculation and saving.
|
||||||
New workbooks and CSV use the independent Ziran engine. Document format,
|
New workbooks and CSV use the independent Ziran engine. Document format,
|
||||||
@@ -32,11 +30,10 @@ development packages installed.
|
|||||||
make cell # build only the headless engine driver
|
make cell # build only the headless engine driver
|
||||||
make check # type-check the application, the driver, and the tests
|
make check # type-check the application, the driver, and the tests
|
||||||
make run # open the editor
|
make run # open the editor
|
||||||
make test # source audit, structure and conversion tests, desktop and host tests on private displays, gnumeric parity
|
make test # source audit, structure and conversion tests, desktop test on a private display, gnumeric parity
|
||||||
make test-ci # the same without parity, which is what CI runs
|
make test-ci # the same without parity, which is what CI runs
|
||||||
make gnumeric-test # native document, edit, undo and round-trip regressions
|
make gnumeric-test # native document, edit, undo and round-trip regressions
|
||||||
make hidden-rows-test # row visibility, totals and undo/redo on a private display
|
make hidden-rows-test # row visibility, totals and undo/redo on a private display
|
||||||
make host-test # the exported editor inside a minimal host, on a private display
|
|
||||||
make parity # evaluation and round-trip tests against Gnumeric
|
make parity # evaluation and round-trip tests against Gnumeric
|
||||||
make fuzz REFERENCE=PATH # compare this cell with another on generated inputs
|
make fuzz REFERENCE=PATH # compare this cell with another on generated inputs
|
||||||
make install # install workbook, cell, and geld under ~/.local
|
make install # install workbook, cell, and geld under ~/.local
|
||||||
@@ -94,21 +91,16 @@ A run that hangs is killed after `FUZZ_TIMEOUT` seconds (20 by default).
|
|||||||
Esc leave the formula bar without changing the cell
|
Esc leave the formula bar without changing the cell
|
||||||
Delete clear the selected cell
|
Delete clear the selected cell
|
||||||
double click edit the clicked cell in the formula bar
|
double click edit the clicked cell in the formula bar
|
||||||
right click open cell, row-header or column-header actions
|
right click open the cell menu, including when activating the window
|
||||||
Ctrl+C/X/V copy, cut, or paste cells (styles retained inside Workbook)
|
Ctrl+C/X/V copy, cut, or paste cells through the system clipboard
|
||||||
Ctrl+Z undo; while a cell is edited, undo its typing word by word
|
Ctrl+Z undo; while a cell is edited, undo its typing word by word
|
||||||
Ctrl+Y redo (also Ctrl+Shift+Z)
|
Ctrl+Y redo (also Ctrl+Shift+Z)
|
||||||
wheel scroll rows, including beyond the last populated cell
|
wheel scroll rows
|
||||||
Ctrl+S save
|
Ctrl+S save
|
||||||
Chart button create a linked formula chart from a selected label/value range
|
|
||||||
|
|
||||||
Formula cells show their calculated value in the grid and their source in the
|
Formula cells show their calculated value in the grid and their source in the
|
||||||
formula bar. Imported cell ranges retain colors, fonts, borders, number formats and
|
formula bar. The toolbar provides save and row/column insertion and deletion,
|
||||||
relative formulas when copied and pasted within Workbook. Plain text remains
|
and the sheet tabs at the bottom switch sheets. Cells accept text, numbers, or
|
||||||
available on the system clipboard for other applications. The toolbar uses icons
|
|
||||||
for bold, italic, text color and cell fill. It also provides save and row/column
|
|
||||||
insertion and deletion.
|
|
||||||
The sheet tabs at the bottom switch sheets. Cells accept text, numbers, or
|
|
||||||
formulas in the Gnumeric expression language.
|
formulas in the Gnumeric expression language.
|
||||||
|
|
||||||
Right-click a row number and choose **Hide rows** to collapse it to a thin
|
Right-click a row number and choose **Hide rows** to collapse it to a thin
|
||||||
@@ -117,12 +109,8 @@ to show its row again; both actions support undo and redo. Hidden rows stay
|
|||||||
in the document. Use `=SUBTOTAL(109,A1:A20)` for totals that skip hidden rows;
|
in the document. Use `=SUBTOTAL(109,A1:A20)` for totals that skip hidden rows;
|
||||||
ordinary `SUM` and `SUBTOTAL(9,…)` continue to include them.
|
ordinary `SUM` and `SUBTOTAL(9,…)` continue to include them.
|
||||||
|
|
||||||
ODS autosave converts an immutable snapshot in a short-lived writer process,
|
Changes save automatically, including the cell you are typing, pasted values,
|
||||||
keeping the editor responsive while the file is compressed. Undo snapshots
|
and inserted or deleted rows and columns. Clicking another cell or closing the
|
||||||
retain the native document stream and restore it only when used.
|
|
||||||
|
|
||||||
Changes save automatically after 500 ms without edits, including the cell you
|
|
||||||
are typing, pasted values, and inserted or deleted rows and columns. Clicking another cell or closing the
|
|
||||||
app keeps the latest edit without requiring Enter or Ctrl+S. Escape restores
|
app keeps the latest edit without requiring Enter or Ctrl+S. Escape restores
|
||||||
the cell's value from before the edit. A failed save leaves the previous file
|
the cell's value from before the edit. A failed save leaves the previous file
|
||||||
intact, reports the failure in the status bar, and retries automatically.
|
intact, reports the failure in the status bar, and retries automatically.
|
||||||
@@ -132,16 +120,10 @@ fill, and row or column insertion and deletion, each with the formula
|
|||||||
references it moved. Undoing a change selects the cells it touched again and
|
references it moved. Undoing a change selects the cells it touched again and
|
||||||
shows their sheet. Up to the last 100 changes can be undone.
|
shows their sheet. Up to the last 100 changes can be undone.
|
||||||
|
|
||||||
Select a two-column label/value range, then use **Chart** in the toolbar or
|
|
||||||
**Sheet → Create formula chart from selection**. Workbook adds a new sheet whose
|
|
||||||
labels and values link to the selected cells, plus a live text bar chart. This
|
|
||||||
portable chart works in ordinary `.gnumeric` documents and updates when its
|
|
||||||
source values change.
|
|
||||||
|
|
||||||
## profiles
|
## profiles
|
||||||
|
|
||||||
`workbook` is the generic profile. `geld` is a link to the same program; it
|
`workbook` is the generic profile. `geld` is a link to the same program; it
|
||||||
opens the current finance portfolio because of the
|
opens the finance profile, with an independent data directory, because of the
|
||||||
name it is started under (`WORKBOOK_PROFILE=geld workbook` does the same).
|
name it is started under (`WORKBOOK_PROFILE=geld workbook` does the same).
|
||||||
`WORKBOOK_PROFILE=NAME workbook` opens any other profile the same way, with its
|
`WORKBOOK_PROFILE=NAME workbook` opens any other profile the same way, with its
|
||||||
data in `$XDG_DATA_HOME/NAME`; a name uses lowercase letters, digits, `-` and
|
data in `$XDG_DATA_HOME/NAME`; a name uses lowercase letters, digits, `-` and
|
||||||
@@ -153,24 +135,6 @@ application:
|
|||||||
G = value, e.g. =D1*E1
|
G = value, e.g. =D1*E1
|
||||||
H = diff, e.g. =(E1-OLD_RATE)*D1
|
H = diff, e.g. =(E1-OLD_RATE)*D1
|
||||||
|
|
||||||
The geld profile sheet also carries its presentation: section rows draw as
|
|
||||||
navy bands with white bold text, and total rows as light blue bands with
|
|
||||||
dark bold text, the palette the portfolio documents use. The exchange rates
|
|
||||||
its rows name refresh once when the profile starts. Owned pension securities
|
|
||||||
in Holdings also refresh their USD quotes from Yahoo Finance, with source and
|
|
||||||
market timestamps retained internally. The rates are saved back with
|
|
||||||
the pct column set against each row's previous rate:
|
|
||||||
|
|
||||||
- crypto, by ticker (`XMR`, `BTC`, `ETH`, `LTC`) or coingecko market id:
|
|
||||||
`api.coingecko.com` (simple price, usd)
|
|
||||||
- fiat (`EUR`, `USD`, `GBP`, `JPY`, `BRL`, `CHF`, `AUD`, `CAD`, `SGD`,
|
|
||||||
`IDR`, `THB`, `PYG`): `open.er-api.com`, `frankfurter.app` as fallback
|
|
||||||
|
|
||||||
Rates are fetched once when the Geld profile starts. They are never fetched
|
|
||||||
again while the window stays open, so editing cannot be interrupted by
|
|
||||||
network refreshes. A rate cell that holds a formula keeps its own rate, and
|
|
||||||
an id a source does not know keeps its last saved rate.
|
|
||||||
|
|
||||||
The `profiles/*.json` files are profile metadata, not source code.
|
The `profiles/*.json` files are profile metadata, not source code.
|
||||||
|
|
||||||
## data
|
## data
|
||||||
@@ -182,13 +146,10 @@ first of:
|
|||||||
workbook.gnumeric in the current directory
|
workbook.gnumeric in the current directory
|
||||||
~/.local/share/workbook/workbook.gnumeric
|
~/.local/share/workbook/workbook.gnumeric
|
||||||
|
|
||||||
Geld opens `~/Documents/Geld/Geld_Portfolio.ods` by default and attempts an
|
Geld always uses `GELD_DIR` when set, or `$XDG_DATA_HOME/geld` (default
|
||||||
exchange-rate refresh once at startup. Application controls follow the desktop
|
`~/.local/share/geld`). A workbook in the directory Geld was launched from
|
||||||
theme. Spreadsheet paper and default/unfilled cells stay white; colored sections
|
does not replace its finance profile. Missing data directories are created
|
||||||
keep their formatting. `GELD_DIR`, when explicitly set,
|
automatically. Named profiles and explicit data-directory overrides import
|
||||||
selects a separate `workbook.gnumeric` for legacy profile use. A workbook in the
|
|
||||||
launch directory does not replace the finance portfolio. Missing generic and
|
|
||||||
explicit profile data directories are created automatically. Named profiles and explicit data-directory overrides import
|
|
||||||
legacy `workbook.json` files when no `workbook.gnumeric` exists beside them; subsequent changes go to
|
legacy `workbook.json` files when no `workbook.gnumeric` exists beside them; subsequent changes go to
|
||||||
`workbook.gnumeric`, keeping the original JSON intact. Ordinary Workbook launches leave the former
|
`workbook.gnumeric`, keeping the original JSON intact. Ordinary Workbook launches leave the former
|
||||||
finance JSON untouched and start with an empty sheet when no saved document exists.
|
finance JSON untouched and start with an empty sheet when no saved document exists.
|
||||||
@@ -227,81 +188,10 @@ GridDraw(session, bounds, book, *view, GridSample(session, bounds))
|
|||||||
`make grid-test` checks it.
|
`make grid-test` checks it.
|
||||||
|
|
||||||
|
|
||||||
## Embedded editor
|
|
||||||
|
|
||||||
Other Kryon apps embed the complete editor — toolbar, formula bar, cell grid,
|
|
||||||
selection, formula reference picking, fill handle, copy/cut/paste, hidden rows,
|
|
||||||
undo/redo, sheet tabs and automatic saving — with the `workbook/editor` export.
|
|
||||||
Each document is an `Editor` handle with its own workbook, undo history and
|
|
||||||
autosave; the host owns the window, menus and other pages.
|
|
||||||
|
|
||||||
```jai
|
|
||||||
using Editor :: #import "workbook/editor";
|
|
||||||
handle := EditorOpen("plan.gnumeric") // null when it cannot be read
|
|
||||||
defer { EditorClose(handle) }
|
|
||||||
typed: [128]u8
|
|
||||||
HostFrame :: (session: Session, bounds: Rectangle) -> s32 {
|
|
||||||
input := EditorSample(session, bounds, handle, typed[:])
|
|
||||||
unused EditorFrame(session, bounds, handle, input)
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`EditorFrame` draws inside the given bounds and handles one frame of input; it
|
|
||||||
returns whether the editor consumed it. The editor takes the keyboard only
|
|
||||||
while focused: a press inside focuses it, a press outside commits and releases
|
|
||||||
it, and Escape on the grid releases it. `EditorSample` follows that rule, and a
|
|
||||||
host with its own keyboard UI can call `EditorSetFocused` instead. Give each
|
|
||||||
embedded editor its own key base with `EditorSetKeyBase` so widget keys do not
|
|
||||||
collide.
|
|
||||||
|
|
||||||
Documents:
|
|
||||||
|
|
||||||
- `EditorOpen(path) -> *Editor` opens a `.gnumeric` or `.csv`; `EditorNew(path = "")`
|
|
||||||
makes an empty workbook. Both, and `EditorClose(editor)`, exist only in
|
|
||||||
native builds.
|
|
||||||
- `EditorInitWithWorkbook(editor, book, path, load_failed = false)` starts a
|
|
||||||
caller-owned, zero-initialized `Editor`; `EditorDestroy` releases its workbook
|
|
||||||
without freeing the handle. The Werkzeug bundle uses this because its host
|
|
||||||
cannot allocate.
|
|
||||||
- `EditorSave(editor, finish_edit = true) -> bool` saves to the handle's path
|
|
||||||
(CSV for `.csv`), `EditorSaveAs(editor, path) -> bool` saves a copy and
|
|
||||||
switches to it, and `EditorOpenPath(editor, path) -> bool` replaces the
|
|
||||||
document, saving the current one first.
|
|
||||||
- `EditorDirty`, `EditorSaveCount` and `EditorChangeCount` tell a host when to
|
|
||||||
refresh data computed from the document. The counters only grow; autosave and
|
|
||||||
undo belong to the handle. `EditorSetAutosave(editor, false)` leaves saving to
|
|
||||||
the host.
|
|
||||||
- `EditorWorkbook(editor) -> *Engine.Workbook` gives a host read access for
|
|
||||||
totals and other derived views. `EditorPath(editor, out)` and
|
|
||||||
`EditorStatus(editor, out)` copy into caller storage, and
|
|
||||||
`EditorSetStatus(editor, message)` puts a host message in the status bar.
|
|
||||||
- `EditorFocused`, `EditorEditingCell`, `EditorCanUndo`, `EditorCanRedo`,
|
|
||||||
`EditorSheetIndex`, `EditorSheetCount` and `EditorClipboardAvailable` are
|
|
||||||
queries.
|
|
||||||
|
|
||||||
Commands a host can place in its own menus: `EditorUndo`, `EditorRedo`,
|
|
||||||
`EditorCut`, `EditorCopy`, `EditorPaste`, `EditorClear`, `EditorSelectAll`,
|
|
||||||
`EditorGoToFirstCell`, `EditorInsertRow`, `EditorInsertRowBelow`,
|
|
||||||
`EditorDeleteRow`, `EditorInsertColumn`, `EditorDeleteColumn`, `EditorAddSheet`,
|
|
||||||
`EditorSelectSheet`, `EditorRecalculate` and `EditorCreateFormulaChart`.
|
|
||||||
|
|
||||||
The standalone Workbook app uses this same module; `src/app.zi` adds profile
|
|
||||||
selection, documents, the window title, menus and the theme. `make host-test`
|
|
||||||
builds `previews/host.tsx`, a minimal host with a host-owned sidebar, and drives
|
|
||||||
it on a private X display: open a `.gnumeric` and a `.csv`, type a value and a
|
|
||||||
formula, undo/redo, save, close, reopen and hand focus between host and editor.
|
|
||||||
|
|
||||||
Native Gnumeric charts and drawing objects stay in a saved document but are not
|
|
||||||
drawn; the embedded editor has the same limitation as the grid. Showing them
|
|
||||||
needs a chart view over the document's chart objects.
|
|
||||||
|
|
||||||
|
|
||||||
## Werkzeug app bundle
|
## Werkzeug app bundle
|
||||||
|
|
||||||
`make bundle` builds `build/workbook.zib`, the spreadsheet editor for a host
|
`make bundle` builds `build/workbook.zib`, the spreadsheet editor for a host
|
||||||
with the `spreadsheet.v1` capability. Werkzeug builds `workbook.zx` from the
|
with the `spreadsheet.v1` capability. Werkzeug on Linux includes the native
|
||||||
same `src/app.zi` entry and its `Main` export. Werkzeug on Linux includes the native
|
|
||||||
calculation service and keeps Workbook documents in its own private folder.
|
calculation service and keeps Workbook documents in its own private folder.
|
||||||
The bundle runs in Werkzeug on Linux, Android and the web, with the same compact grid, bottom sheet tabs and editing commands
|
The bundle runs in Werkzeug on Linux, Android and the web, with the same compact grid, bottom sheet tabs and editing commands
|
||||||
as the desktop editor. Its File menu imports and exports documents with the
|
as the desktop editor. Its File menu imports and exports documents with the
|
||||||
@@ -318,9 +208,3 @@ Gnumeric document metadata are not preserved by the built-in document reader.
|
|||||||
|
|
||||||
The native menu bar contains File, Edit, View, Insert and Sheet. Ctrl+O opens
|
The native menu bar contains File, Edit, View, Insert and Sheet. Ctrl+O opens
|
||||||
a document, Ctrl+Shift+S saves a copy, and F10 or Alt+F focuses the menus.
|
a document, Ctrl+Shift+S saves a copy, and F10 or Alt+F focuses the menus.
|
||||||
|
|
||||||
ODS import and export preserve optional decimal places in plain number styles, including inherited row and column formats. For example, units formatted as `0.##` display as `11` or `0.4`, while fixed currency formats retain two decimals. Stored values and formulas keep their full precision.
|
|
||||||
|
|
||||||
The Format, Font and Color menus edit selected imported workbook cells: bold,
|
|
||||||
italic, alignment, number formats, font family and size, text color and cell fill.
|
|
||||||
Column headers offer insert before/after and delete, with Undo.
|
|
||||||
@@ -5,4 +5,4 @@ Comment=Spreadsheet editor
|
|||||||
Exec=workbook %f
|
Exec=workbook %f
|
||||||
Terminal=false
|
Terminal=false
|
||||||
Categories=Office;Spreadsheet;
|
Categories=Office;Spreadsheet;
|
||||||
MimeType=application/x-gnumeric;application/vnd.oasis.opendocument.spreadsheet;
|
MimeType=application/x-gnumeric;
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import * as NativeButton from "kryon/button";
|
|
||||||
import * as NativeBox from "kryon/box";
|
|
||||||
// A real TSX host around the public embedded editor, driven on a private display.
|
|
||||||
import * as App from "kryon/app";
|
|
||||||
import * as State from "host_state";
|
|
||||||
import * as Editor from "workbook/editor";
|
|
||||||
import * as Grid from "grid";
|
|
||||||
import * as NativeText from "kryon/text";
|
|
||||||
import { Box } from "kryon/tsx/box";
|
|
||||||
import { Button } from "kryon/tsx/button";
|
|
||||||
import { Text } from "kryon/tsx/text";
|
|
||||||
import { Rectangle } from "kryon/geometry";
|
|
||||||
import { Session } from "kryon/session";
|
|
||||||
|
|
||||||
function ActionLabel(id: s32): string {
|
|
||||||
if (id === s32(1)) { return "Host focus"; }
|
|
||||||
if (id === s32(2)) { return "Editor focus"; }
|
|
||||||
if (id === s32(3)) { return "Save"; }
|
|
||||||
if (id === s32(4)) { return "Close"; }
|
|
||||||
if (id === s32(5)) { return "Open Gnumeric"; }
|
|
||||||
if (id === s32(6)) { return "Open CSV"; }
|
|
||||||
return "Reopen";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Frame(frame: App.Frame): void {
|
|
||||||
const session: Session = nativeInit<Session>({slot: frame.slot, epoch: frame.epoch});
|
|
||||||
const viewport = frame.viewport;
|
|
||||||
State.Begin();
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: u64(900000),
|
|
||||||
bounds: {x: viewport.x, y: viewport.y, width: 200.0, height: viewport.height},
|
|
||||||
fill: Grid.GridColor("surface"), border: Grid.GridColor("border-soft")})}/>;
|
|
||||||
const x = viewport.x + float32(12);
|
|
||||||
for (let id = s32(1); id <= s32(7); id += s32(1)) {
|
|
||||||
if (Button({session: session, props: nativeInit<NativeButton.Props>({key: u64(100) + u64(id), id: id,
|
|
||||||
label: ActionLabel(id), bounds: {x: x, y: viewport.y + float32(16) + float32(id - s32(1)) * float32(36),
|
|
||||||
width: 176.0, height: 28.0}})})) { State.Activate(id); }
|
|
||||||
}
|
|
||||||
State.UpdateLabels();
|
|
||||||
for (let index = s32(0); index < s32(7); index += s32(1)) {
|
|
||||||
<Text session={session} props={nativeInit<NativeText.Props>({key: u64(910001) + u64(index), text: State.Label(index), size: NativeText.Text14,
|
|
||||||
bounds: {x: x, y: viewport.y + float32(280) + float32(index) * float32(24), width: 176.0, height: 20.0}})}/>;
|
|
||||||
}
|
|
||||||
const bounds: Rectangle = nativeInit<Rectangle>({x: viewport.x + float32(200), y: viewport.y,
|
|
||||||
width: viewport.width - float32(200), height: viewport.height});
|
|
||||||
const input = State.SampleInput(session, bounds);
|
|
||||||
Editor.EditorFrame(session, bounds, State.EditorHandle(), input);
|
|
||||||
State.AfterFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function main(): s32 {
|
|
||||||
return App.Run({title: "workbook-host"}, Frame);
|
|
||||||
}
|
|
||||||
@@ -1,179 +0,0 @@
|
|||||||
// A minimal Kryon host with Workbook's editor embedded beside host-owned UI.
|
|
||||||
// The host test starts this program on a private display and drives it through
|
|
||||||
// Kryon's test driver; the sidebar buttons stand in for a real host's pages.
|
|
||||||
using Editor :: #import "workbook/editor";
|
|
||||||
Engine :: #import "engine";
|
|
||||||
App :: #import "kryon/app";
|
|
||||||
Grid :: #import "grid";
|
|
||||||
#import "kryon/geometry"
|
|
||||||
#import "kryon/session"
|
|
||||||
#import "kryon/drawing_props"
|
|
||||||
#import "kryon/control_props"
|
|
||||||
#import "kryon/text_input"
|
|
||||||
#import "kryon/key_input"
|
|
||||||
#import "kryon/tree_input"
|
|
||||||
#import "std/byte_text_linux"
|
|
||||||
#import "std/text_buffer"
|
|
||||||
#import "std/number_text"
|
|
||||||
#import "std/environment_linux"
|
|
||||||
|
|
||||||
SidebarWidth :: 200.0;
|
|
||||||
|
|
||||||
host_editor: Editor;
|
|
||||||
editor: *Editor;
|
|
||||||
started: bool;
|
|
||||||
host_focus: bool;
|
|
||||||
host_clicked: bool;
|
|
||||||
typed_storage: [128]u8;
|
|
||||||
gnumeric_path: [4096]u8;
|
|
||||||
csv_path: [4096]u8;
|
|
||||||
path_text: [4096]u8;
|
|
||||||
doc_text: [4200]u8;
|
|
||||||
state_text: [64]u8;
|
|
||||||
focus_text: [64]u8;
|
|
||||||
save_text: [64]u8;
|
|
||||||
editing_text: [64]u8;
|
|
||||||
a1_text: [300]u8;
|
|
||||||
b1_text: [300]u8;
|
|
||||||
|
|
||||||
SetText :: (output: []u8, value: string) {
|
|
||||||
output[0] = 0
|
|
||||||
AppendText(output, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
AppendText :: (output: []u8, value: string) {
|
|
||||||
at: s32 = cast(s32)TextUntilNul(output).count
|
|
||||||
index: s32 = 0
|
|
||||||
while index < cast(s32)value.count && at + 1 < cast(s32)output.count {
|
|
||||||
output[at] = value[index]
|
|
||||||
at += 1
|
|
||||||
index += 1
|
|
||||||
}
|
|
||||||
output[at] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
FileName :: (path: string) -> string {
|
|
||||||
at: s32 = cast(s32)path.count
|
|
||||||
while at > 0 && path[at - 1] != #char "/" {
|
|
||||||
at -= 1
|
|
||||||
}
|
|
||||||
return path[at:cast(s32)path.count]
|
|
||||||
}
|
|
||||||
|
|
||||||
CloseEditor :: () {
|
|
||||||
if editor == null { return }
|
|
||||||
EditorSetFocused(editor, false)
|
|
||||||
EditorClose(editor)
|
|
||||||
editor = null
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGnumeric :: () {
|
|
||||||
CloseEditor()
|
|
||||||
editor = EditorOpen(TextUntilNul(gnumeric_path[:]))
|
|
||||||
if editor == null { editor = EditorNew(TextUntilNul(gnumeric_path[:])) }
|
|
||||||
if editor != null {
|
|
||||||
EditorSetAutosave(editor, false)
|
|
||||||
EditorSetFocused(editor, true)
|
|
||||||
}
|
|
||||||
host_focus = false
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenCsv :: () {
|
|
||||||
CloseEditor()
|
|
||||||
editor = EditorOpen(TextUntilNul(csv_path[:]))
|
|
||||||
if editor != null {
|
|
||||||
EditorSetAutosave(editor, false)
|
|
||||||
EditorSetFocused(editor, true)
|
|
||||||
}
|
|
||||||
host_focus = false
|
|
||||||
}
|
|
||||||
|
|
||||||
Start :: () {
|
|
||||||
SetText(gnumeric_path[:], EnvironmentText("HOST_TEST_GNUMERIC"))
|
|
||||||
SetText(csv_path[:], EnvironmentText("HOST_TEST_CSV"))
|
|
||||||
OpenGnumeric()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads the shown cell's displayed value into output as "NAME=value".
|
|
||||||
CellLabel :: (name: string, sheet: s32, row: s32, column: s32, output: []u8) {
|
|
||||||
SetText(output, name)
|
|
||||||
AppendText(output, "=")
|
|
||||||
book := EditorWorkbook(editor)
|
|
||||||
if book == null { return }
|
|
||||||
display: [256]u8
|
|
||||||
Engine.WorkbookCellDisplay(book, sheet, row, column, cast(*s8)*display[0], 256)
|
|
||||||
AppendText(output, TextUntilNul(display[:]))
|
|
||||||
}
|
|
||||||
|
|
||||||
Begin :: () {
|
|
||||||
if !started { Start(); started = true }
|
|
||||||
host_clicked = false
|
|
||||||
}
|
|
||||||
|
|
||||||
Activate :: (action: s32) {
|
|
||||||
host_clicked = true
|
|
||||||
if action == 1 {
|
|
||||||
host_focus = true
|
|
||||||
if editor != null { EditorSetFocused(editor, false) }
|
|
||||||
} else if action == 2 {
|
|
||||||
host_focus = false
|
|
||||||
if editor != null { EditorSetFocused(editor, true) }
|
|
||||||
} else if action == 3 {
|
|
||||||
if editor != null { unused EditorSave(editor, true) }
|
|
||||||
} else if action == 4 { CloseEditor() }
|
|
||||||
else if action == 6 { OpenCsv() }
|
|
||||||
else { OpenGnumeric() }
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateLabels :: () {
|
|
||||||
SetText(state_text[:], ifx editor == null then "state=closed" else "state=open")
|
|
||||||
if editor == null {
|
|
||||||
SetText(focus_text[:], "focus=closed")
|
|
||||||
SetText(doc_text[:], "doc=")
|
|
||||||
SetText(save_text[:], "save=0")
|
|
||||||
SetText(editing_text[:], "editing=no")
|
|
||||||
} else {
|
|
||||||
SetText(focus_text[:], ifx EditorFocused(editor) then "focus=editor" else "focus=host")
|
|
||||||
SetText(doc_text[:], "doc=")
|
|
||||||
AppendText(doc_text[:], FileName(EditorPath(editor, path_text[:])))
|
|
||||||
SetText(save_text[:], "save=")
|
|
||||||
digits: [24]u8
|
|
||||||
AppendText(save_text[:], FormatInteger(cast(s64)EditorSaveCount(editor), digits[:]))
|
|
||||||
SetText(editing_text[:], ifx EditorEditingCell(editor) then "editing=yes" else "editing=no")
|
|
||||||
}
|
|
||||||
CellLabel("A1", 0, 0, 0, a1_text[:])
|
|
||||||
CellLabel("B1", 0, 0, 1, b1_text[:])
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Label :: (index: s32) -> string {
|
|
||||||
if index == 0 { return TextUntilNul(state_text[:]) }
|
|
||||||
if index == 1 { return TextUntilNul(focus_text[:]) }
|
|
||||||
if index == 2 { return TextUntilNul(doc_text[:]) }
|
|
||||||
if index == 3 { return TextUntilNul(a1_text[:]) }
|
|
||||||
if index == 4 { return TextUntilNul(b1_text[:]) }
|
|
||||||
if index == 5 { return TextUntilNul(save_text[:]) }
|
|
||||||
return TextUntilNul(editing_text[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorHandle :: () -> *Editor { return editor }
|
|
||||||
|
|
||||||
SampleInput :: (session: Session, bounds: Rectangle) -> EditorInput {
|
|
||||||
input := EditorSample(session, bounds, editor, typed_storage[:], false)
|
|
||||||
if host_focus {
|
|
||||||
// The host owns the keyboard while it has focus; its own widgets would
|
|
||||||
// consume these in a real host.
|
|
||||||
while TypedCodepointTake(session) != 0 {}
|
|
||||||
unused KeyboardTake(session)
|
|
||||||
}
|
|
||||||
if host_clicked {
|
|
||||||
input.blocked = true
|
|
||||||
host_clicked = false
|
|
||||||
}
|
|
||||||
return input
|
|
||||||
}
|
|
||||||
|
|
||||||
AfterFrame :: () {
|
|
||||||
if editor != null && EditorFocused(editor) { host_focus = false }
|
|
||||||
}
|
|
||||||
|
|
||||||
+2155
-557
File diff suppressed because it is too large.
Load diff
@@ -1,53 +0,0 @@
|
|||||||
import * as NativeButton from "kryon/button";
|
|
||||||
import * as NativeBox from "kryon/box";
|
|
||||||
import * as Grid from "grid";
|
|
||||||
import * as Model from "editor";
|
|
||||||
import * as Menu from "kryon/menu";
|
|
||||||
import * as Popup from "kryon/context_menu";
|
|
||||||
import * as NativeText from "kryon/text";
|
|
||||||
import { ControlSize } from "kryon/control_props";
|
|
||||||
import { Rectangle } from "kryon/geometry";
|
|
||||||
import { Session } from "kryon/session";
|
|
||||||
import { WorkbookEditor } from "editor_view";
|
|
||||||
import { Box } from "kryon/tsx/box";
|
|
||||||
import { Button } from "kryon/tsx/button";
|
|
||||||
import { ContextMenu } from "kryon/tsx/context_menu";
|
|
||||||
import { Text } from "kryon/tsx/text";
|
|
||||||
|
|
||||||
export function DrawDocument(session: Session, menuBounds: Rectangle, editorBounds: Rectangle,
|
|
||||||
editor: NativeRef<Model.Editor>, input: Model.EditorInput): void {
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: u64(990000), bounds: menuBounds, fill: Grid.GridColor("canvas")})}/>;
|
|
||||||
<WorkbookEditor session={session} bounds={editorBounds} editor={editor} input={input}/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function DrawUpdateMessage(session: Session, bounds: Rectangle): void {
|
|
||||||
<Text session={session} props={nativeInit<NativeText.Props>({bounds: bounds, text: "Update Werkzeug to open Workbook.", size: NativeText.Text16})}/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function DrawHostedMenu(session: Session, props: Menu.Props, groups: NativeSlice<Menu.MenuGroup>,
|
|
||||||
state: NativeRef<Menu.MenuState>, items: NativeSlice<Popup.ContextMenuItem>): s32 {
|
|
||||||
if (!state.initialized) { Menu.MenuStateInit(state); }
|
|
||||||
const bounds = props.bounds;
|
|
||||||
for (let index = s32(0); index < s32(groups.count); index += s32(1)) {
|
|
||||||
const pressed = Button({session: session, props: nativeInit<NativeButton.Props>({
|
|
||||||
key: u64(1310) + u64(index), label: nativeAt(groups, index).label, size: ControlSize.ControlSizeSmall,
|
|
||||||
bounds: {x: bounds.x + float32(2) + float32(index) * float32(58), y: bounds.y, width: 58.0, height: 26.0},
|
|
||||||
})});
|
|
||||||
if (pressed) { state.open_index = state.open_index === index ? s32(-1) : index; }
|
|
||||||
}
|
|
||||||
const open = state.open_index;
|
|
||||||
if (open < s32(0) || open >= s32(groups.count)) { return s32(0); }
|
|
||||||
const commands = nativeAt(groups, open).items;
|
|
||||||
const count = s32(commands.count);
|
|
||||||
for (let index = s32(0); index < count; index += s32(1)) {
|
|
||||||
const item = nativeAt(commands, index);
|
|
||||||
nativeSet(items, index, nativeInit<Popup.ContextMenuItem>({id: item.id, label: item.label, disabled: item.disabled,
|
|
||||||
separator: item.kind === Menu.MenuItemKind.MenuSeparator}));
|
|
||||||
}
|
|
||||||
const result = ContextMenu({session: session, items: nativeSlice(items, s32(0), count), props: nativeInit<Popup.Props>({
|
|
||||||
key: u64(1350) + u64(open), open: true, escape: props.input.escape,
|
|
||||||
x: bounds.x + float32(2) + float32(open) * float32(58), y: bounds.y + float32(26),
|
|
||||||
})});
|
|
||||||
if (!result.open) { state.open_index = s32(-1); }
|
|
||||||
return result.activated_id;
|
|
||||||
}
|
|
||||||
+2
-9
@@ -3,7 +3,6 @@
|
|||||||
// cell eval FILE [-o OUT.csv] evaluate and export the first sheet as CSV
|
// cell eval FILE [-o OUT.csv] evaluate and export the first sheet as CSV
|
||||||
// cell csv2gnm IN.csv OUT.gnumeric import CSV, write a .gnumeric file
|
// cell csv2gnm IN.csv OUT.gnumeric import CSV, write a .gnumeric file
|
||||||
// cell copy IN OUT.gnumeric load any supported file, write .gnumeric
|
// cell copy IN OUT.gnumeric load any supported file, write .gnumeric
|
||||||
// cell copy-ods IN OUT load any supported file, write ODS
|
|
||||||
// cell gnm2csv IN.gnumeric OUT.csv load .gnumeric, evaluate, export CSV
|
// cell gnm2csv IN.gnumeric OUT.csv load .gnumeric, evaluate, export CSV
|
||||||
// cell info FILE sheet names and dimensions
|
// cell info FILE sheet names and dimensions
|
||||||
#import "engine"
|
#import "engine"
|
||||||
@@ -34,7 +33,6 @@ main :: (argc: s32, argv: **s8) -> s32 {
|
|||||||
if Is(command, "info") && argc == 3 {
|
if Is(command, "info") && argc == 3 {
|
||||||
return Info(argv[2])
|
return Info(argv[2])
|
||||||
}
|
}
|
||||||
if Is(command,"copy-ods") && argc==4 { return Convert(argv[2],argv[3],true) }
|
|
||||||
if Is(command, "copy") && argc == 4 {
|
if Is(command, "copy") && argc == 4 {
|
||||||
return Convert(argv[2], argv[3])
|
return Convert(argv[2], argv[3])
|
||||||
}
|
}
|
||||||
@@ -59,7 +57,6 @@ main :: (argc: s32, argv: **s8) -> s32 {
|
|||||||
|
|
||||||
Usage :: () {
|
Usage :: () {
|
||||||
WriteLiteral(StandardError, "usage: cell eval FILE [-o OUT.csv]\n")
|
WriteLiteral(StandardError, "usage: cell eval FILE [-o OUT.csv]\n")
|
||||||
WriteLiteral(StandardError, " cell copy-ods IN OUT\n")
|
|
||||||
WriteLiteral(StandardError, " cell csv2gnm IN.csv OUT.gnumeric\n")
|
WriteLiteral(StandardError, " cell csv2gnm IN.csv OUT.gnumeric\n")
|
||||||
WriteLiteral(StandardError, " cell gnm2csv IN.gnumeric OUT.csv\n")
|
WriteLiteral(StandardError, " cell gnm2csv IN.gnumeric OUT.csv\n")
|
||||||
WriteLiteral(StandardError, " cell info FILE\n")
|
WriteLiteral(StandardError, " cell info FILE\n")
|
||||||
@@ -89,14 +86,10 @@ Evaluate :: (input: *s8, output: *s8) -> s32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
Convert :: (input: *s8, output: *s8,force_ods: bool=false) -> s32 {
|
Convert :: (input: *s8, output: *s8) -> s32 {
|
||||||
workbook: *Workbook = Load(input)
|
workbook: *Workbook = Load(input)
|
||||||
if workbook == null { return 1 }
|
if workbook == null { return 1 }
|
||||||
length: s64 = 0
|
if WorkbookWriteGnumeric(workbook, output) == 0 {
|
||||||
while output[length] != 0 { length += 1 }
|
|
||||||
is_ods: bool = force_ods || length >= 4 && TextCompareFoldLiteral(*output[length - 4], ".ods") == 0
|
|
||||||
ok: s32 = ifx is_ods then WorkbookWriteOds(workbook, output) else WorkbookWriteGnumeric(workbook, output)
|
|
||||||
if ok == 0 {
|
|
||||||
Fail("cannot write ", output)
|
Fail("cannot write ", output)
|
||||||
WorkbookFree(workbook)
|
WorkbookFree(workbook)
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import * as NativeBox from "kryon/box";
|
|
||||||
import * as NativeImage from "kryon/image";
|
|
||||||
import { Color } from "kryon/drawing_props";
|
|
||||||
import { Session } from "kryon/session";
|
|
||||||
import { Box } from "kryon/tsx/box";
|
|
||||||
import { Image } from "kryon/tsx/image";
|
|
||||||
|
|
||||||
// Native chart rendering supplies the cached texture and clipped source.
|
|
||||||
export function DrawEmbeddedChart(session: Session, image: NativeImage.Props, border: Color): void {
|
|
||||||
<Image session={session} props={image}/>;
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: image.key + u64(1), bounds: image.bounds, border: border})}/>;
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// Native document/profile state feeds the TSX editor and menu composition.
|
|
||||||
import * as App from "kryon/app";
|
|
||||||
import * as Host from "app";
|
|
||||||
|
|
||||||
export function Frame(frame: App.Frame): void {
|
|
||||||
Host.DesktopFrame(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function main(): s32 {
|
|
||||||
const result = App.Run({title: "Workbook"}, Frame);
|
|
||||||
Host.DesktopShutdown();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// The native desktop menu; hosted documents compose their own buttons/popup.
|
|
||||||
import * as Menu from "kryon/menu";
|
|
||||||
import { Menu as MenuBar } from "kryon/tsx/menu";
|
|
||||||
import { Session } from "kryon/session";
|
|
||||||
|
|
||||||
export function DrawMenu(session: Session, props: Menu.Props, groups: Menu.MenuGroup[],
|
|
||||||
state: NativeRef<Menu.MenuState>): s32 {
|
|
||||||
const result = MenuBar({session: session, props: props, groups: groups, state: state});
|
|
||||||
return result.activated_id;
|
|
||||||
}
|
|
||||||
-2955
File diff suppressed because it is too large.
Load diff
@@ -1,10 +0,0 @@
|
|||||||
// Public workbook/editor API. Keep the original handle and action types.
|
|
||||||
using EditorModel :: #import "editor";
|
|
||||||
#import "kryon/session"
|
|
||||||
#import "kryon/geometry"
|
|
||||||
View :: #import "editor_view";
|
|
||||||
|
|
||||||
// Draw one frame inside the host bounds and report whether it handled input.
|
|
||||||
EditorFrame :: (session: Session, bounds: Rectangle, editor: *Editor, input: EditorInput) -> bool {
|
|
||||||
return View.WorkbookEditor(.{session = session, bounds = bounds, editor = editor, input = input})
|
|
||||||
}
|
|
||||||
@@ -1,352 +0,0 @@
|
|||||||
import * as NativeBox from "kryon/box";
|
|
||||||
import * as Model from "editor";
|
|
||||||
import * as Grid from "grid";
|
|
||||||
import * as NativeButton from "kryon/button";
|
|
||||||
import * as NativeMenu from "kryon/context_menu";
|
|
||||||
import * as NativeTabs from "kryon/tab_bar";
|
|
||||||
import * as NativeText from "kryon/text";
|
|
||||||
import { ButtonEmphasis, ButtonTone, ControlSize } from "kryon/control_props";
|
|
||||||
import { Color } from "kryon/drawing_props";
|
|
||||||
import { Rectangle } from "kryon/geometry";
|
|
||||||
import { KeyEscape } from "kryon/input_protocol";
|
|
||||||
import { Session } from "kryon/session";
|
|
||||||
import { TextUntilNul } from "std/text_buffer";
|
|
||||||
import { Box } from "kryon/tsx/box";
|
|
||||||
import { Button } from "kryon/tsx/button";
|
|
||||||
import { ContextMenu } from "kryon/tsx/context_menu";
|
|
||||||
import { ControlledTextField } from "kryon/tsx/text_field";
|
|
||||||
import { TabBar } from "kryon/tsx/tab_bar";
|
|
||||||
import { Text } from "kryon/tsx/text";
|
|
||||||
|
|
||||||
import { Shape as Bold } from "mingcute/mingcute_regular_bold";
|
|
||||||
import { Shape as Italic } from "mingcute/mingcute_regular_italic";
|
|
||||||
import { Shape as TextColor } from "mingcute/mingcute_regular_text_color";
|
|
||||||
import { Shape as CellFill } from "mingcute/mingcute_regular_paint";
|
|
||||||
import { Shape as Save } from "mingcute/mingcute_regular_save_2";
|
|
||||||
import { Shape as AddRow } from "mingcute/mingcute_extra_table_row_add";
|
|
||||||
import { Shape as RemoveRow } from "mingcute/mingcute_extra_table_row_remove";
|
|
||||||
import { Shape as AddColumn } from "mingcute/mingcute_extra_table_column_add";
|
|
||||||
import { Shape as RemoveColumn } from "mingcute/mingcute_extra_table_column_remove";
|
|
||||||
import { Shape as Left } from "mingcute/mingcute_regular_arrow_left";
|
|
||||||
import { Shape as Right } from "mingcute/mingcute_regular_arrow_right";
|
|
||||||
import { Shape as Up } from "mingcute/mingcute_regular_arrow_up";
|
|
||||||
import { Shape as Down } from "mingcute/mingcute_regular_arrow_down";
|
|
||||||
|
|
||||||
interface EditorRegion {
|
|
||||||
session: Session;
|
|
||||||
bounds: Rectangle;
|
|
||||||
editor: NativeRef<Model.Editor>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EditorInputRegion {
|
|
||||||
session: Session;
|
|
||||||
bounds: Rectangle;
|
|
||||||
editor: NativeRef<Model.Editor>;
|
|
||||||
input: Model.EditorInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
function IconButton(session: Session, base: s32, id: s32, x: float32, y: float32,
|
|
||||||
icon: string, accent: boolean, label: string = ""): boolean {
|
|
||||||
const button: NativeButton.Props = nativeInit<NativeButton.Props>({
|
|
||||||
id: base + id, label: label, icon_shape: icon, icon_only: true,
|
|
||||||
size: ControlSize.ControlSizeSmall, emphasis: ButtonEmphasis.ButtonEmphasisFilled,
|
|
||||||
bounds: {x: x, y: y, width: 28.0, height: 28.0},
|
|
||||||
});
|
|
||||||
if (accent) { button.tone = ButtonTone.ButtonToneAccent; }
|
|
||||||
return Button({session: session, props: button});
|
|
||||||
}
|
|
||||||
|
|
||||||
function Toolbar(view: EditorRegion): void {
|
|
||||||
const session = view.session;
|
|
||||||
const editor = view.editor;
|
|
||||||
const x = view.bounds.x + float32(4);
|
|
||||||
const y = view.bounds.y + float32(2);
|
|
||||||
const base = Model.EditorControlKeyBase(editor);
|
|
||||||
if (IconButton(session, base, s32(1001), x, y, Save, editor.dirty)) { Model.EditorSave(editor, true); }
|
|
||||||
if (IconButton(session, base, s32(1002), x + float32(30), y, AddRow, false)) { Model.EditorInsertRow(editor); }
|
|
||||||
if (IconButton(session, base, s32(1003), x + float32(60), y, RemoveRow, false)) { Model.EditorDeleteRow(editor); }
|
|
||||||
if (IconButton(session, base, s32(1004), x + float32(90), y, AddColumn, false)) { Model.EditorInsertColumn(editor); }
|
|
||||||
if (IconButton(session, base, s32(1005), x + float32(120), y, RemoveColumn, false)) { Model.EditorDeleteColumn(editor); }
|
|
||||||
const chart: NativeButton.Props = nativeInit<NativeButton.Props>({
|
|
||||||
id: base + s32(1010), label: "Chart", size: ControlSize.ControlSizeSmall,
|
|
||||||
bounds: {x: x + float32(150), y: y, width: 58.0, height: 28.0},
|
|
||||||
});
|
|
||||||
const chartPressed = Button({session: session, props: chart});
|
|
||||||
if (chartPressed) { Model.EditorCreateFormulaChart(editor); }
|
|
||||||
if (view.bounds.width >= float32(600)) {
|
|
||||||
if (IconButton(session, base, s32(1022), x + float32(214), y, Bold, false, "Bold")) { Model.EditorFormatSelection(editor, s32(500)); }
|
|
||||||
if (IconButton(session, base, s32(1023), x + float32(244), y, Italic, false, "Italic")) { Model.EditorFormatSelection(editor, s32(501)); }
|
|
||||||
if (IconButton(session, base, s32(1020), x + float32(278), y, TextColor, false, "Text color")) {
|
|
||||||
editor.format_menu_kind = s32(1); editor.format_menu_x = x + float32(278); editor.format_menu_y = y + float32(30);
|
|
||||||
}
|
|
||||||
if (IconButton(session, base, s32(1021), x + float32(308), y, CellFill, false, "Cell fill")) {
|
|
||||||
editor.format_menu_kind = s32(2); editor.format_menu_x = x + float32(308); editor.format_menu_y = y + float32(30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (view.bounds.width < float32(600)) {
|
|
||||||
const left = IconButton(session, base, s32(1006), x + float32(210), y, Left, false);
|
|
||||||
const up = IconButton(session, base, s32(1007), x + float32(240), y, Up, false);
|
|
||||||
const down = IconButton(session, base, s32(1008), x + float32(270), y, Down, false);
|
|
||||||
const right = IconButton(session, base, s32(1009), x + float32(300), y, Right, false);
|
|
||||||
Model.EditorMoveSelection(editor, left, up, down, right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function FormulaBar(session: Session, bounds: Rectangle, editor: NativeRef<Model.Editor>, state: NativeRef<Model.EditorFrameState>): void {
|
|
||||||
const label: NativeText.Props = nativeInit<NativeText.Props>({
|
|
||||||
key: editor.key_base + u64(3), text: "fx", size: NativeText.Text16, disabled: true,
|
|
||||||
bounds: {x: bounds.x + float32(8), y: bounds.y + float32(35), width: 24.0, height: 20.0},
|
|
||||||
});
|
|
||||||
<Text session={session} props={label}/>;
|
|
||||||
let result: Model.FormulaFieldResult = nativeInit<Model.FormulaFieldResult>({});
|
|
||||||
{
|
|
||||||
const field = Model.EditorFormulaField(editor, bounds, state);
|
|
||||||
field.value = TextUntilNul(nativeSlice(editor.edit));
|
|
||||||
field.composition.text = TextUntilNul(nativeSlice(editor.edit_composition_text));
|
|
||||||
if (field.focused) { field.input.text = TextUntilNul(nativeSlice(state.typed)); }
|
|
||||||
const drawn = ControlledTextField({session: session, props: field});
|
|
||||||
result = Model.EditorCopyFormulaFieldResult(drawn);
|
|
||||||
}
|
|
||||||
Model.EditorApplyFormulaField(editor, state.control, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Outline(session: Session, key: u64, bounds: Rectangle, color: Color, thickness: s32): void {
|
|
||||||
if (bounds.width <= float32(0) || bounds.height <= float32(0)) { return; }
|
|
||||||
for (let line = s32(0); line < thickness; line += s32(1)) {
|
|
||||||
const inset = float32(line);
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({
|
|
||||||
key: key + u64(line), border: color,
|
|
||||||
bounds: {x: bounds.x + inset, y: bounds.y + inset,
|
|
||||||
width: bounds.width - inset * float32(2), height: bounds.height - inset * float32(2)},
|
|
||||||
})}/>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GridSelection(session: Session, editor: NativeRef<Model.Editor>, table: Rectangle, grid: Model.EditorGrid): void {
|
|
||||||
const accent = Grid.GridAccentColor();
|
|
||||||
if (grid.here && editor.selection_axis === s32(0) && !editor.edit_focused) {
|
|
||||||
Outline(session, editor.key_base + u64(400000), Model.EditorSelectionOutline(editor, table, grid), accent, s32(2));
|
|
||||||
const handle = Model.FillHandleBounds(editor, table);
|
|
||||||
if (handle.width > float32(0)) {
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({
|
|
||||||
key: editor.key_base + u64(400008), fill: accent, border: Grid.GridCellBackground(),
|
|
||||||
bounds: {x: handle.x + float32(2), y: handle.y + float32(2), width: 7.0, height: 7.0},
|
|
||||||
})}/>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Outline(session, editor.key_base + u64(400010), Model.EditorFillOutline(editor, table, grid), accent, s32(1));
|
|
||||||
const ref: Model.EditorReferenceOutline = nativeInit<Model.EditorReferenceOutline>({});
|
|
||||||
for (let index = s32(0); index < s32(32); index += s32(1)) {
|
|
||||||
if (!Model.EditorReadReferenceOutline(editor, table, index, nativeRef(ref))) { break; }
|
|
||||||
Outline(session, editor.key_base + u64(400100) + u64(index) * u64(4), ref.bounds, ref.color, s32(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function InlineEditor(session: Session, editor: NativeRef<Model.Editor>, table: Rectangle): void {
|
|
||||||
const text = TextUntilNul(nativeSlice(editor.edit));
|
|
||||||
const bounds = Model.EditorInlineBounds(editor, table, text);
|
|
||||||
if (bounds.width <= float32(0) || bounds.height <= float32(0)) { return; }
|
|
||||||
const accent = Grid.GridAccentColor();
|
|
||||||
Grid.GridSquare(session, editor.key_base + u64(400500), bounds,
|
|
||||||
bounds.x + bounds.width, bounds.y + bounds.height, Grid.GridCellBackground(), text, false);
|
|
||||||
Outline(session, editor.key_base + u64(400504), bounds, accent, s32(1));
|
|
||||||
const caret = Model.EditorCaretX(editor, text);
|
|
||||||
if (caret < bounds.width - float32(2)) {
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({
|
|
||||||
key: editor.key_base + u64(400502), fill: accent, border: accent,
|
|
||||||
bounds: {x: bounds.x + caret, y: bounds.y + float32(5), width: 1.0, height: bounds.height - float32(10)},
|
|
||||||
})}/>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function CellKey(editor: NativeRef<Model.Editor>, index: s32): u64 {
|
|
||||||
return editor.key_base + u64(1000000) + u64(index) * u64(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function GridHeading(session: Session, editor: NativeRef<Model.Editor>, index: s32, bounds: Rectangle, selected: boolean, text: string): void {
|
|
||||||
const fill = selected ? Grid.GridSelectedBackground() : Grid.GridHeaderBackground();
|
|
||||||
Grid.GridSquare(session, CellKey(editor, index), bounds, editor.grid_right, editor.grid_bottom, fill, text, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function CellGrid(view: EditorInputRegion): void {
|
|
||||||
const session = view.session;
|
|
||||||
const editor = view.editor;
|
|
||||||
const bounds = view.bounds;
|
|
||||||
const table: Rectangle = nativeInit<Rectangle>({x: bounds.x, y: bounds.y + float32(60), width: bounds.width, height: bounds.height - float32(88)});
|
|
||||||
const grid = Model.EditorPrepareGrid(editor, table, view.input);
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: editor.key_base + u64(999999),
|
|
||||||
bounds: table, fill: Grid.GridCellBackground()})}/>;
|
|
||||||
const headerWidth = float32(Grid.GridRowHeaderWidth);
|
|
||||||
const headerHeight = float32(Grid.GridHeaderHeight);
|
|
||||||
GridHeading(session, editor, s32(10), {x: table.x, y: table.y, width: headerWidth, height: headerHeight}, false, "");
|
|
||||||
const columns = Model.Min(grid.columns, editor.scroll_column + editor.visible_columns);
|
|
||||||
const rows = Model.Min(grid.rows, editor.scroll_row + editor.visible_rows);
|
|
||||||
for (let column = editor.scroll_column; column < columns; column += s32(1)) {
|
|
||||||
const width = Model.GridColWidth(editor, column);
|
|
||||||
if (width <= float32(0)) { continue; }
|
|
||||||
const name: Model.EditorColumnLabelBuffer = nativeInit<Model.EditorColumnLabelBuffer>({});
|
|
||||||
const text = Model.EditorColumnLabel(column, nativeSlice(name.bytes));
|
|
||||||
const header: Rectangle = nativeInit<Rectangle>({x: Model.ColumnX(editor, table, column), y: table.y, width: width, height: headerHeight});
|
|
||||||
const selected = grid.here && editor.selection_axis === s32(2) && column === editor.selected_column;
|
|
||||||
GridHeading(session, editor, s32(20) + column - editor.scroll_column, header, selected, text);
|
|
||||||
}
|
|
||||||
for (let row = editor.scroll_row; row < rows; row += s32(1)) {
|
|
||||||
const shown = row - editor.scroll_row;
|
|
||||||
const y = Model.RowY(editor, table, row);
|
|
||||||
const height = Model.GridRowHeight(editor, row);
|
|
||||||
if (Model.RowHidden(editor, row)) {
|
|
||||||
if (height > float32(0)) {
|
|
||||||
GridHeading(session, editor, s32(1000) + shown, {x: table.x, y: y, width: table.width, height: height}, false, "");
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({
|
|
||||||
key: editor.key_base + u64(500000) + u64(shown), fill: Grid.GridLineColor(),
|
|
||||||
bounds: {x: table.x, y: y + float32(2), width: table.width, height: 1.0},
|
|
||||||
})}/>;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const digits: Model.EditorRowLabelBuffer = nativeInit<Model.EditorRowLabelBuffer>({});
|
|
||||||
const label = Model.EditorRowLabel(row, nativeSlice(digits.bytes));
|
|
||||||
const selected = grid.here && editor.selection_axis === s32(1) && row === editor.selected_row;
|
|
||||||
GridHeading(session, editor, s32(1000) + shown, {x: table.x, y: y, width: headerWidth, height: height}, selected, label);
|
|
||||||
for (let column = editor.scroll_column; column < columns; column += s32(1)) {
|
|
||||||
const width = Model.GridColWidth(editor, column);
|
|
||||||
if (width <= float32(0)) { continue; }
|
|
||||||
const cell: Model.EditorGridCell = nativeInit<Model.EditorGridCell>({});
|
|
||||||
if (!Model.EditorReadGridCell(editor, table, grid, row, column, y, height, width, nativeRef(cell))) { continue; }
|
|
||||||
const key = CellKey(editor, s32(10000) + shown * editor.visible_columns + column - editor.scroll_column);
|
|
||||||
Grid.GridSquareStyled(session, key, cell.bounds, editor.grid_right, editor.grid_bottom,
|
|
||||||
cell.fill, cell.line, TextUntilNul(nativeSlice(cell.display)), cell.has_fg, cell.fg, cell.bold, cell.italic,
|
|
||||||
cell.align, cell.font_size, nativeRef(cell.style));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GridSelection(session, editor, table, grid);
|
|
||||||
Model.EditorDrawEmbeddedCharts(session, editor, table);
|
|
||||||
InlineEditor(session, editor, table);
|
|
||||||
Model.EditorHandleGridPointer(editor, table, grid, view.input);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ColoredTabs(view: EditorInputRegion, shown: NativeSlice<s32>, count: s32): boolean {
|
|
||||||
const editor = view.editor;
|
|
||||||
if (!Model.EditorHasColoredTabs(editor, shown, count)) { return false; }
|
|
||||||
const bounds = Model.SheetTabsBounds(editor, view.bounds);
|
|
||||||
let width = bounds.width / float32(count);
|
|
||||||
if (width < float32(72)) { width = float32(72); }
|
|
||||||
if (width > float32(104)) { width = float32(104); }
|
|
||||||
let picked = s32(-1);
|
|
||||||
for (let index = s32(0); index < count; index += s32(1)) {
|
|
||||||
const sheet = nativeAt(shown, editor.tab_scroll + index);
|
|
||||||
const style = Model.EditorSheetTabStyle(editor, sheet);
|
|
||||||
const rect: Rectangle = nativeInit<Rectangle>({x: bounds.x + float32(index) * width, y: bounds.y, width: width, height: 28.0});
|
|
||||||
if (!view.input.blocked && view.input.pointer.pressed &&
|
|
||||||
Grid.GridInside(view.input.pointer.x, view.input.pointer.y, rect)) { picked = sheet; }
|
|
||||||
<Box session={view.session} props={nativeInit<NativeBox.Props>({key: editor.key_base + u64(1100) + u64(index),
|
|
||||||
bounds: rect, fill: style.fill, border: {r: u8(0), g: u8(0), b: u8(0), a: u8(50)}})}/>;
|
|
||||||
if (style.active) {
|
|
||||||
<Box session={view.session} props={nativeInit<NativeBox.Props>({key: editor.key_base + u64(410000) + u64(index),
|
|
||||||
bounds: {x: rect.x + float32(1), y: rect.y, width: rect.width - float32(2), height: 3.0},
|
|
||||||
fill: style.accent})}/>;
|
|
||||||
}
|
|
||||||
Model.EditorPaintSheetTabLabel(view.session, editor, sheet, rect, style);
|
|
||||||
}
|
|
||||||
Model.EditorPickSheet(editor, picked);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function SheetTabs(view: EditorInputRegion): void {
|
|
||||||
const session = view.session;
|
|
||||||
const editor = view.editor;
|
|
||||||
const bounds = view.bounds;
|
|
||||||
const visible: Model.EditorTabList = nativeInit<Model.EditorTabList>({});
|
|
||||||
const shown = Model.EditorShownSheets(editor, nativeSlice(visible.sheets));
|
|
||||||
if (shown < s32(1)) { return; }
|
|
||||||
const y = bounds.y + bounds.height - float32(28);
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({
|
|
||||||
key: editor.key_base + u64(1098), fill: Grid.GridHeaderBackground(), border: Grid.GridLineColor(),
|
|
||||||
bounds: {x: bounds.x, y: y, width: bounds.width, height: 28.0},
|
|
||||||
})}/>;
|
|
||||||
const base = Model.EditorControlKeyBase(editor);
|
|
||||||
const maxScroll = shown - s32(16);
|
|
||||||
if (maxScroll > s32(0)) {
|
|
||||||
const previous: NativeButton.Props = nativeInit<NativeButton.Props>({
|
|
||||||
id: base + s32(1096), label: "<", size: ControlSize.ControlSizeSmall, disabled: editor.tab_scroll <= s32(0),
|
|
||||||
bounds: {x: bounds.x + float32(2), y: y + float32(2), width: 22.0, height: 24.0},
|
|
||||||
});
|
|
||||||
const previousPressed = Button({session: session, props: previous});
|
|
||||||
if (previousPressed && editor.tab_scroll > s32(0)) { editor.tab_scroll = editor.tab_scroll - s32(1); }
|
|
||||||
const next: NativeButton.Props = nativeInit<NativeButton.Props>({
|
|
||||||
id: base + s32(1097), label: ">", size: ControlSize.ControlSizeSmall, disabled: editor.tab_scroll >= maxScroll,
|
|
||||||
bounds: {x: bounds.x + float32(26), y: y + float32(2), width: 22.0, height: 24.0},
|
|
||||||
});
|
|
||||||
const nextPressed = Button({session: session, props: next});
|
|
||||||
if (nextPressed && editor.tab_scroll < maxScroll) { editor.tab_scroll = editor.tab_scroll + s32(1); }
|
|
||||||
}
|
|
||||||
const count = Model.Min(shown - editor.tab_scroll, s32(16));
|
|
||||||
if (ColoredTabs(view, nativeSlice(visible.sheets), count)) { return; }
|
|
||||||
Model.EditorReadTabNames(editor, nativeRef(visible), count);
|
|
||||||
let selected = s32(0);
|
|
||||||
for (let index = s32(0); index < count; index += s32(1)) {
|
|
||||||
const sheet = nativeAt(visible.sheets, editor.tab_scroll + index);
|
|
||||||
nativeSet(visible.tabs, index, nativeInit<NativeTabs.Tab>({key: editor.key_base + u64(1100) + u64(index),
|
|
||||||
label: Model.EditorSheetTabName(nativeSlice(visible.names), index)}));
|
|
||||||
if (sheet === editor.sheet_index) { selected = index; }
|
|
||||||
}
|
|
||||||
const bar: NativeTabs.Props = nativeInit<NativeTabs.Props>({
|
|
||||||
key: editor.key_base + u64(1099), selected_index: selected,
|
|
||||||
placement: NativeTabs.TabBarPlacement.TabBarBottom, bounds: Model.SheetTabsBounds(editor, bounds),
|
|
||||||
min_tab_width: s32(72), max_tab_width: s32(104),
|
|
||||||
});
|
|
||||||
const result = TabBar({session: session, props: bar, tabs: nativeSlice(visible.tabs, s32(0), count)});
|
|
||||||
if (result.selected_index >= s32(0) && result.selected_index < count) {
|
|
||||||
Model.EditorPickSheet(editor, nativeAt(visible.sheets, editor.tab_scroll + result.selected_index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GridMenu(session: Session, editor: NativeRef<Model.Editor>, escape: boolean): void {
|
|
||||||
if (!editor.grid_menu_open) { return; }
|
|
||||||
const items: Model.EditorGridMenuItems = nativeInit<Model.EditorGridMenuItems>({});
|
|
||||||
const count = Model.EditorGridCommands(editor, nativeSlice(items.items));
|
|
||||||
const props: NativeMenu.Props = nativeInit<NativeMenu.Props>({key: editor.key_base + u64(1200), open: true,
|
|
||||||
x: editor.grid_menu_x, y: editor.grid_menu_y, escape: escape});
|
|
||||||
const result = ContextMenu({session: session, props: props, items: nativeSlice(items.items, s32(0), count)});
|
|
||||||
Model.EditorApplyGridCommand(editor, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function FormatMenu(session: Session, editor: NativeRef<Model.Editor>, escape: boolean): void {
|
|
||||||
if (editor.format_menu_kind === s32(0)) { return; }
|
|
||||||
const items: Model.EditorGridMenuItems = nativeInit<Model.EditorGridMenuItems>({});
|
|
||||||
const count = Model.EditorFormatCommands(editor, nativeSlice(items.items));
|
|
||||||
const props: NativeMenu.Props = nativeInit<NativeMenu.Props>({key: editor.key_base + u64(1201), open: true,
|
|
||||||
x: editor.format_menu_x, y: editor.format_menu_y, escape: escape});
|
|
||||||
const result = ContextMenu({session: session, props: props, items: nativeSlice(items.items, s32(0), count)});
|
|
||||||
Model.EditorApplyFormatCommand(editor, result);
|
|
||||||
}
|
|
||||||
function EditorStatus(view: EditorRegion): void {
|
|
||||||
const bounds = view.bounds;
|
|
||||||
const text = TextUntilNul(nativeSlice(view.editor.status));
|
|
||||||
if (text.count === s64(0)) { return; }
|
|
||||||
<Text session={view.session} props={nativeInit<NativeText.Props>({key: view.editor.key_base + u64(5), text: text, size: NativeText.Text14,
|
|
||||||
bounds: {x: bounds.x + float32(180), y: bounds.y + bounds.height - float32(24),
|
|
||||||
width: bounds.width - float32(184), height: 20.0},
|
|
||||||
})}/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function WorkbookEditor(view: EditorInputRegion): boolean {
|
|
||||||
const state: Model.EditorFrameState = nativeInit<Model.EditorFrameState>({});
|
|
||||||
const editor = view.editor;
|
|
||||||
const session = view.session;
|
|
||||||
const bounds = view.bounds;
|
|
||||||
if (!Model.EditorPrepareFrame(bounds, editor, view.input, nativeRef(state))) { return false; }
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: editor.key_base + u64(7), bounds: bounds, fill: Grid.GridColor("canvas")})}/>;
|
|
||||||
<Toolbar session={session} editor={editor} bounds={bounds}/>;
|
|
||||||
state.was_editing = editor.edit_focused;
|
|
||||||
FormulaBar(session, bounds, editor, nativeRef(state));
|
|
||||||
Model.EditorApplyGridKeys(editor, nativeRef(state));
|
|
||||||
<CellGrid session={session} editor={editor} bounds={bounds} input={state.input}/>;
|
|
||||||
<SheetTabs session={session} editor={editor} bounds={bounds} input={state.input}/>;
|
|
||||||
GridMenu(session, editor, state.key === KeyEscape);
|
|
||||||
FormatMenu(session, editor, state.key === KeyEscape);
|
|
||||||
Model.EditorAutosave(editor);
|
|
||||||
<EditorStatus session={session} editor={editor} bounds={bounds}/>;
|
|
||||||
Model.EditorFinishFrame(editor, state.input.pointer);
|
|
||||||
return state.handled;
|
|
||||||
}
|
|
||||||
+26
-213
@@ -52,7 +52,6 @@ Sheet :: struct {
|
|||||||
cells: *Cell
|
cells: *Cell
|
||||||
cell_count: s32
|
cell_count: s32
|
||||||
cell_cap: s32
|
cell_cap: s32
|
||||||
native_cell_count: s32
|
|
||||||
hidden_rows: *s32
|
hidden_rows: *s32
|
||||||
hidden_count: s32
|
hidden_count: s32
|
||||||
hidden_cap: s32
|
hidden_cap: s32
|
||||||
@@ -62,10 +61,6 @@ Sheet :: struct {
|
|||||||
|
|
||||||
Workbook :: struct {
|
Workbook :: struct {
|
||||||
native: *void
|
native: *void
|
||||||
native_format: s32
|
|
||||||
native_snapshot: *void
|
|
||||||
native_snapshot_uri: *s8
|
|
||||||
native_snapshot_cells: s32
|
|
||||||
sheets: *Sheet
|
sheets: *Sheet
|
||||||
sheet_count: s32
|
sheet_count: s32
|
||||||
sheet_cap: s32
|
sheet_cap: s32
|
||||||
@@ -410,8 +405,6 @@ WorkbookFree :: (wb: *Workbook) {
|
|||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
NativeClose(wb.native)
|
NativeClose(wb.native)
|
||||||
NativeClose(wb.native_snapshot)
|
|
||||||
MemoryFree(cast(*void)wb.native_snapshot_uri)
|
|
||||||
MemoryFree(cast(*void)wb.sheets)
|
MemoryFree(cast(*void)wb.sheets)
|
||||||
MemoryFree(cast(*void)wb)
|
MemoryFree(cast(*void)wb)
|
||||||
}
|
}
|
||||||
@@ -424,7 +417,6 @@ WorkbookClone :: (wb: *Workbook) -> *Workbook {
|
|||||||
copy: *Workbook = WorkbookNew()
|
copy: *Workbook = WorkbookNew()
|
||||||
if copy == null { return null }
|
if copy == null { return null }
|
||||||
copy.native = NativeClone(wb.native)
|
copy.native = NativeClone(wb.native)
|
||||||
copy.native_format = wb.native_format
|
|
||||||
if copy.native == null || NativeRefresh(copy) == 0 {
|
if copy.native == null || NativeRefresh(copy) == 0 {
|
||||||
WorkbookFree(copy)
|
WorkbookFree(copy)
|
||||||
return null
|
return null
|
||||||
@@ -486,41 +478,18 @@ WorkbookClone :: (wb: *Workbook) -> *Workbook {
|
|||||||
return copy
|
return copy
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undo retains an immutable native document stream. Parse it only when the
|
|
||||||
// owner actually undoes; recording a small edit must not reload 49 sheets.
|
|
||||||
WorkbookSnapshot :: (wb: *Workbook) -> *Workbook {
|
|
||||||
if wb.native == null { return WorkbookClone(wb) }
|
|
||||||
copy:=WorkbookNew(); if copy==null { return null }
|
|
||||||
copy.native_snapshot=NativeCreateSnapshot(wb.native)
|
|
||||||
if copy.native_snapshot==null { WorkbookFree(copy); return null }
|
|
||||||
copy.native_snapshot_uri=NativeSnapshotUri(wb.native)
|
|
||||||
copy.native_snapshot_cells=WorkbookCellCount(wb)
|
|
||||||
copy.native_format=wb.native_format
|
|
||||||
return copy
|
|
||||||
}
|
|
||||||
WorkbookRestoreSnapshot :: (wb: *Workbook) -> s32 {
|
|
||||||
if wb.native_snapshot==null { return 1 }
|
|
||||||
view:=NativeRestoreStream(wb.native_snapshot,wb.native_snapshot_uri)
|
|
||||||
if view==null { return 0 }
|
|
||||||
wb.native=view
|
|
||||||
NativeClose(wb.native_snapshot); wb.native_snapshot=null
|
|
||||||
MemoryFree(cast(*void)wb.native_snapshot_uri); wb.native_snapshot_uri=null
|
|
||||||
return NativeRefresh(wb)
|
|
||||||
}
|
|
||||||
|
|
||||||
// How many cells the workbook holds, over all its sheets.
|
// How many cells the workbook holds, over all its sheets.
|
||||||
WorkbookCellCount :: (wb: *Workbook) -> s32 {
|
WorkbookCellCount :: (wb: *Workbook) -> s32 {
|
||||||
if wb.native_snapshot!=null { return wb.native_snapshot_cells }
|
|
||||||
count: s32 = 0
|
count: s32 = 0
|
||||||
i: s32 = 0
|
i: s32 = 0
|
||||||
while i < wb.sheet_count {
|
while i < wb.sheet_count {
|
||||||
count += ifx wb.native!=null then wb.sheets[i].native_cell_count else wb.sheets[i].cell_count
|
count += wb.sheets[i].cell_count
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkbookPushSheet :: (wb: *Workbook, name: *s8) -> *Sheet {
|
WorkbookAddSheet :: (wb: *Workbook, name: *s8) -> *Sheet {
|
||||||
if wb.native == null && wb.sheet_count >= WB_MAX_SHEETS {
|
if wb.native == null && wb.sheet_count >= WB_MAX_SHEETS {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -540,14 +509,6 @@ WorkbookPushSheet :: (wb: *Workbook, name: *s8) -> *Sheet {
|
|||||||
return sheet
|
return sheet
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkbookAddSheet :: (wb: *Workbook, name: *s8) -> *Sheet {
|
|
||||||
if wb.native != null {
|
|
||||||
if NativeAddSheet(wb, name) == 0 || wb.sheet_count == 0 { return null }
|
|
||||||
return *wb.sheets[wb.sheet_count - 1]
|
|
||||||
}
|
|
||||||
return WorkbookPushSheet(wb, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookFindSheet :: (wb: *Workbook, name: *s8) -> *Sheet {
|
WorkbookFindSheet :: (wb: *Workbook, name: *s8) -> *Sheet {
|
||||||
i: s32 = 0
|
i: s32 = 0
|
||||||
while i < wb.sheet_count {
|
while i < wb.sheet_count {
|
||||||
@@ -2491,19 +2452,6 @@ WorkbookDeleteColumn :: (wb: *Workbook, sheet_index: s32, col: s32) -> s32 {
|
|||||||
return SheetDeleteColumn(*wb.sheets[sheet_index], col)
|
return SheetDeleteColumn(*wb.sheets[sheet_index], col)
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkbookEditStructure :: (wb: *Workbook,sheet: s32,at: s32,count: s32,rows: bool,insert: bool) -> s32 {
|
|
||||||
limit:=ifx rows then WB_MAX_ROWS else WB_MAX_COLS
|
|
||||||
if sheet<0 || sheet>=wb.sheet_count || at<0 || count<1 || at>=limit || count>limit-at { return 0 }
|
|
||||||
if wb.native!=null { return NativeShift(wb,sheet,at,rows,insert,count) }
|
|
||||||
for i: 0..count-1 {
|
|
||||||
if rows { if insert { WorkbookInsertRow(wb,sheet,at) } else { WorkbookDeleteRow(wb,sheet,at) } }
|
|
||||||
else { if insert { WorkbookInsertColumn(wb,sheet,at) } else { WorkbookDeleteColumn(wb,sheet,at) } }
|
|
||||||
}
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Native mutations have already recalculated and invalidated their source cache.
|
|
||||||
WorkbookEvaluateChanged :: (wb: *Workbook) { if wb.native==null { WorkbookEvaluate(wb) } }
|
|
||||||
WorkbookEvaluate :: (wb: *Workbook) {
|
WorkbookEvaluate :: (wb: *Workbook) {
|
||||||
if wb.native != null { unused NativeRefresh(wb); return }
|
if wb.native != null { unused NativeRefresh(wb); return }
|
||||||
i: s32 = 0
|
i: s32 = 0
|
||||||
@@ -29037,8 +28985,6 @@ WorkbookLoadFile :: (wb: *Workbook, path: *s8) -> s32 {
|
|||||||
while IsSpaceByte(cast(s32)first[0]) != 0 { first = *first[1] }
|
while IsSpaceByte(cast(s32)first[0]) != 0 { first = *first[1] }
|
||||||
length: u64 = TextLength(path)
|
length: u64 = TextLength(path)
|
||||||
document: bool = length >= 9 && TextCompareFoldLiteral(*path[length - 9], ".gnumeric") == 0
|
document: bool = length >= 9 && TextCompareFoldLiteral(*path[length - 9], ".gnumeric") == 0
|
||||||
ods_ext: bool = length >= 4 && TextCompareFoldLiteral(*path[length - 4], ".ods") == 0
|
|
||||||
ods_zip: bool = size >= 4 && bytes[0] == 80 && bytes[1] == 75 && bytes[2] == 3 && bytes[3] == 4
|
|
||||||
csv: bool = length >= 4 && TextCompareFoldLiteral(*path[length - 4], ".csv") == 0
|
csv: bool = length >= 4 && TextCompareFoldLiteral(*path[length - 4], ".csv") == 0
|
||||||
csv_gzip: bool = length >= 7 && TextCompareFoldLiteral(*path[length - 7], ".csv.gz") == 0
|
csv_gzip: bool = length >= 7 && TextCompareFoldLiteral(*path[length - 7], ".csv.gz") == 0
|
||||||
if csv_gzip {
|
if csv_gzip {
|
||||||
@@ -29051,19 +28997,6 @@ WorkbookLoadFile :: (wb: *Workbook, path: *s8) -> s32 {
|
|||||||
if ok != 0 { WorkbookEvaluate(wb) }
|
if ok != 0 { WorkbookEvaluate(wb) }
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
if ods_ext || (!csv && !document && ods_zip) {
|
|
||||||
if !NativeReady() {
|
|
||||||
FreeFileBytes(bytes)
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
view: *void = NativeReadDocument(bytes, cast(s64)size, path, true)
|
|
||||||
FreeFileBytes(bytes)
|
|
||||||
if view == null { return 0 }
|
|
||||||
NativeClose(wb.native)
|
|
||||||
wb.native = view
|
|
||||||
wb.native_format = 1
|
|
||||||
return NativeRefresh(wb)
|
|
||||||
}
|
|
||||||
if document || (!csv && (first[0] == 60 || GzipIs(bytes, cast(u64)size) != 0)) {
|
if document || (!csv && (first[0] == 60 || GzipIs(bytes, cast(u64)size) != 0)) {
|
||||||
if !NativeReady() {
|
if !NativeReady() {
|
||||||
text: *u8 = bytes
|
text: *u8 = bytes
|
||||||
@@ -29080,12 +29013,11 @@ WorkbookLoadFile :: (wb: *Workbook, path: *s8) -> s32 {
|
|||||||
}
|
}
|
||||||
// Pass the original bytes and their length to Gnumeric: it handles
|
// Pass the original bytes and their length to Gnumeric: it handles
|
||||||
// compression, XML encodings, namespaces and shared expressions.
|
// compression, XML encodings, namespaces and shared expressions.
|
||||||
view: *void = NativeReadDocument(bytes, cast(s64)size, path, false)
|
view: *void = NativeReadDocument(bytes, cast(s64)size, path)
|
||||||
FreeFileBytes(bytes)
|
FreeFileBytes(bytes)
|
||||||
if view == null { return 0 }
|
if view == null { return 0 }
|
||||||
NativeClose(wb.native)
|
NativeClose(wb.native)
|
||||||
wb.native = view
|
wb.native = view
|
||||||
wb.native_format = 0
|
|
||||||
return NativeRefresh(wb)
|
return NativeRefresh(wb)
|
||||||
}
|
}
|
||||||
ok: s32 = ParseCsvIntoSheet(wb, cast(*s8)bytes)
|
ok: s32 = ParseCsvIntoSheet(wb, cast(*s8)bytes)
|
||||||
@@ -29236,35 +29168,14 @@ ParseGnumericCell :: (sheet: *Sheet, node: *XmlNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorkbookWriteGnumeric :: (wb: *Workbook, path: *s8) -> s32 {
|
WorkbookWriteGnumeric :: (wb: *Workbook, path: *s8) -> s32 {
|
||||||
if wb.native != null { return NativeSave(wb.native, path, false, false) }
|
if wb.native != null { return NativeSave(wb.native, path, false) }
|
||||||
buf: XmlBuffer
|
buf: XmlBuffer
|
||||||
ok: s32 = 0
|
ok: s32 = 0
|
||||||
WorkbookSerializeGnumericXml(wb, *buf)
|
|
||||||
ok = ifx WriteFileText(path, XmlBufferFinish(*buf)) then 1 else 0
|
|
||||||
XmlBufferFree(*buf)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookWriteOds :: (wb: *Workbook, path: *s8) -> s32 {
|
|
||||||
if wb.native != null { return NativeSave(wb.native, path, false, true) }
|
|
||||||
if !NativeReady() { return 0 }
|
|
||||||
buf: XmlBuffer
|
|
||||||
WorkbookSerializeGnumericXml(wb, *buf)
|
|
||||||
xml: *s8 = XmlBufferFinish(*buf)
|
|
||||||
view: *void = NativeRead(cast(*u8)xml, cast(s64)TextLength(xml), null, false)
|
|
||||||
XmlBufferFree(*buf)
|
|
||||||
if view == null { return 0 }
|
|
||||||
ok: s32 = NativeSave(view, path, false, true)
|
|
||||||
NativeClose(view)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookSerializeGnumericXml :: (wb: *Workbook, buf: *XmlBuffer) {
|
|
||||||
sheet_index: s32 = 0
|
sheet_index: s32 = 0
|
||||||
XmlBufferRaw(buf, CText("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"))
|
XmlBufferRaw(*buf, CText("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"))
|
||||||
XmlBufferRaw(buf, CText("<gnm:Workbook xmlns:gnm=\"http://www.gnumeric.org/v10.dtd\">\n"))
|
XmlBufferRaw(*buf, CText("<gnm:Workbook xmlns:gnm=\"http://www.gnumeric.org/v10.dtd\">\n"))
|
||||||
XmlBufferRaw(buf, CText(" <gnm:Version Epoch=\"1\" Major=\"12\" Minor=\"62\" Full=\"1.12.62\"/>\n"))
|
XmlBufferRaw(*buf, CText(" <gnm:Version Epoch=\"1\" Major=\"12\" Minor=\"62\" Full=\"1.12.62\"/>\n"))
|
||||||
XmlBufferRaw(buf, CText(" <gnm:SheetNameIndex>\n"))
|
XmlBufferRaw(*buf, CText(" <gnm:SheetNameIndex>\n"))
|
||||||
sheet_index = 0
|
sheet_index = 0
|
||||||
while sheet_index < wb.sheet_count {
|
while sheet_index < wb.sheet_count {
|
||||||
columns: s32 = 256
|
columns: s32 = 256
|
||||||
@@ -29272,27 +29183,30 @@ WorkbookSerializeGnumericXml :: (wb: *Workbook, buf: *XmlBuffer) {
|
|||||||
while columns <= wb.sheets[sheet_index].max_col && columns < WB_MAX_COLS { columns *= 2 }
|
while columns <= wb.sheets[sheet_index].max_col && columns < WB_MAX_COLS { columns *= 2 }
|
||||||
while rows <= wb.sheets[sheet_index].max_row && rows < WB_MAX_ROWS { rows *= 2 }
|
while rows <= wb.sheets[sheet_index].max_row && rows < WB_MAX_ROWS { rows *= 2 }
|
||||||
dimension: [32]s8
|
dimension: [32]s8
|
||||||
XmlBufferRaw(buf, CText(" <gnm:SheetName gnm:Cols=\""))
|
XmlBufferRaw(*buf, CText(" <gnm:SheetName gnm:Cols=\""))
|
||||||
FormatNumber(cast(float64)columns, *dimension[0], 32)
|
FormatNumber(cast(float64)columns, *dimension[0], 32)
|
||||||
XmlBufferRaw(buf, *dimension[0])
|
XmlBufferRaw(*buf, *dimension[0])
|
||||||
XmlBufferRaw(buf, CText("\" gnm:Rows=\""))
|
XmlBufferRaw(*buf, CText("\" gnm:Rows=\""))
|
||||||
FormatNumber(cast(float64)rows, *dimension[0], 32)
|
FormatNumber(cast(float64)rows, *dimension[0], 32)
|
||||||
XmlBufferRaw(buf, *dimension[0])
|
XmlBufferRaw(*buf, *dimension[0])
|
||||||
XmlBufferRaw(buf, CText("\">"))
|
XmlBufferRaw(*buf, CText("\">"))
|
||||||
XmlBufferEsc(buf, *wb.sheets[sheet_index].name[0])
|
XmlBufferEsc(*buf, *wb.sheets[sheet_index].name[0])
|
||||||
XmlBufferRaw(buf, CText("</gnm:SheetName>\n"))
|
XmlBufferRaw(*buf, CText("</gnm:SheetName>\n"))
|
||||||
sheet_index += 1
|
sheet_index += 1
|
||||||
}
|
}
|
||||||
XmlBufferRaw(buf, CText(" </gnm:SheetNameIndex>\n"))
|
XmlBufferRaw(*buf, CText(" </gnm:SheetNameIndex>\n"))
|
||||||
XmlBufferRaw(buf, CText(" <gnm:Sheets>\n"))
|
XmlBufferRaw(*buf, CText(" <gnm:Sheets>\n"))
|
||||||
sheet_index = 0
|
sheet_index = 0
|
||||||
while sheet_index < wb.sheet_count {
|
while sheet_index < wb.sheet_count {
|
||||||
WriteGnumericSheet(buf, *wb.sheets[sheet_index])
|
WriteGnumericSheet(*buf, *wb.sheets[sheet_index])
|
||||||
sheet_index += 1
|
sheet_index += 1
|
||||||
}
|
}
|
||||||
XmlBufferRaw(buf, CText(" </gnm:Sheets>\n"))
|
XmlBufferRaw(*buf, CText(" </gnm:Sheets>\n"))
|
||||||
XmlBufferRaw(buf, CText(" <gnm:UIData SelectedTab=\"0\"/>\n"))
|
XmlBufferRaw(*buf, CText(" <gnm:UIData SelectedTab=\"0\"/>\n"))
|
||||||
XmlBufferRaw(buf, CText("</gnm:Workbook>\n"))
|
XmlBufferRaw(*buf, CText("</gnm:Workbook>\n"))
|
||||||
|
ok = ifx WriteFileText(path, XmlBufferFinish(*buf)) then 1 else 0
|
||||||
|
XmlBufferFree(*buf)
|
||||||
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteGnumericSheet :: (buf: *XmlBuffer, sheet: *Sheet) {
|
WriteGnumericSheet :: (buf: *XmlBuffer, sheet: *Sheet) {
|
||||||
@@ -29595,110 +29509,9 @@ WorkbookRowHidden :: (wb: *Workbook, index: s32, row: s32) -> s32 {
|
|||||||
return SheetRowHidden(*wb.sheets[index], row)
|
return SheetRowHidden(*wb.sheets[index], row)
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkbookSheetVisible :: (wb: *Workbook, index: s32) -> s32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 1 }
|
|
||||||
if wb.native != null { return NativeSheetVisible(wb, index) }
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookIsOds :: (wb: *Workbook) -> s32 {
|
|
||||||
return ifx wb != null && wb.native != null && wb.native_format == 1 then 1 else 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookSheetTabColor :: (wb: *Workbook, index: s32, out: *SheetTabColor) -> s32 {
|
|
||||||
if out != null { out.* = SheetTabColor.{} }
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count || out == null { return 0 }
|
|
||||||
if wb.native != null { return NativeSheetTabColor(wb, index, out) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookSetSheetVisible :: (wb: *Workbook, index: s32, visible: s32) -> s32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0 }
|
|
||||||
if wb.native != null { return NativeSetSheetVisible(wb, index, visible) }
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookColHidden :: (wb: *Workbook, index: s32, col: s32) -> s32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0 }
|
|
||||||
if wb.native != null { return NativeColHidden(wb, index, col) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookColWidth :: (wb: *Workbook, index: s32, col: s32) -> float32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0.0 }
|
|
||||||
if wb.native != null { return NativeColWidth(wb, index, col) }
|
|
||||||
return 0.0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookRowHeight :: (wb: *Workbook, index: s32, row: s32) -> float32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0.0 }
|
|
||||||
if wb.native != null { return NativeRowHeight(wb, index, row) }
|
|
||||||
return 0.0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookColDistancePts :: (wb: *Workbook, index: s32, from: s32, to: s32) -> float64 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0.0 }
|
|
||||||
if wb.native != null { return NativeColDistancePts(wb, index, from, to) }
|
|
||||||
return 0.0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookRowDistancePts :: (wb: *Workbook, index: s32, from: s32, to: s32) -> float64 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0.0 }
|
|
||||||
if wb.native != null { return NativeRowDistancePts(wb, index, from, to) }
|
|
||||||
return 0.0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookCellMerge :: (wb: *Workbook, index: s32, row: s32, col: s32, out: *CellMerge) -> s32 {
|
|
||||||
if out != null { out.* = CellMerge.{} }
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count || out == null { return 0 }
|
|
||||||
if wb.native != null { return NativeCellMerge(wb, index, row, col, out) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookCellStyle :: (wb: *Workbook, index: s32, row: s32, col: s32, out: *CellStyle) -> s32 {
|
|
||||||
if out != null { out.* = CellStyle.{} }
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count || out == null { return 0 }
|
|
||||||
if wb.native != null { return NativeCellStyle(wb, index, row, col, out) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Colors one region of a native sheet; the built-in engine has no styles.
|
|
||||||
WorkbookStyleRange :: (wb: *Workbook, index: s32, start_row: s32, start_col: s32,
|
|
||||||
end_row: s32, end_col: s32, back_rgba: u32, ink_rgba: u32, bold: s32) -> s32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0 }
|
|
||||||
if wb.native != null {
|
|
||||||
return NativeStyleRange(wb, index, start_row, start_col, end_row, end_col,
|
|
||||||
back_rgba, ink_rgba, bold)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookFormatRange :: (wb: *Workbook,index: s32,r0: s32,c0: s32,r1: s32,c1: s32,command: s32) -> s32 {
|
|
||||||
return NativeFormatRange(wb,index,r0,c0,r1,c1,command)
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookChartCount :: (wb: *Workbook, index: s32) -> s32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0 }
|
|
||||||
if wb.native != null { return NativeChartCount(wb, index) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookChartBounds :: (wb: *Workbook, index: s32, chart_index: s32, out: *SheetChart) -> s32 {
|
|
||||||
if out != null { out.* = SheetChart.{} }
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count || out == null { return 0 }
|
|
||||||
if wb.native != null { return NativeChartBounds(wb, index, chart_index, out) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookChartRenderRgba :: (wb: *Workbook, index: s32, chart_index: s32, width: s32, height: s32, out_rgba: []u8) -> s32 {
|
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count { return 0 }
|
|
||||||
if wb.native != null { return NativeChartRenderRgba(wb, index, chart_index, width, height, out_rgba) }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookSetRowsHidden :: (wb: *Workbook, index: s32, first: s32, last: s32, hidden: s32) -> s32 {
|
WorkbookSetRowsHidden :: (wb: *Workbook, index: s32, first: s32, last: s32, hidden: s32) -> s32 {
|
||||||
if wb == null || index < 0 || index >= wb.sheet_count ||
|
if wb == null || index < 0 || index >= wb.sheet_count ||
|
||||||
first < 0 || first > last || first >= WB_MAX_ROWS || last >= WB_MAX_ROWS {
|
first < 0 || first > last || first >= WB_MAX_ROWS || last >= WB_MAX_ROWS {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if wb.native != null {
|
if wb.native != null {
|
||||||
@@ -29724,7 +29537,7 @@ WorkbookCellText :: (wb: *Workbook, index: s32, row: s32, col: s32) -> *s8 {
|
|||||||
if index < 0 || index >= wb.sheet_count {
|
if index < 0 || index >= wb.sheet_count {
|
||||||
return CText("")
|
return CText("")
|
||||||
}
|
}
|
||||||
cell = ifx wb.native!=null then NativeCachedCell(wb,index,row,col) else CellAt(*wb.sheets[index], row, col)
|
cell = CellAt(*wb.sheets[index], row, col)
|
||||||
if cell == null {
|
if cell == null {
|
||||||
return CText("")
|
return CText("")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,533 +0,0 @@
|
|||||||
// The geld finance profile's own behavior: the profile sheet carries its
|
|
||||||
// presentation — navy section bands with white bold text and banded total
|
|
||||||
// rows — and the exchange rates its rows name refresh once when the profile
|
|
||||||
// opens, never again while the window stays open. Crypto ids go to coingecko
|
|
||||||
// and fiat codes to the same keyless forex tables the profile always used;
|
|
||||||
// an id a source does not know keeps its last saved rate.
|
|
||||||
Engine :: #import "engine"
|
|
||||||
EditorModel :: #import "editor"
|
|
||||||
Http :: #import "kryon/http_transfer"
|
|
||||||
Json :: #import "std/json_scan"
|
|
||||||
Time :: #import "std/date_time_linux"
|
|
||||||
#import "std/byte_text_linux"
|
|
||||||
#import "std/float_text"
|
|
||||||
#import "std/net_http"
|
|
||||||
#import "std/text_buffer"
|
|
||||||
|
|
||||||
#scope_file
|
|
||||||
libc :: #system_library "libc";
|
|
||||||
FormatBytes :: (output: *u8, capacity: u64, format: *u8, args: ..any) -> s32 #foreign libc "snprintf";
|
|
||||||
|
|
||||||
// The finance table's width and scan bounds, and the band palette the
|
|
||||||
// portfolio documents use: navy sections with white bold text, light blue
|
|
||||||
// totals with dark bold text.
|
|
||||||
GELD_COLUMNS :: 8;
|
|
||||||
GELD_SCAN_ROWS :: 256;
|
|
||||||
GELD_SECTION_BACK :: 0x182b49ff;
|
|
||||||
GELD_SECTION_INK :: 0xffffffff;
|
|
||||||
GELD_TOTAL_BACK :: 0xddebf7ff;
|
|
||||||
GELD_TOTAL_INK :: 0x17233bff;
|
|
||||||
GELD_IDS :: 24;
|
|
||||||
GELD_RATES :: 48;
|
|
||||||
GELD_ID_BYTES :: 48;
|
|
||||||
GELD_FIAT_BYTES :: 8;
|
|
||||||
GELD_TIMEOUT :: 8000;
|
|
||||||
|
|
||||||
GeldRate :: struct {
|
|
||||||
id: [GELD_ID_BYTES]u8;
|
|
||||||
value: float64;
|
|
||||||
}
|
|
||||||
|
|
||||||
// One refresh, advancing a stage per frame: crypto prices first, then the
|
|
||||||
// fiat table, once more through the fallback when the first fiat source
|
|
||||||
// answers nothing. Stage four holds the answers while a cell edit finishes.
|
|
||||||
GeldFetch :: struct {
|
|
||||||
quote_index: s32;
|
|
||||||
quote_sheet: s32;
|
|
||||||
quotes_updated: s32;
|
|
||||||
stage: s32;
|
|
||||||
transfer: Http.HttpTransfer;
|
|
||||||
crypto: [GELD_IDS][GELD_ID_BYTES]u8;
|
|
||||||
crypto_count: s32;
|
|
||||||
fiat: [GELD_IDS][GELD_FIAT_BYTES]u8;
|
|
||||||
fiat_count: s32;
|
|
||||||
rates: [GELD_RATES]GeldRate;
|
|
||||||
rate_count: s32;
|
|
||||||
errors: [192]u8;
|
|
||||||
}
|
|
||||||
|
|
||||||
geld: GeldFetch;
|
|
||||||
response: [131072]u8;
|
|
||||||
|
|
||||||
CopyText :: (out: []u8, text: string) {
|
|
||||||
if out.count == 0 { return }
|
|
||||||
at: s32 = 0
|
|
||||||
while at < cast(s32)text.count && at + 1 < cast(s32)out.count {
|
|
||||||
out[at] = text[at]
|
|
||||||
at += 1
|
|
||||||
}
|
|
||||||
out[at] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
UpperFold :: (byte: u8) -> u8 {
|
|
||||||
if byte >= cast(u8)97 && byte <= cast(u8)122 { return byte - cast(u8)32 }
|
|
||||||
return byte
|
|
||||||
}
|
|
||||||
|
|
||||||
StartsFold :: (text: string, prefix: string) -> bool {
|
|
||||||
if text.count < prefix.count { return false }
|
|
||||||
at: s32 = 0
|
|
||||||
while at < cast(s32)prefix.count {
|
|
||||||
if UpperFold(text[at]) != UpperFold(prefix[at]) { return false }
|
|
||||||
at += 1
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
EqualsFold :: (text: string, other: string) -> bool {
|
|
||||||
if text.count != other.count { return false }
|
|
||||||
at: s32 = 0
|
|
||||||
while at < cast(s32)text.count {
|
|
||||||
if UpperFold(text[at]) != UpperFold(other[at]) { return false }
|
|
||||||
at += 1
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// A row id is a fiat code, a ticker with a coingecko market id, or a plain
|
|
||||||
// coingecko id. Returns GELD_NONE when the id names nothing fetchable.
|
|
||||||
GELD_NONE :: 0;
|
|
||||||
GELD_FIAT :: 1;
|
|
||||||
GELD_COIN :: 2;
|
|
||||||
|
|
||||||
GeldClassify :: (text: string, out: []u8) -> s32 {
|
|
||||||
fiat_codes: [12]string = .["EUR", "USD", "GBP", "JPY", "BRL", "CHF", "AUD", "CAD", "SGD", "IDR", "THB", "PYG"]
|
|
||||||
tickers: [4]string = .["XMR", "BTC", "ETH", "LTC"]
|
|
||||||
coins: [4]string = .["monero", "bitcoin", "ethereum", "litecoin"]
|
|
||||||
at: s32 = 0
|
|
||||||
end: s32 = cast(s32)text.count
|
|
||||||
while at < end && (text[at] == #char " " || text[at] == #char "\t") { at += 1 }
|
|
||||||
while end > at && (text[end - 1] == #char " " || text[end - 1] == #char "\t") { end -= 1 }
|
|
||||||
if at >= end { return GELD_NONE }
|
|
||||||
trimmed := text[at:end]
|
|
||||||
for fiat: fiat_codes {
|
|
||||||
if EqualsFold(trimmed, fiat) {
|
|
||||||
CopyText(out, fiat)
|
|
||||||
return GELD_FIAT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for index: 0..tickers.count - 1 {
|
|
||||||
if EqualsFold(trimmed, tickers[index]) {
|
|
||||||
CopyText(out, coins[index])
|
|
||||||
return GELD_COIN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Coingecko market ids are lowercase letters, digits and hyphens.
|
|
||||||
for byte: trimmed {
|
|
||||||
if !(byte >= cast(u8)97 && byte <= cast(u8)122) &&
|
|
||||||
!(byte >= cast(u8)48 && byte <= cast(u8)57) && byte != cast(u8)45 {
|
|
||||||
return GELD_NONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CopyText(out, trimmed)
|
|
||||||
return GELD_COIN
|
|
||||||
}
|
|
||||||
|
|
||||||
RowText :: (book: *Engine.Workbook, row: s32, col: s32) -> string {
|
|
||||||
return TextFromCString(cast(*u8)Engine.WorkbookCellText(book, 0, row, col))
|
|
||||||
}
|
|
||||||
|
|
||||||
// A section row names a group in column A and carries nothing in B; a total
|
|
||||||
// row's label in B starts with "total".
|
|
||||||
GeldRowSection :: (book: *Engine.Workbook, row: s32) -> bool {
|
|
||||||
return RowText(book, row, 0).count > 0 && RowText(book, row, 1).count == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
GeldRowTotal :: (book: *Engine.Workbook, row: s32) -> bool {
|
|
||||||
return StartsFold(RowText(book, row, 1), "total")
|
|
||||||
}
|
|
||||||
|
|
||||||
AppendBytes :: (out: []u8, text: string) {
|
|
||||||
at: s32 = 0
|
|
||||||
while at < cast(s32)out.count { if out[at] == 0 { break }; at += 1 }
|
|
||||||
index: s32 = 0
|
|
||||||
while index < cast(s32)text.count && at + 1 < cast(s32)out.count {
|
|
||||||
out[at] = text[index]
|
|
||||||
at += 1
|
|
||||||
index += 1
|
|
||||||
}
|
|
||||||
if at < cast(s32)out.count { out[at] = 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
StoreRate :: (id: string, value: float64) {
|
|
||||||
if geld.rate_count >= GELD_RATES { return }
|
|
||||||
CopyText(geld.rates[geld.rate_count].id[:], id)
|
|
||||||
geld.rates[geld.rate_count].value = value
|
|
||||||
geld.rate_count += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
FindRate :: (id: string) -> (value: float64, found: bool) {
|
|
||||||
index: s32 = 0
|
|
||||||
while index < geld.rate_count {
|
|
||||||
if EqualsFold(TextFromCString(*geld.rates[index].id[0]), id) {
|
|
||||||
return geld.rates[index].value, true
|
|
||||||
}
|
|
||||||
index += 1
|
|
||||||
}
|
|
||||||
return 0.0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads the ids column, C. Unique fetch ids are kept for the requests; a
|
|
||||||
// plain USD needs no request at all.
|
|
||||||
GeldScanIds :: (book: *Engine.Workbook) -> s32 {
|
|
||||||
geld.crypto_count = 0
|
|
||||||
geld.fiat_count = 0
|
|
||||||
rows := Engine.WorkbookSheetRows(book, 0)
|
|
||||||
if rows > GELD_SCAN_ROWS { rows = GELD_SCAN_ROWS }
|
|
||||||
id: [GELD_ID_BYTES]u8
|
|
||||||
for row: 0..rows - 1 {
|
|
||||||
if GeldRowSection(book, row) || GeldRowTotal(book, row) { continue }
|
|
||||||
text := RowText(book, row, 2)
|
|
||||||
if text.count == 0 { continue }
|
|
||||||
kind := GeldClassify(text, id[:])
|
|
||||||
if kind == GELD_FIAT {
|
|
||||||
code := TextFromCString(*id[0])
|
|
||||||
if EqualsFold(code, "USD") { continue }
|
|
||||||
known := false
|
|
||||||
for index: 0..geld.fiat_count - 1 {
|
|
||||||
if EqualsFold(TextFromCString(*geld.fiat[index][0]), code) { known = true }
|
|
||||||
}
|
|
||||||
if !known && geld.fiat_count < GELD_IDS {
|
|
||||||
CopyText(geld.fiat[geld.fiat_count][:], code)
|
|
||||||
geld.fiat_count += 1
|
|
||||||
}
|
|
||||||
} else if kind == GELD_COIN {
|
|
||||||
coin := TextFromCString(*id[0])
|
|
||||||
known := false
|
|
||||||
for index: 0..geld.crypto_count - 1 {
|
|
||||||
if TextFromCString(*geld.crypto[index][0]) == coin { known = true }
|
|
||||||
}
|
|
||||||
if !known && geld.crypto_count < GELD_IDS {
|
|
||||||
CopyText(geld.crypto[geld.crypto_count][:], coin)
|
|
||||||
geld.crypto_count += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StoreRate("USD", 1.0)
|
|
||||||
return geld.crypto_count + geld.fiat_count
|
|
||||||
}
|
|
||||||
|
|
||||||
StartRequest :: (url: string) -> bool {
|
|
||||||
request: HttpRequest
|
|
||||||
request.method = "GET"
|
|
||||||
request.url = url
|
|
||||||
// The price sources' front doors refuse clients that name no browser.
|
|
||||||
headers: [1]HttpHeader
|
|
||||||
headers[0] = HttpHeader.{"User-Agent", "Mozilla/5.0"}
|
|
||||||
request.headers = headers[:]
|
|
||||||
return Http.HttpTransferStart(*geld.transfer, request, response[:], GELD_TIMEOUT)
|
|
||||||
}
|
|
||||||
|
|
||||||
ParseCoins :: (text: string) {
|
|
||||||
index: s32 = 0
|
|
||||||
while index < geld.crypto_count {
|
|
||||||
id := TextFromCString(*geld.crypto[index][0])
|
|
||||||
entry := Json.FieldAt(text, 0, id)
|
|
||||||
if entry >= 0 {
|
|
||||||
usd := Json.FieldAt(text, entry, "usd")
|
|
||||||
if usd >= 0 {
|
|
||||||
number: Json.JsonNumber = Json.ReadNumber(text, usd)
|
|
||||||
if number.valid && number.value > 0.0 { StoreRate(id, number.value) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Both fiat tables are per-1-USD, so a unit's USD rate is the inverse.
|
|
||||||
// Returns how many of the profile's codes the table answered.
|
|
||||||
ParseFiat :: (text: string) -> s32 {
|
|
||||||
table := Json.FieldAt(text, 0, "rates")
|
|
||||||
if table < 0 { return 0 }
|
|
||||||
answered: s32 = 0
|
|
||||||
index: s32 = 0
|
|
||||||
while index < geld.fiat_count {
|
|
||||||
code := TextFromCString(*geld.fiat[index][0])
|
|
||||||
at := Json.FieldAt(text, table, code)
|
|
||||||
if at >= 0 {
|
|
||||||
number: Json.JsonNumber = Json.ReadNumber(text, at)
|
|
||||||
if number.valid && number.value > 0.0 {
|
|
||||||
StoreRate(code, 1.0 / number.value)
|
|
||||||
answered += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index += 1
|
|
||||||
}
|
|
||||||
return answered
|
|
||||||
}
|
|
||||||
|
|
||||||
#scope_export
|
|
||||||
|
|
||||||
// Styles the profile sheet's own rows: navy bands with white bold text for
|
|
||||||
// the sections, light blue bands with dark bold text for the totals. A
|
|
||||||
// portable sheet keeps whatever it carries. Returns how many rows changed.
|
|
||||||
GeldStyleSheet :: (editor: *EditorModel.Editor) -> s32 {
|
|
||||||
book := EditorModel.EditorWorkbook(editor)
|
|
||||||
if book == null || book.native == null { return 0 }
|
|
||||||
if Engine.WorkbookSheetCount(book) < 1 { return 0 }
|
|
||||||
rows := Engine.WorkbookSheetRows(book, 0)
|
|
||||||
if rows > GELD_SCAN_ROWS { rows = GELD_SCAN_ROWS }
|
|
||||||
styled: s32 = 0
|
|
||||||
for row: 0..rows - 1 {
|
|
||||||
if GeldRowSection(book, row) {
|
|
||||||
if Engine.WorkbookStyleRange(book, 0, row, 0, row, GELD_COLUMNS - 1,
|
|
||||||
GELD_SECTION_BACK, GELD_SECTION_INK, 1) != 0 { styled += 1 }
|
|
||||||
} else if GeldRowTotal(book, row) {
|
|
||||||
if Engine.WorkbookStyleRange(book, 0, row, 0, row, GELD_COLUMNS - 1,
|
|
||||||
GELD_TOTAL_BACK, GELD_TOTAL_INK, 1) != 0 { styled += 1 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return styled
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begins the profile's one rate refresh. The window stays responsive: each
|
|
||||||
// request runs on Kryon's transfer worker and is polled a stage per frame.
|
|
||||||
GeldStartRates :: (editor: *EditorModel.Editor) {
|
|
||||||
book := EditorModel.EditorWorkbook(editor)
|
|
||||||
if book == null { return }
|
|
||||||
geld.stage = 0
|
|
||||||
geld.rate_count = 0
|
|
||||||
geld.errors[0] = 0
|
|
||||||
if GeldScanIds(book) < 1 { return }
|
|
||||||
EditorModel.EditorSetStatus(editor, "Fetching rates…")
|
|
||||||
if geld.crypto_count > 0 {
|
|
||||||
url: [640]u8
|
|
||||||
CopyText(url[:], "https://api.coingecko.com/api/v3/simple/price?ids=")
|
|
||||||
index: s32 = 0
|
|
||||||
while index < geld.crypto_count {
|
|
||||||
if index > 0 { AppendBytes(url[:], ",") }
|
|
||||||
AppendBytes(url[:], TextFromCString(*geld.crypto[index][0]))
|
|
||||||
index += 1
|
|
||||||
}
|
|
||||||
AppendBytes(url[:], "&vs_currencies=usd")
|
|
||||||
if StartRequest(TextFromCString(*url[0])) {
|
|
||||||
geld.stage = 1
|
|
||||||
EditorModel.EditorSetStatus(editor, "Fetching rates…")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
AppendBytes(geld.errors[:], "coingecko unavailable")
|
|
||||||
}
|
|
||||||
GeldStartFiat(editor)
|
|
||||||
}
|
|
||||||
|
|
||||||
GeldStartFiat :: (editor: *EditorModel.Editor) {
|
|
||||||
if geld.fiat_count < 1 { GeldApply(editor); return }
|
|
||||||
if StartRequest("https://open.er-api.com/v6/latest/USD") {
|
|
||||||
geld.stage = 2
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if StartRequest("https://api.frankfurter.app/latest?from=USD") {
|
|
||||||
geld.stage = 3
|
|
||||||
return
|
|
||||||
}
|
|
||||||
AppendBytes(geld.errors[:], ifx geld.errors[0] != 0 then "; " else "")
|
|
||||||
AppendBytes(geld.errors[:], "fiat rates unavailable")
|
|
||||||
GeldApply(editor)
|
|
||||||
}
|
|
||||||
|
|
||||||
// One frame of the refresh: consumes a finished answer, starts the next
|
|
||||||
// stage, and applies the rates once every stage has ended. An edit in
|
|
||||||
// progress is never interrupted; its frame applies the answers instead.
|
|
||||||
GeldPoll :: (editor: *EditorModel.Editor) {
|
|
||||||
if geld.stage == 4 {
|
|
||||||
if !EditorModel.EditorEditingCell(editor) { geld.stage = 0; GeldApply(editor) }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if geld.stage==5 && EditorModel.EditorEditingCell(editor) { return }
|
|
||||||
if geld.stage < 1 { return }
|
|
||||||
status: s32
|
|
||||||
length: s64
|
|
||||||
result := Http.HttpTransferPollLength(*geld.transfer, *status, *length)
|
|
||||||
if result == -1 { return }
|
|
||||||
received := GeldConsumeResponse(editor, result, status, length)
|
|
||||||
if geld.stage==5 {
|
|
||||||
if !received { QuoteError(quote_slots[geld.quote_index].symbol) }
|
|
||||||
geld.quote_index+=1; GeldNextQuote(editor); return
|
|
||||||
}
|
|
||||||
if geld.stage == 1 {
|
|
||||||
if !received { AppendBytes(geld.errors[:], "coingecko unavailable") }
|
|
||||||
GeldStartFiat(editor)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if geld.stage == 2 {
|
|
||||||
if received { GeldApply(editor); return }
|
|
||||||
if StartRequest("https://api.frankfurter.app/latest?from=USD") {
|
|
||||||
geld.stage = 3
|
|
||||||
return
|
|
||||||
}
|
|
||||||
AppendBytes(geld.errors[:], ifx geld.errors[0] != 0 then "; " else "")
|
|
||||||
AppendBytes(geld.errors[:], "fiat rates unavailable")
|
|
||||||
GeldApply(editor)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if geld.stage == 3 {
|
|
||||||
if !received {
|
|
||||||
AppendBytes(geld.errors[:], ifx geld.errors[0] != 0 then "; " else "")
|
|
||||||
AppendBytes(geld.errors[:], "fiat rates unavailable")
|
|
||||||
}
|
|
||||||
GeldApply(editor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finish using the response view before starting another transfer into its
|
|
||||||
// backing buffer. Only an owned boolean crosses that boundary.
|
|
||||||
GeldConsumeResponse :: (editor: *EditorModel.Editor, result: s32, status: s32, length: s64) -> bool {
|
|
||||||
if result != 1 || status != 200 || length <= 0 || length >= cast(s64)response.count { return false }
|
|
||||||
text := TextView(response[0:length])
|
|
||||||
if geld.stage == 5 { return GeldApplyQuote(editor, text) }
|
|
||||||
if geld.stage == 1 { ParseCoins(text); return true }
|
|
||||||
return ParseFiat(text) > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drops a refresh in flight: a document opened over the profile workbook is
|
|
||||||
// not the profile's to update.
|
|
||||||
GeldCancel :: () {
|
|
||||||
Http.HttpTransferCancel(*geld.transfer)
|
|
||||||
geld.stage = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rewrites the rate column with the fetched prices, the pct column with the
|
|
||||||
// move against each row's previous rate, and saves once. Rows whose rate
|
|
||||||
// cell is a formula keep their own rate.
|
|
||||||
GeldApply :: (editor: *EditorModel.Editor) {
|
|
||||||
// One refresh applies once; the stage ends here whatever happens below.
|
|
||||||
geld.stage = 0
|
|
||||||
if EditorModel.EditorEditingCell(editor) {
|
|
||||||
// Wait for a frame without an active edit; the answers are ready.
|
|
||||||
geld.stage = 4
|
|
||||||
return
|
|
||||||
}
|
|
||||||
book := EditorModel.EditorWorkbook(editor)
|
|
||||||
if book == null { return }
|
|
||||||
changed: s32 = 0
|
|
||||||
id: [GELD_ID_BYTES]u8
|
|
||||||
rows := Engine.WorkbookSheetRows(book, 0)
|
|
||||||
if rows > GELD_SCAN_ROWS { rows = GELD_SCAN_ROWS }
|
|
||||||
cell: [64]u8
|
|
||||||
for row: 0..rows - 1 {
|
|
||||||
if GeldRowSection(book, row) || GeldRowTotal(book, row) { continue }
|
|
||||||
text := RowText(book, row, 2)
|
|
||||||
if text.count == 0 { continue }
|
|
||||||
kind := GeldClassify(text, id[:])
|
|
||||||
if kind == GELD_NONE { continue }
|
|
||||||
rate, found := FindRate(TextFromCString(*id[0]))
|
|
||||||
if !found { continue }
|
|
||||||
current := RowText(book, row, 4)
|
|
||||||
if current.count > 0 && current[0] == #char "=" { continue }
|
|
||||||
previous, had_previous := ParseFloat64(current)
|
|
||||||
if FormatBytes(*cell[0], cast(u64)cell.count, cast(*u8)Engine.CText("%.15g"), rate) > 0 {
|
|
||||||
Engine.WorkbookSetCell(book, 0, row, 4, cast(*s8)*cell[0])
|
|
||||||
changed += 1
|
|
||||||
}
|
|
||||||
pct := RowText(book, row, 5)
|
|
||||||
if had_previous && previous > 0.0 && !(pct.count > 0 && pct[0] == #char "=") {
|
|
||||||
move := (rate - previous) / previous
|
|
||||||
if FormatBytes(*cell[0], cast(u64)cell.count, cast(*u8)Engine.CText("%.15g"), move) > 0 {
|
|
||||||
Engine.WorkbookSetCell(book, 0, row, 5, cast(*s8)*cell[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if changed > 0 {
|
|
||||||
EditorModel.EditorExternalChange(editor)
|
|
||||||
}
|
|
||||||
GeldStartQuotes(editor)
|
|
||||||
if geld.stage==5 { return }
|
|
||||||
if geld.errors[0] != 0 {
|
|
||||||
EditorModel.EditorSetStatus(editor, TextFromCString(*geld.errors[0]))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if geld.rate_count < 1 { return }
|
|
||||||
message: [64]u8
|
|
||||||
now := Time.LocalNow()
|
|
||||||
if now.valid && FormatBytes(*message[0], cast(u64)message.count,
|
|
||||||
cast(*u8)Engine.CText("updated %02d:%02d:%02d"), now.hour, now.minute, now.second) > 0 {
|
|
||||||
EditorModel.EditorSetStatus(editor, TextFromCString(*message[0]))
|
|
||||||
} else {
|
|
||||||
EditorModel.EditorSetStatus(editor, "Rates updated")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refresh the same USD security lines as the planner, once at open. Source
|
|
||||||
// and market time stay in the existing internal quote cells, outside the table.
|
|
||||||
QuoteSlot :: struct { symbol: string; row: s32; units_col: s32; price_col: s32; meta_row: s32; }
|
|
||||||
quote_slots :: QuoteSlot.[
|
|
||||||
.{symbol="FWRA.L",row=10,units_col=1,price_col=2,meta_row=10},
|
|
||||||
.{symbol="SPCX",row=11,units_col=1,price_col=2,meta_row=11},
|
|
||||||
.{symbol="IGLN.L",row=12,units_col=1,price_col=2,meta_row=12},
|
|
||||||
.{symbol="ISLN.L",row=13,units_col=1,price_col=2,meta_row=13},
|
|
||||||
.{symbol="WCOA.L",row=14,units_col=1,price_col=2,meta_row=14},
|
|
||||||
.{symbol="SPCE.L",row=16,units_col=1,price_col=2,meta_row=15},
|
|
||||||
.{symbol="RBTX.L",row=10,units_col=11,price_col=12,meta_row=16},
|
|
||||||
.{symbol="SMR",row=11,units_col=11,price_col=12,meta_row=17},
|
|
||||||
.{symbol="XMR-USD",row=15,units_col=1,price_col=2,meta_row=18},
|
|
||||||
.{symbol="NVDA",row=12,units_col=11,price_col=12,meta_row=19},
|
|
||||||
.{symbol="NET",row=13,units_col=11,price_col=12,meta_row=20}
|
|
||||||
];
|
|
||||||
QuoteUrl :: (symbol: string,out: []u8) {
|
|
||||||
CopyText(out,"https://query1.finance.yahoo.com/v8/finance/chart/"); AppendBytes(out,symbol); AppendBytes(out,"?interval=1d&range=1d")
|
|
||||||
}
|
|
||||||
QuoteError :: (symbol: string) {
|
|
||||||
if geld.errors[0]!=0 { AppendBytes(geld.errors[:],"; ") }
|
|
||||||
AppendBytes(geld.errors[:],symbol); AppendBytes(geld.errors[:]," quote unavailable")
|
|
||||||
}
|
|
||||||
GeldStartQuotes :: (editor: *EditorModel.Editor) {
|
|
||||||
book:=EditorModel.EditorWorkbook(editor); geld.quote_sheet=-1
|
|
||||||
for i: 0..Engine.WorkbookSheetCount(book)-1 { if Engine.TextCompareLiteral(Engine.WorkbookSheetName(book,cast(s32)i),"Holdings")==0 { geld.quote_sheet=cast(s32)i } }
|
|
||||||
if geld.quote_sheet<0 { return }
|
|
||||||
geld.quote_index=0; geld.quotes_updated=0; GeldNextQuote(editor)
|
|
||||||
}
|
|
||||||
GeldNextQuote :: (editor: *EditorModel.Editor) {
|
|
||||||
book:=EditorModel.EditorWorkbook(editor)
|
|
||||||
while geld.quote_index<cast(s32)quote_slots.count {
|
|
||||||
slot:=quote_slots[geld.quote_index]
|
|
||||||
units,valid:=ParseFloat64(TextFromCString(cast(*u8)Engine.WorkbookCellText(book,geld.quote_sheet,slot.row,slot.units_col)))
|
|
||||||
if valid && units!=0 {
|
|
||||||
url: [256]u8; QuoteUrl(slot.symbol,url[:])
|
|
||||||
if StartRequest(TextFromCString(*url[0])) { geld.stage=5; EditorModel.EditorSetStatus(editor,"Updating prices…"); return }
|
|
||||||
QuoteError(slot.symbol)
|
|
||||||
}
|
|
||||||
geld.quote_index+=1
|
|
||||||
}
|
|
||||||
geld.stage=0
|
|
||||||
if geld.errors[0]!=0 { EditorModel.EditorSetStatus(editor,TextFromCString(*geld.errors[0])) }
|
|
||||||
else if geld.quotes_updated>0 { EditorModel.EditorSetStatus(editor,"Prices and rates updated") }
|
|
||||||
}
|
|
||||||
GeldApplyQuote :: (editor: *EditorModel.Editor,text: string) -> bool {
|
|
||||||
slot:=quote_slots[geld.quote_index]
|
|
||||||
chart:=Json.FieldAt(text,0,"chart"); results:=Json.FieldAt(text,chart,"result")
|
|
||||||
first:=Json.ElementAt(text,results,0); meta:=Json.FieldAt(text,first,"meta")
|
|
||||||
if meta<0 { return false }
|
|
||||||
symbol: [64]u8; currency: [16]u8; company: [256]u8
|
|
||||||
if Json.ReadStringText(text,Json.FieldAt(text,meta,"symbol"),symbol[:])<0 || TextFromCString(*symbol[0])!=slot.symbol { return false }
|
|
||||||
if Json.ReadStringText(text,Json.FieldAt(text,meta,"currency"),currency[:])<0 || TextFromCString(*currency[0])!="USD" { return false }
|
|
||||||
if slot.symbol=="SPCX" {
|
|
||||||
if Json.ReadStringText(text,Json.FieldAt(text,meta,"longName"),company[:])<0 || !StartsFold(TextFromCString(*company[0]),"Space Exploration") { return false }
|
|
||||||
}
|
|
||||||
price:=Json.ReadNumber(text,Json.FieldAt(text,meta,"regularMarketPrice"))
|
|
||||||
previous:=Json.ReadNumber(text,Json.FieldAt(text,meta,"chartPreviousClose"))
|
|
||||||
epoch:=Json.ReadNumber(text,Json.FieldAt(text,meta,"regularMarketTime")); now:=Time.UnixNow()
|
|
||||||
if !price.valid || price.value<=0 || !previous.valid || previous.value<=0 || !epoch.valid || epoch.value<=0 || epoch.value>cast(float64)(now+300) || cast(float64)now-epoch.value>604800 { return false }
|
|
||||||
book:=EditorModel.EditorWorkbook(editor); sheet:=geld.quote_sheet
|
|
||||||
number: [64]u8
|
|
||||||
unused FormatBytes(*number[0],64,cast(*u8)Engine.CText("%.15g"),price.value)
|
|
||||||
if Engine.WorkbookSetCell(book,sheet,slot.row,slot.price_col,cast(*s8)*number[0])==0 { return false }
|
|
||||||
unused Engine.WorkbookSetCell(book,sheet,slot.meta_row,25,cast(*s8)*number[0])
|
|
||||||
unused FormatBytes(*number[0],64,cast(*u8)Engine.CText("%.15g"),previous.value)
|
|
||||||
unused Engine.WorkbookSetCell(book,sheet,slot.meta_row,26,cast(*s8)*number[0])
|
|
||||||
stamp:=Time.UtcAt(cast(s64)epoch.value)
|
|
||||||
unused FormatBytes(*number[0],64,cast(*u8)Engine.CText("%04d-%02d-%02dT%02d:%02d:%02dZ"),stamp.year,stamp.month,stamp.day,stamp.hour,stamp.minute,stamp.second)
|
|
||||||
unused Engine.WorkbookSetCell(book,sheet,slot.meta_row,24,cast(*s8)*number[0])
|
|
||||||
url: [256]u8; QuoteUrl(slot.symbol,url[:])
|
|
||||||
unused Engine.WorkbookSetCell(book,sheet,slot.meta_row,28,cast(*s8)*url[0])
|
|
||||||
geld.quotes_updated+=1; EditorModel.EditorExternalChange(editor); return true
|
|
||||||
}
|
|
||||||
+70
-1187
File diff suppressed because it is too large.
Load diff
+109
-179
@@ -2,23 +2,21 @@
|
|||||||
// and cell squares, and a read-only view of a workbook with column letters,
|
// and cell squares, and a read-only view of a workbook with column letters,
|
||||||
// row numbers, the cells of one sheet and its sheet tabs. The Workbook editor
|
// row numbers, the cells of one sheet and its sheet tabs. The Workbook editor
|
||||||
// paints its own grid with the same squares and colors.
|
// paints its own grid with the same squares and colors.
|
||||||
Styles :: #import "kryon/style";
|
|
||||||
TabBar :: #import "kryon/tab_bar";
|
|
||||||
View :: #import "grid_view";
|
|
||||||
Text :: #import "kryon/text";
|
|
||||||
#import "kryon/drawing_props"
|
|
||||||
#import "kryon/geometry"
|
|
||||||
#import "kryon/session"
|
|
||||||
#if !#defined(KRYON_HOSTED_UI) {
|
|
||||||
#import "kryon/tree_input"
|
|
||||||
#import "kryon/font_metrics"
|
|
||||||
#import "kryon/paint_queue"
|
|
||||||
KryonTheme :: #import "kryon/theme";
|
|
||||||
}
|
|
||||||
#if #defined(KRYON_HOSTED_UI) {
|
#if #defined(KRYON_HOSTED_UI) {
|
||||||
|
#import "geometry"
|
||||||
|
#import "session"
|
||||||
|
#import "drawing_props"
|
||||||
|
#import "box_props"
|
||||||
|
#import "box_widget"
|
||||||
|
#import "text_props"
|
||||||
|
#import "text_align"
|
||||||
|
#import "text_widget"
|
||||||
|
#import "tab_bar_props"
|
||||||
|
#import "tab_bar_widget"
|
||||||
Engine :: #import "portable_engine";
|
Engine :: #import "portable_engine";
|
||||||
Theme :: #import "kryon/app_theme";
|
Theme :: #import "kryon/app_theme";
|
||||||
} else {
|
} else {
|
||||||
|
using UI :: #import "kryon/Widgets";
|
||||||
Engine :: #import "engine";
|
Engine :: #import "engine";
|
||||||
#import "std/c_string"
|
#import "std/c_string"
|
||||||
}
|
}
|
||||||
@@ -90,18 +88,12 @@ GridColor :: (name: string) -> Color {
|
|||||||
}
|
}
|
||||||
return Theme.AppThemeColor(name, Color.{245, 245, 245, 255})
|
return Theme.AppThemeColor(name, Color.{245, 245, 245, 255})
|
||||||
} else {
|
} else {
|
||||||
if name == "border-soft" { return StyleTokenColor("border") }
|
|
||||||
return StyleTokenColor(name)
|
return StyleTokenColor(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GridHeaderBackground :: () -> Color { return GridColor("surface") }
|
GridHeaderBackground :: () -> Color { return GridColor("surface") }
|
||||||
GridCellBackground :: () -> Color { return Color.{255, 255, 255, 255} }
|
GridCellBackground :: () -> Color { return GridColor("card") }
|
||||||
GridSelectedBackground :: () -> Color {
|
GridSelectedBackground :: () -> Color { return GridColor("accent-soft") }
|
||||||
accent := GridAccentColor()
|
|
||||||
return Color.{cast(u8)((255 * 4 + cast(s32)accent.r) / 5),
|
|
||||||
cast(u8)((255 * 4 + cast(s32)accent.g) / 5),
|
|
||||||
cast(u8)((255 * 4 + cast(s32)accent.b) / 5), 255}
|
|
||||||
}
|
|
||||||
GridAccentColor :: () -> Color { return GridColor("accent") }
|
GridAccentColor :: () -> Color { return GridColor("accent") }
|
||||||
GridLineColor :: () -> Color { return GridColor("border-soft") }
|
GridLineColor :: () -> Color { return GridColor("border-soft") }
|
||||||
|
|
||||||
@@ -109,79 +101,25 @@ GridLineColor :: () -> Color { return GridColor("border-soft") }
|
|||||||
// It uses two widget keys, key and key + 1.
|
// It uses two widget keys, key and key + 1.
|
||||||
GridSquare :: (session: Session, key: u64, bounds: Rectangle, right: float32, bottom: float32,
|
GridSquare :: (session: Session, key: u64, bounds: Rectangle, right: float32, bottom: float32,
|
||||||
fill: Color, text: string, align_end: bool = false) {
|
fill: Color, text: string, align_end: bool = false) {
|
||||||
empty_style: Engine.CellStyle
|
|
||||||
luma := (cast(s32)fill.r * 299 + cast(s32)fill.g * 587 + cast(s32)fill.b * 114) / 1000
|
|
||||||
ink := ifx luma < 140 then Color.{248, 250, 252, 255} else Color.{17, 24, 39, 255}
|
|
||||||
GridSquareStyled(session, key, bounds, right, bottom, fill, GridLineColor(), text,
|
|
||||||
true, ink, false, false, ifx align_end then 2 else 0, Text.Text14, *empty_style)
|
|
||||||
}
|
|
||||||
|
|
||||||
// One styled grid square with optional explicit text color, bold/italic,
|
|
||||||
// horizontal alignment (0 start, 1 center, 2 end), font size, gridline color,
|
|
||||||
// and per-edge cell borders.
|
|
||||||
GridSquareStyled :: (session: Session, key: u64, bounds: Rectangle, right: float32, bottom: float32,
|
|
||||||
fill: Color, grid_line: Color, text: string, has_fg: bool, fg: Color, bold: bool, italic: bool,
|
|
||||||
align: s32, font_size: s32, borders: *Engine.CellStyle) {
|
|
||||||
if bounds.x + bounds.width > right { bounds.width = right - bounds.x }
|
if bounds.x + bounds.width > right { bounds.width = right - bounds.x }
|
||||||
if bounds.y + bounds.height > bottom { bounds.height = bottom - bounds.y }
|
if bounds.y + bounds.height > bottom { bounds.height = bottom - bounds.y }
|
||||||
if bounds.width <= 0.0 || bounds.height <= 0.0 { return }
|
if bounds.width <= 0.0 || bounds.height <= 0.0 { return }
|
||||||
View.DrawCellBackground(session, key, bounds, fill, grid_line)
|
box: BoxProps
|
||||||
#if !#defined(KRYON_HOSTED_UI) {
|
box.key = key
|
||||||
if borders != null {
|
box.bounds = bounds
|
||||||
if borders.border_top_width > 0 {
|
box.fill = fill
|
||||||
bw := cast(float32)borders.border_top_width
|
box.border = GridLineColor()
|
||||||
PaintRoundedFill(session, -1, Rectangle.{bounds.x, bounds.y, bounds.width, bw}, 0.0, 1, ColorFromPacked(borders.border_top_rgba))
|
Box(session, box)
|
||||||
}
|
|
||||||
if borders.border_bottom_width > 0 {
|
|
||||||
bw := cast(float32)borders.border_bottom_width
|
|
||||||
PaintRoundedFill(session, -1, Rectangle.{bounds.x, bounds.y + bounds.height - bw, bounds.width, bw}, 0.0, 1, ColorFromPacked(borders.border_bottom_rgba))
|
|
||||||
}
|
|
||||||
if borders.border_left_width > 0 {
|
|
||||||
bw := cast(float32)borders.border_left_width
|
|
||||||
PaintRoundedFill(session, -1, Rectangle.{bounds.x, bounds.y, bw, bounds.height}, 0.0, 1, ColorFromPacked(borders.border_left_rgba))
|
|
||||||
}
|
|
||||||
if borders.border_right_width > 0 {
|
|
||||||
bw := cast(float32)borders.border_right_width
|
|
||||||
PaintRoundedFill(session, -1, Rectangle.{bounds.x + bounds.width - bw, bounds.y, bw, bounds.height}, 0.0, 1, ColorFromPacked(borders.border_right_rgba))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if text.count == 0 { return }
|
if text.count == 0 { return }
|
||||||
size := font_size
|
label: TextProps
|
||||||
if size < 6 { size = 6 }
|
label.key = key + 1
|
||||||
if size > 96 { size = 96 }
|
label.text = text
|
||||||
#if !#defined(KRYON_HOSTED_UI) {
|
label.font = Text14
|
||||||
face: string
|
label.wrap = TextWrap.TextWrapNone
|
||||||
if borders != null { face=TextUntilNul(borders.font_name[:]) }
|
if align_end { label.align = TextAlign.TextAlignEnd }
|
||||||
if face.count>0 || has_fg || bold || italic || size != Text.Text14 || bounds.height > 26.0 {
|
label.bounds = Rectangle.{bounds.x + 4.0, bounds.y + 3.0,
|
||||||
color := ifx has_fg then fg else ColorFromPacked(KryonTheme.CurrentText())
|
bounds.width - 8.0, bounds.height - 4.0}
|
||||||
inner_x := bounds.x + 4.0
|
Text(session, label)
|
||||||
inner_w := bounds.width - 8.0
|
|
||||||
if inner_w <= 1.0 { return }
|
|
||||||
text_w := cast(float32)GlyphWidth(text, size, face)
|
|
||||||
tx := inner_x
|
|
||||||
if align == 1 {
|
|
||||||
if inner_w > text_w { tx = inner_x + (inner_w - text_w) * 0.5 }
|
|
||||||
} else if align == 2 {
|
|
||||||
if inner_w > text_w { tx = inner_x + (inner_w - text_w) }
|
|
||||||
}
|
|
||||||
line_h := cast(float32)GlyphLineHeight(size, face)
|
|
||||||
if line_h <= 0.0 { line_h = cast(float32)size + 4.0 }
|
|
||||||
ty := bounds.y + (bounds.height - line_h) * 0.5
|
|
||||||
if ty < bounds.y + 1.0 { ty = bounds.y + 1.0 }
|
|
||||||
clip := Rectangle.{bounds.x + 2.0, bounds.y + 1.0, bounds.width - 4.0, bounds.height - 2.0}
|
|
||||||
if clip.width <= 0.0 || clip.height <= 0.0 { return }
|
|
||||||
if italic {
|
|
||||||
PaintClippedSlanted(session, -1, text, cast(s32)tx, cast(s32)ty, size, color, clip, false, face)
|
|
||||||
if bold { PaintClippedSlanted(session, -1, text, cast(s32)tx, cast(s32)ty, size, color, clip, true, face) }
|
|
||||||
} else {
|
|
||||||
PaintClippedLabel(session, -1, text, cast(s32)tx, cast(s32)ty, size, color, clip, face)
|
|
||||||
if bold { PaintClippedEmphasis(session, -1, text, cast(s32)tx, cast(s32)ty, size, color, clip, face) }
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
View.DrawCellLabel(session, key, bounds, text, size, align)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Column letters: A to Z, then AA to ZZ.
|
// Column letters: A to Z, then AA to ZZ.
|
||||||
@@ -410,98 +348,90 @@ GridInside :: (x: float32, y: float32, bounds: Rectangle) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Per-frame workbook data and geometry for the TSX grid.
|
|
||||||
GridFrame :: struct {
|
|
||||||
book: *Engine.Workbook;
|
|
||||||
table: Rectangle;
|
|
||||||
sheets: s32;
|
|
||||||
rows: s32;
|
|
||||||
right: float32;
|
|
||||||
bottom: float32;
|
|
||||||
frozen: s32;
|
|
||||||
shown_rows: s32;
|
|
||||||
}
|
|
||||||
|
|
||||||
GridTabList :: struct {
|
|
||||||
sheets: [16]s32;
|
|
||||||
tabs: [16]TabBar.Tab;
|
|
||||||
count: s32;
|
|
||||||
selected: s32;
|
|
||||||
}
|
|
||||||
|
|
||||||
GridTextBuffer :: struct { bytes: [256]u8; }
|
|
||||||
GridLabel :: struct { text: string; numeric: bool; }
|
|
||||||
|
|
||||||
// Geometry, scroll clamping and workbook access stay in the native model.
|
|
||||||
GridPrepareFrame :: (bounds: Rectangle, book: *Engine.Workbook, view: *GridView, input: GridInput) -> GridFrame {
|
|
||||||
frame: GridFrame
|
|
||||||
frame.book = book
|
|
||||||
if book == null { return frame }
|
|
||||||
frame.sheets = Engine.WorkbookSheetCount(book)
|
|
||||||
if frame.sheets < 1 { return frame }
|
|
||||||
frame.table = bounds
|
|
||||||
if frame.sheets > 1 { frame.table.height -= GridTabsHeight }
|
|
||||||
frame.right = frame.table.x + frame.table.width
|
|
||||||
frame.bottom = frame.table.y + frame.table.height
|
|
||||||
view.visible_rows = cast(s32)((frame.table.height - GridHeaderHeight) / GridRowHeight)
|
|
||||||
if view.visible_rows < 1 { view.visible_rows = 1 }
|
|
||||||
GridClamp(book, view)
|
|
||||||
GridScroll(book, view, input, frame.table)
|
|
||||||
frame.rows = Engine.WorkbookSheetRows(book, view.sheet)
|
|
||||||
columns := Engine.WorkbookSheetColumns(book, view.sheet)
|
|
||||||
frame.frozen = view.frozen_rows
|
|
||||||
if frame.frozen < 0 { frame.frozen = 0 }
|
|
||||||
if frame.frozen > frame.rows { frame.frozen = frame.rows }
|
|
||||||
view.visible_columns = 0
|
|
||||||
at := frame.table.x + GridRowHeaderWidth
|
|
||||||
while at < frame.right && view.visible_columns < GridColumnsMax {
|
|
||||||
if view.trim && view.scroll_column + view.visible_columns >= columns { break }
|
|
||||||
at += GridWidth(view, view.scroll_column + view.visible_columns)
|
|
||||||
view.visible_columns += 1
|
|
||||||
}
|
|
||||||
if view.trim && at < frame.right { frame.right = at }
|
|
||||||
frame.shown_rows = cast(s32)((frame.table.height - GridHeaderHeight + GridRowHeight - 1.0) / GridRowHeight)
|
|
||||||
return frame
|
|
||||||
}
|
|
||||||
|
|
||||||
GridReadCellLabel :: (frame: GridFrame, view: *GridView, row: s32, column: s32, out: []u8) -> GridLabel {
|
|
||||||
text, numeric := GridCellText(frame.book, view, row, column, out)
|
|
||||||
return GridLabel.{text, numeric}
|
|
||||||
}
|
|
||||||
|
|
||||||
GridRowLabel :: (row: s32) -> string {
|
|
||||||
number: Vec(u8)
|
|
||||||
BuilderPrint(*number, "%", row + 1)
|
|
||||||
return BuilderFinish(number)
|
|
||||||
}
|
|
||||||
|
|
||||||
GridReadTabs :: (frame: GridFrame, view: *GridView, list: *GridTabList) {
|
|
||||||
list.count = 0
|
|
||||||
list.selected = 0
|
|
||||||
for index: 0..frame.sheets - 1 {
|
|
||||||
if Engine.WorkbookSheetVisible(frame.book, index) != 0 && list.count < 16 {
|
|
||||||
list.sheets[list.count] = index
|
|
||||||
list.count += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if list.count == 0 {
|
|
||||||
list.count = ifx frame.sheets > 16 then 16 else frame.sheets
|
|
||||||
for index: 0..list.count - 1 { list.sheets[index] = index }
|
|
||||||
}
|
|
||||||
for index: 0..list.count - 1 {
|
|
||||||
sheet := list.sheets[index]
|
|
||||||
list.tabs[index].key = view.key + cast(u64)(90000 + index)
|
|
||||||
list.tabs[index].label = GridSheetName(frame.book, sheet)
|
|
||||||
if sheet == view.sheet { list.selected = index }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draws the sheet tabs along the bottom when the workbook has more than one
|
// Draws the sheet tabs along the bottom when the workbook has more than one
|
||||||
// sheet, and the shown sheet's grid above them: frozen rows first, then the
|
// sheet, and the shown sheet's grid above them: frozen rows first, then the
|
||||||
// scrolled rows, filling bounds with empty cells as the editor does unless the
|
// scrolled rows, filling bounds with empty cells as the editor does unless the
|
||||||
// view is trimmed. The wheel scrolls; see GridScroll.
|
// view is trimmed. The wheel scrolls; see GridScroll.
|
||||||
// Preserve the public host API; all grid and tab composition is in TSX.
|
|
||||||
GridDraw :: (session: Session, bounds: Rectangle, book: *Engine.Workbook, view: *GridView, input: GridInput) {
|
GridDraw :: (session: Session, bounds: Rectangle, book: *Engine.Workbook, view: *GridView, input: GridInput) {
|
||||||
frame := GridPrepareFrame(bounds, book, view, input)
|
sheets := Engine.WorkbookSheetCount(book)
|
||||||
View.WorkbookGrid(session, bounds, view, frame)
|
if book == null || sheets < 1 { return }
|
||||||
|
table := bounds
|
||||||
|
if sheets > 1 { table.height -= GridTabsHeight }
|
||||||
|
right := table.x + table.width
|
||||||
|
bottom := table.y + table.height
|
||||||
|
view.visible_rows = cast(s32)((table.height - GridHeaderHeight) / GridRowHeight)
|
||||||
|
if view.visible_rows < 1 { view.visible_rows = 1 }
|
||||||
|
GridClamp(book, view)
|
||||||
|
GridScroll(book, view, input, table)
|
||||||
|
rows := Engine.WorkbookSheetRows(book, view.sheet)
|
||||||
|
columns := Engine.WorkbookSheetColumns(book, view.sheet)
|
||||||
|
frozen := view.frozen_rows
|
||||||
|
if frozen < 0 { frozen = 0 }
|
||||||
|
if frozen > rows { frozen = rows }
|
||||||
|
view.visible_columns = 0
|
||||||
|
at := table.x + GridRowHeaderWidth
|
||||||
|
while at < right && view.visible_columns < GridColumnsMax {
|
||||||
|
if view.trim && view.scroll_column + view.visible_columns >= columns { break }
|
||||||
|
at += GridWidth(view, view.scroll_column + view.visible_columns)
|
||||||
|
view.visible_columns += 1
|
||||||
|
}
|
||||||
|
// A trimmed grid ends at its last column and row.
|
||||||
|
if view.trim && at < right { right = at }
|
||||||
|
|
||||||
|
GridSquare(session, view.key, Rectangle.{table.x, table.y, GridRowHeaderWidth, GridHeaderHeight}, right, bottom, GridHeaderBackground(), "")
|
||||||
|
for shown: 0..view.visible_columns - 1 {
|
||||||
|
column := view.scroll_column + shown
|
||||||
|
name := GridColumnName(column)
|
||||||
|
GridSquare(session, view.key + cast(u64)(2 + shown * 2), Rectangle.{GridColumnX(view, table.x, column), table.y, GridWidth(view, column), GridHeaderHeight},
|
||||||
|
right, bottom, GridHeaderBackground(), name)
|
||||||
|
}
|
||||||
|
// Every row that fits, past the sheet's last row as well unless trimmed.
|
||||||
|
shown_rows := cast(s32)((table.height - GridHeaderHeight + GridRowHeight - 1.0) / GridRowHeight)
|
||||||
|
for shown: 0..shown_rows - 1 {
|
||||||
|
row := ifx shown < frozen then shown else view.scroll_row + shown
|
||||||
|
if view.trim && row >= rows { break }
|
||||||
|
heading := shown < frozen || (view.total_rows > 0 && row >= rows - view.total_rows && row < rows)
|
||||||
|
fill := ifx heading then GridHeaderBackground() else GridCellBackground()
|
||||||
|
y := table.y + GridHeaderHeight + cast(float32)shown * GridRowHeight
|
||||||
|
number: Vec(u8)
|
||||||
|
BuilderPrint(*number, "%", row + 1)
|
||||||
|
GridSquare(session, view.key + cast(u64)(2000 + shown * 2), Rectangle.{table.x, y, GridRowHeaderWidth, GridRowHeight},
|
||||||
|
right, bottom, GridHeaderBackground(), BuilderFinish(number))
|
||||||
|
for index: 0..view.visible_columns - 1 {
|
||||||
|
column := view.scroll_column + index
|
||||||
|
display: [256]u8
|
||||||
|
text, numeric := GridCellText(book, view, row, column, display[:])
|
||||||
|
GridSquare(session, view.key + cast(u64)(100000 + (shown * GridColumnsMax + index) * 2),
|
||||||
|
Rectangle.{GridColumnX(view, table.x, column), y, GridWidth(view, column), GridRowHeight},
|
||||||
|
right, bottom, fill, text, numeric)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sheets < 2 { return }
|
||||||
|
count := ifx sheets > 16 then 16 else sheets
|
||||||
|
tabs: [16]Tab
|
||||||
|
for index: 0..count - 1 {
|
||||||
|
tabs[index].key = view.key + cast(u64)(90000 + index)
|
||||||
|
tabs[index].label = GridSheetName(book, index)
|
||||||
|
}
|
||||||
|
strip: BoxProps
|
||||||
|
strip.key = view.key + 89998
|
||||||
|
strip.bounds = Rectangle.{bounds.x, bottom, bounds.width, GridTabsHeight}
|
||||||
|
strip.fill = GridHeaderBackground()
|
||||||
|
strip.border = GridLineColor()
|
||||||
|
Box(session, strip)
|
||||||
|
bar: TabBarProps
|
||||||
|
bar.key = view.key + 89999
|
||||||
|
bar.placement = TabBarPlacement.TabBarBottom
|
||||||
|
bar.selected_index = view.sheet
|
||||||
|
width := 140.0 * cast(float32)count
|
||||||
|
bar.bounds = Rectangle.{bounds.x, bottom, ifx width < bounds.width then width else bounds.width, GridTabsHeight}
|
||||||
|
bar.min_tab_width = 96
|
||||||
|
bar.max_tab_width = 160
|
||||||
|
result := TabBar(session, bar, tabs[0:count])
|
||||||
|
if result.selected_index != view.sheet && result.selected_index >= 0 {
|
||||||
|
view.sheet = result.selected_index
|
||||||
|
view.scroll_row = 0
|
||||||
|
view.scroll_column = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
import * as NativeBox from "kryon/box";
|
|
||||||
import { Color } from "kryon/drawing_props";
|
|
||||||
import { Rectangle } from "kryon/geometry";
|
|
||||||
import { Session } from "kryon/session";
|
|
||||||
import * as NativeText from "kryon/text";
|
|
||||||
import { TextAlign } from "kryon/text_align";
|
|
||||||
import { Box } from "kryon/tsx/box";
|
|
||||||
import { Text } from "kryon/tsx/text";
|
|
||||||
import { TabBar } from "kryon/tsx/tab_bar";
|
|
||||||
import * as Grid from "grid";
|
|
||||||
import * as NativeTabs from "kryon/tab_bar";
|
|
||||||
|
|
||||||
export function DrawCellBackground(session: Session, key: u64, bounds: Rectangle, fill: Color, line: Color): void {
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: key, bounds: bounds, fill: fill, border: line})}/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function DrawCellLabel(session: Session, key: u64, bounds: Rectangle, text: string, size: s32, align: s32): void {
|
|
||||||
const label: NativeText.Props = nativeInit<NativeText.Props>({
|
|
||||||
key: key + u64(1), text: text, size: size, wrap: NativeText.Wrap.TextWrapNone,
|
|
||||||
bounds: {x: bounds.x + float32(4), y: bounds.y + float32(3),
|
|
||||||
width: bounds.width - float32(8), height: bounds.height - float32(4)},
|
|
||||||
});
|
|
||||||
if (align === s32(1)) { label.align = TextAlign.TextAlignCenter; }
|
|
||||||
else if (align === s32(2)) { label.align = TextAlign.TextAlignEnd; }
|
|
||||||
<Text session={session} props={label}/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The read-only embeddable grid uses the same cell primitives as the editor.
|
|
||||||
export function WorkbookGrid(session: Session, bounds: Rectangle, view: NativeRef<Grid.GridView>, frame: Grid.GridFrame): void {
|
|
||||||
if (frame.sheets < s32(1)) { return; }
|
|
||||||
const table = frame.table;
|
|
||||||
const headerWidth = float32(Grid.GridRowHeaderWidth);
|
|
||||||
const headerHeight = float32(Grid.GridHeaderHeight);
|
|
||||||
const rowHeight = float32(Grid.GridRowHeight);
|
|
||||||
Grid.GridSquare(session, view.key, {x: table.x, y: table.y, width: headerWidth, height: headerHeight},
|
|
||||||
frame.right, frame.bottom, Grid.GridHeaderBackground(), "", false);
|
|
||||||
for (let shown = s32(0); shown < view.visible_columns; shown += s32(1)) {
|
|
||||||
const column = view.scroll_column + shown;
|
|
||||||
Grid.GridSquare(session, view.key + u64(s32(2) + shown * s32(2)),
|
|
||||||
{x: Grid.GridColumnX(view, table.x, column), y: table.y, width: Grid.GridWidth(view, column), height: headerHeight},
|
|
||||||
frame.right, frame.bottom, Grid.GridHeaderBackground(), Grid.GridColumnName(column), false);
|
|
||||||
}
|
|
||||||
for (let shown = s32(0); shown < frame.shown_rows; shown += s32(1)) {
|
|
||||||
const row = shown < frame.frozen ? shown : view.scroll_row + shown;
|
|
||||||
if (view.trim && row >= frame.rows) { break; }
|
|
||||||
const heading = shown < frame.frozen || (view.total_rows > s32(0) && row >= frame.rows - view.total_rows && row < frame.rows);
|
|
||||||
const fill = heading ? Grid.GridHeaderBackground() : Grid.GridCellBackground();
|
|
||||||
const y = table.y + headerHeight + float32(shown) * rowHeight;
|
|
||||||
Grid.GridSquare(session, view.key + u64(s32(2000) + shown * s32(2)),
|
|
||||||
{x: table.x, y: y, width: headerWidth, height: rowHeight}, frame.right, frame.bottom,
|
|
||||||
Grid.GridHeaderBackground(), Grid.GridRowLabel(row), false);
|
|
||||||
for (let index = s32(0); index < view.visible_columns; index += s32(1)) {
|
|
||||||
const column = view.scroll_column + index;
|
|
||||||
const display: Grid.GridTextBuffer = nativeInit<Grid.GridTextBuffer>({});
|
|
||||||
const label = Grid.GridReadCellLabel(frame, view, row, column, nativeSlice(display.bytes));
|
|
||||||
Grid.GridSquare(session, view.key + u64(s32(100000) + (shown * s32(Grid.GridColumnsMax) + index) * s32(2)),
|
|
||||||
{x: Grid.GridColumnX(view, table.x, column), y: y, width: Grid.GridWidth(view, column), height: rowHeight},
|
|
||||||
frame.right, frame.bottom, fill, label.text, label.numeric);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (frame.sheets < s32(2)) { return; }
|
|
||||||
const list: Grid.GridTabList = nativeInit<Grid.GridTabList>({});
|
|
||||||
Grid.GridReadTabs(frame, view, nativeRef(list));
|
|
||||||
<Box session={session} props={nativeInit<NativeBox.Props>({key: view.key + u64(89998),
|
|
||||||
bounds: {x: bounds.x, y: frame.bottom, width: bounds.width, height: float32(Grid.GridTabsHeight)},
|
|
||||||
fill: Grid.GridHeaderBackground(), border: Grid.GridLineColor()})}/>;
|
|
||||||
const width = float32(140) * float32(list.count);
|
|
||||||
const props: NativeTabs.Props = nativeInit<NativeTabs.Props>({key: view.key + u64(89999),
|
|
||||||
placement: NativeTabs.TabBarPlacement.TabBarBottom, selected_index: list.selected,
|
|
||||||
bounds: {x: bounds.x, y: frame.bottom, width: width < bounds.width ? width : bounds.width, height: float32(Grid.GridTabsHeight)},
|
|
||||||
min_tab_width: s32(96), max_tab_width: s32(160)});
|
|
||||||
const result = TabBar({session: session, props: props, tabs: nativeSlice(list.tabs, s32(0), list.count)});
|
|
||||||
if (result.selected_index >= s32(0) && result.selected_index < list.count) {
|
|
||||||
const selected = nativeAt(list.sheets, result.selected_index);
|
|
||||||
if (selected !== view.sheet) {
|
|
||||||
view.sheet = selected;
|
|
||||||
view.scroll_row = s32(0);
|
|
||||||
view.scroll_column = s32(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,15 +7,6 @@
|
|||||||
Json :: #import "std/json_scan";
|
Json :: #import "std/json_scan";
|
||||||
|
|
||||||
Workbook :: struct { id: s32; sheets: s32; cells: s32; }
|
Workbook :: struct { id: s32; sheets: s32; cells: s32; }
|
||||||
CellMerge :: struct { start_row: s32; start_col: s32; end_row: s32; end_col: s32; merged: s32; }
|
|
||||||
CellStyle :: struct {
|
|
||||||
bg_rgba: u32; fg_rgba: u32; has_bg: s32; has_fg: s32;
|
|
||||||
bold: s32; italic: s32; align_h: s32; wrap: s32; font_size: float32; font_name: [128]u8;
|
|
||||||
border_top_rgba: u32; border_bottom_rgba: u32; border_left_rgba: u32; border_right_rgba: u32;
|
|
||||||
border_top_width: s32; border_bottom_width: s32; border_left_width: s32; border_right_width: s32;
|
|
||||||
}
|
|
||||||
SheetTabColor :: struct { bg_rgba: u32; fg_rgba: u32; has_bg: s32; has_fg: s32; }
|
|
||||||
SheetChart :: struct { left_pts: float64; top_pts: float64; right_pts: float64; bottom_pts: float64; }
|
|
||||||
FormulaRef :: struct {
|
FormulaRef :: struct {
|
||||||
start: s32; end: s32; corner_start: s32; sheet: s32; range: s32
|
start: s32; end: s32; corner_start: s32; sheet: s32; range: s32
|
||||||
row1: s32; col1: s32; row2: s32; col2: s32
|
row1: s32; col1: s32; row2: s32; col2: s32
|
||||||
@@ -177,9 +168,6 @@ WorkbookAddSheet :: (book: *Workbook, name: string) -> s32 {
|
|||||||
return ifx OK(Request("add-sheet", book, 0, 0, 0, name)) then 1 else 0
|
return ifx OK(Request("add-sheet", book, 0, 0, 0, name)) then 1 else 0
|
||||||
}
|
}
|
||||||
WorkbookSheetCount :: (book: *Workbook) -> s32 { return book.sheets }
|
WorkbookSheetCount :: (book: *Workbook) -> s32 { return book.sheets }
|
||||||
WorkbookEvaluateChanged :: (book: *Workbook) { WorkbookEvaluate(book) }
|
|
||||||
WorkbookSnapshot :: (book: *Workbook) -> *Workbook { return WorkbookClone(book) }
|
|
||||||
WorkbookRestoreSnapshot :: (book: *Workbook) -> s32 { return 1 }
|
|
||||||
WorkbookCellCount :: (book: *Workbook) -> s32 { return book.cells }
|
WorkbookCellCount :: (book: *Workbook) -> s32 { return book.cells }
|
||||||
Meta :: (book: *Workbook, sheet: s32) {
|
Meta :: (book: *Workbook, sheet: s32) {
|
||||||
if meta_id != book.id || meta_sheet != sheet { unused Request("info", book, sheet) }
|
if meta_id != book.id || meta_sheet != sheet { unused Request("info", book, sheet) }
|
||||||
@@ -196,11 +184,6 @@ WorkbookSetRowsHidden :: (book: *Workbook, sheet: s32, first: s32, last: s32, hi
|
|||||||
BuilderPrint(*bytes, ",\"last\":%,\"hidden\":%", last, hidden)
|
BuilderPrint(*bytes, ",\"last\":%,\"hidden\":%", last, hidden)
|
||||||
return ifx OK(Request("set-rows-hidden", book, sheet, first, 0, "", BuilderFinish(bytes))) then 1 else 0
|
return ifx OK(Request("set-rows-hidden", book, sheet, first, 0, "", BuilderFinish(bytes))) then 1 else 0
|
||||||
}
|
}
|
||||||
WorkbookEditStructure :: (book: *Workbook,sheet: s32,at: s32,count: s32,rows: bool,insert: bool) -> s32 {
|
|
||||||
operation:=ifx rows then (ifx insert then "insert-row" else "delete-row") else (ifx insert then "insert-column" else "delete-column")
|
|
||||||
for i: 0..count-1 { if !OK(Request(operation,book,sheet,ifx rows then at else 0,ifx rows then 0 else at)) { return 0 } }
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
WorkbookInsertRow :: (book: *Workbook, sheet: s32, row: s32) { unused Request("insert-row", book, sheet, row) }
|
WorkbookInsertRow :: (book: *Workbook, sheet: s32, row: s32) { unused Request("insert-row", book, sheet, row) }
|
||||||
WorkbookDeleteRow :: (book: *Workbook, sheet: s32, row: s32) { unused Request("delete-row", book, sheet, row) }
|
WorkbookDeleteRow :: (book: *Workbook, sheet: s32, row: s32) { unused Request("delete-row", book, sheet, row) }
|
||||||
WorkbookInsertColumn :: (book: *Workbook, sheet: s32, col: s32) { unused Request("insert-column", book, sheet, 0, col) }
|
WorkbookInsertColumn :: (book: *Workbook, sheet: s32, col: s32) { unused Request("insert-column", book, sheet, 0, col) }
|
||||||
@@ -220,21 +203,6 @@ FileRequest :: (book: *Workbook, op: string, path: string) -> s32 {
|
|||||||
}
|
}
|
||||||
WorkbookLoadFile :: (book: *Workbook, path: string) -> s32 { return FileRequest(book, "load", path) }
|
WorkbookLoadFile :: (book: *Workbook, path: string) -> s32 { return FileRequest(book, "load", path) }
|
||||||
WorkbookWriteGnumeric :: (book: *Workbook, path: string) -> s32 { return FileRequest(book, "save", path) }
|
WorkbookWriteGnumeric :: (book: *Workbook, path: string) -> s32 { return FileRequest(book, "save", path) }
|
||||||
WorkbookWriteOds :: (book: *Workbook, path: string) -> s32 { return FileRequest(book, "save", path) }
|
|
||||||
WorkbookSheetVisible :: (book: *Workbook, sheet: s32) -> s32 { unused book; unused sheet; return 1 }
|
|
||||||
WorkbookIsOds :: (book: *Workbook) -> s32 { unused book; return 0 }
|
|
||||||
WorkbookSheetTabColor :: (book: *Workbook, sheet: s32, out: *SheetTabColor) -> s32 { unused book; unused sheet; if out != null { out.* = SheetTabColor.{} }; return 0 }
|
|
||||||
WorkbookSetSheetVisible :: (book: *Workbook, sheet: s32, visible: s32) -> s32 { unused book; unused sheet; unused visible; return 0 }
|
|
||||||
WorkbookColHidden :: (book: *Workbook, sheet: s32, col: s32) -> s32 { unused book; unused sheet; unused col; return 0 }
|
|
||||||
WorkbookColWidth :: (book: *Workbook, sheet: s32, col: s32) -> float32 { unused book; unused sheet; unused col; return 0.0 }
|
|
||||||
WorkbookRowHeight :: (book: *Workbook, sheet: s32, row: s32) -> float32 { unused book; unused sheet; unused row; return 0.0 }
|
|
||||||
WorkbookColDistancePts :: (book: *Workbook, sheet: s32, from: s32, to: s32) -> float64 { unused book; unused sheet; unused from; unused to; return 0.0 }
|
|
||||||
WorkbookRowDistancePts :: (book: *Workbook, sheet: s32, from: s32, to: s32) -> float64 { unused book; unused sheet; unused from; unused to; return 0.0 }
|
|
||||||
WorkbookCellMerge :: (book: *Workbook, sheet: s32, row: s32, col: s32, out: *CellMerge) -> s32 { unused book; unused sheet; unused row; unused col; if out != null { out.* = CellMerge.{} }; return 0 }
|
|
||||||
WorkbookCellStyle :: (book: *Workbook, sheet: s32, row: s32, col: s32, out: *CellStyle) -> s32 { unused book; unused sheet; unused row; unused col; if out != null { out.* = CellStyle.{} }; return 0 }
|
|
||||||
WorkbookChartCount :: (book: *Workbook, sheet: s32) -> s32 { unused book; unused sheet; return 0 }
|
|
||||||
WorkbookChartBounds :: (book: *Workbook, sheet: s32, chart_index: s32, out: *SheetChart) -> s32 { unused book; unused sheet; unused chart_index; if out != null { out.* = SheetChart.{} }; return 0 }
|
|
||||||
WorkbookChartRenderRgba :: (book: *Workbook, sheet: s32, chart_index: s32, width: s32, height: s32, out_rgba: []u8) -> s32 { unused book; unused sheet; unused chart_index; unused width; unused height; unused out_rgba; return 0 }
|
|
||||||
|
|
||||||
PacketNumber :: (text: string, at: *s64) -> s32 {
|
PacketNumber :: (text: string, at: *s64) -> s32 {
|
||||||
n: s32
|
n: s32
|
||||||
|
|||||||
+11
-11
@@ -891,20 +891,20 @@ quad_agm_internal :: (res: *Quad, method: s32, x: *Quad) {
|
|||||||
qrp.l = 0
|
qrp.l = 0
|
||||||
if method == {
|
if method == {
|
||||||
case AGM_ARCSIN;
|
case AGM_ARCSIN;
|
||||||
quad_ihypot(*dpk[0], x)
|
quad_ihypot(*dpk[0], x)
|
||||||
gp = one
|
gp = one
|
||||||
qnum = x.*
|
qnum = x.*
|
||||||
case AGM_ARCCOS;
|
case AGM_ARCCOS;
|
||||||
dpk[0] = x.*
|
dpk[0] = x.*
|
||||||
gp = one
|
gp = one
|
||||||
quad_ihypot(*qnum, x)
|
quad_ihypot(*qnum, x)
|
||||||
case AGM_ARCTAN;
|
case AGM_ARCTAN;
|
||||||
dpk[0] = one
|
dpk[0] = one
|
||||||
QuadHypot(*gp, x, *one)
|
QuadHypot(*gp, x, *one)
|
||||||
qnum = x.*
|
qnum = x.*
|
||||||
case;
|
case;
|
||||||
QuadInit(res, NotANumber())
|
QuadInit(res, NotANumber())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
n = 1
|
n = 1
|
||||||
|
|||||||
+1
-2
@@ -83,8 +83,7 @@ Save :: (book: *Engine.Workbook, files: *AppFiles, name: string) -> bool {
|
|||||||
if !CopyCString(suffix, temporary[:]) { return false }
|
if !CopyCString(suffix, temporary[:]) { return false }
|
||||||
fd := Temporary(*temporary[0])
|
fd := Temporary(*temporary[0])
|
||||||
if fd < 0 { return false }
|
if fd < 0 { return false }
|
||||||
is_ods := name.count >= 4 && Engine.TextCompareFoldLiteral(Engine.CText(name[name.count - 4:]), ".ods") == 0
|
ok := Engine.WorkbookWriteGnumeric(book, cast(*s8)*temporary[0]) != 0
|
||||||
ok := ifx is_ods then Engine.WorkbookWriteOds(book, cast(*s8)*temporary[0]) != 0 else Engine.WorkbookWriteGnumeric(book, cast(*s8)*temporary[0]) != 0
|
|
||||||
#if !#defined(PLATFORM_WEB) {
|
#if !#defined(PLATFORM_WEB) {
|
||||||
if ok { ok = Sync(fd) == 0 }
|
if ok { ok = Sync(fd) == 0 }
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-70
@@ -32,10 +32,9 @@ TabWidth :: 104;
|
|||||||
|
|
||||||
Background :: 0xF8FAFC;
|
Background :: 0xF8FAFC;
|
||||||
// The fixture theme below is #f8fafc with ink #1e2530, base white, and a
|
// The fixture theme below is #f8fafc with ink #1e2530, base white, and a
|
||||||
// #3070e0 accent. Kryon's public system palette uses the base for surfaces
|
// #3070e0 accent; the app derives its header and selection from those.
|
||||||
// and mixes 20% accent into white spreadsheet paper for the selected cell.
|
HeaderFill :: 0xEDEFF2;
|
||||||
HeaderFill :: 0xFFFFFF;
|
SelectedFill :: 0xCCDCF6;
|
||||||
SelectedFill :: 0xD5E2F8;
|
|
||||||
White :: 0xFFFFFF;
|
White :: 0xFFFFFF;
|
||||||
|
|
||||||
TwoSheets :: #string END
|
TwoSheets :: #string END
|
||||||
@@ -326,27 +325,14 @@ StopApp :: () -> s32 {
|
|||||||
// with the expected rows (CSV text; empty cells at the end of a row may be
|
// with the expected rows (CSV text; empty cells at the end of a row may be
|
||||||
// left out).
|
// left out).
|
||||||
ExpectRows :: (expected: string, message: string) {
|
ExpectRows :: (expected: string, message: string) {
|
||||||
// Autosave waits for a short quiet period so typing does not serialize
|
Check(PathExists(TextUntilNul(saved_path[:])), "the app did not write workbook.gnumeric")
|
||||||
// the workbook on every key. Wait for the expected saved state.
|
|
||||||
output: [65536]u8
|
output: [65536]u8
|
||||||
command: [3]string = .{HeadlessCellPath(), "eval", TextUntilNul(saved_path[:])}
|
command: [3]string = .{HeadlessCellPath(), "eval", TextUntilNul(saved_path[:])}
|
||||||
|
result: CaptureResult = Run(command[:], output[:])
|
||||||
|
Check(result.code == 0 && !result.error && !result.truncated,
|
||||||
|
"the cell command could not evaluate the saved workbook")
|
||||||
|
Check(ParseCsv(0, TextView(output[0:result.length])), "the saved rows are too large")
|
||||||
Check(ParseCsv(1, expected), "the expected rows are too large")
|
Check(ParseCsv(1, expected), "the expected rows are too large")
|
||||||
attempts: s32 = 0
|
|
||||||
while attempts < 40 {
|
|
||||||
if PathExists(TextUntilNul(saved_path[:])) {
|
|
||||||
result: CaptureResult = Run(command[:], output[:])
|
|
||||||
Check(result.code == 0 && !result.error && !result.truncated,
|
|
||||||
"the cell command could not evaluate the saved workbook")
|
|
||||||
Check(ParseCsv(0, TextView(output[0:result.length])), "the saved rows are too large")
|
|
||||||
if DiffCsv(CsvUsedRows(1), "saved", "expected", false) == 0 {
|
|
||||||
SayWith("edit: ", message)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SleepMilliseconds(50)
|
|
||||||
attempts += 1
|
|
||||||
}
|
|
||||||
Check(PathExists(TextUntilNul(saved_path[:])), "the app did not write workbook.gnumeric")
|
|
||||||
heading: [512]u8
|
heading: [512]u8
|
||||||
SetText(heading[:], "FAIL: ")
|
SetText(heading[:], "FAIL: ")
|
||||||
AppendText(heading[:], message)
|
AppendText(heading[:], message)
|
||||||
@@ -360,17 +346,9 @@ ExpectRows :: (expected: string, message: string) {
|
|||||||
ExpectSizes :: (expected: string, message: string) {
|
ExpectSizes :: (expected: string, message: string) {
|
||||||
output: [4096]u8
|
output: [4096]u8
|
||||||
command: [3]string = .{HeadlessCellPath(), "info", TextUntilNul(saved_path[:])}
|
command: [3]string = .{HeadlessCellPath(), "info", TextUntilNul(saved_path[:])}
|
||||||
length: s32 = 0
|
result: CaptureResult = Run(command[:], output[:])
|
||||||
attempts: s32 = 0
|
Check(result.code == 0 && !result.error, "the cell command could not read the saved workbook")
|
||||||
while attempts < 40 {
|
actual: string = TextView(output[0:result.length])
|
||||||
result: CaptureResult = Run(command[:], output[:])
|
|
||||||
length = result.length
|
|
||||||
Check(result.code == 0 && !result.error, "the cell command could not read the saved workbook")
|
|
||||||
if TextView(output[0:result.length]) == expected { return }
|
|
||||||
SleepMilliseconds(50)
|
|
||||||
attempts += 1
|
|
||||||
}
|
|
||||||
actual: string = TextView(output[0:length])
|
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
WriteText(2, "sheets and sizes, expected:\n")
|
WriteText(2, "sheets and sizes, expected:\n")
|
||||||
WriteText(2, expected)
|
WriteText(2, expected)
|
||||||
@@ -581,8 +559,7 @@ DriveAutosave :: (directory: string) -> s32 {
|
|||||||
SetEnvironment("WORKBOOK_PROFILE", "geld")
|
SetEnvironment("WORKBOOK_PROFILE", "geld")
|
||||||
SetEnvironment("XDG_DATA_HOME", TextUntilNul(xdg[:]))
|
SetEnvironment("XDG_DATA_HOME", TextUntilNul(xdg[:]))
|
||||||
UnsetEnvironment("WORKBOOK_DIR")
|
UnsetEnvironment("WORKBOOK_DIR")
|
||||||
// Synthetic legacy-profile tests explicitly opt into their private data.
|
UnsetEnvironment("GELD_DIR")
|
||||||
SetEnvironment("GELD_DIR", TextUntilNul(geld[:]))
|
|
||||||
// Launch from beside the generic workbook; it must not become Geld's data.
|
// Launch from beside the generic workbook; it must not become Geld's data.
|
||||||
working_directory: [4096]u8
|
working_directory: [4096]u8
|
||||||
Check(CopyCString(directory, working_directory[:]) &&
|
Check(CopyCString(directory, working_directory[:]) &&
|
||||||
@@ -590,11 +567,7 @@ DriveAutosave :: (directory: string) -> s32 {
|
|||||||
LaunchApp(directory, TextUntilNul(geld[:]))
|
LaunchApp(directory, TextUntilNul(geld[:]))
|
||||||
TypeText("23")
|
TypeText("23")
|
||||||
ExpectRows("23\n", "Geld autosaves an active edit in its own fresh data directory")
|
ExpectRows("23\n", "Geld autosaves an active edit in its own fresh data directory")
|
||||||
ClickCell(0, 1)
|
|
||||||
Xdotool("type", "--delay", "0", "exit flush", "", "")
|
|
||||||
SleepMilliseconds(100)
|
|
||||||
Check(StopApp() == 0, "the autosave app did not exit cleanly")
|
Check(StopApp() == 0, "the autosave app did not exit cleanly")
|
||||||
ExpectSavedCell(0, 1, "exit flush")
|
|
||||||
LaunchApp(directory, TextUntilNul(geld[:]))
|
LaunchApp(directory, TextUntilNul(geld[:]))
|
||||||
Key("Return")
|
Key("Return")
|
||||||
TypeText("+1")
|
TypeText("+1")
|
||||||
@@ -676,31 +649,23 @@ DriveAutosave :: (directory: string) -> s32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ExpectSavedSheetCell :: (sheet: s32, row: s32, column: s32, expected: string, message: string) {
|
ExpectSavedSheetCell :: (sheet: s32, row: s32, column: s32, expected: string, message: string) {
|
||||||
actual_text: [4096]u8
|
saved: *Engine.Workbook = Engine.WorkbookNew()
|
||||||
attempts: s32 = 0
|
if Engine.WorkbookLoadFile(saved, cast(*s8)*saved_path[0]) == 0 {
|
||||||
while attempts < 40 {
|
ShowLog()
|
||||||
if PathExists(TextUntilNul(saved_path[:])) {
|
Fail("cannot read the saved workbook")
|
||||||
saved: *Engine.Workbook = Engine.WorkbookNew()
|
|
||||||
if Engine.WorkbookLoadFile(saved, cast(*s8)*saved_path[0]) == 0 {
|
|
||||||
Engine.WorkbookFree(saved)
|
|
||||||
ShowLog()
|
|
||||||
Fail("cannot read the saved workbook")
|
|
||||||
}
|
|
||||||
source: *s8 = Engine.WorkbookCellText(saved, sheet, row, column)
|
|
||||||
if source == null { SetText(actual_text[:], "") }
|
|
||||||
else { SetText(actual_text[:], TextFromCString(cast(*u8)source)) }
|
|
||||||
Engine.WorkbookFree(saved)
|
|
||||||
if TextUntilNul(actual_text[:]) == expected { return }
|
|
||||||
}
|
|
||||||
SleepMilliseconds(50)
|
|
||||||
attempts += 1
|
|
||||||
}
|
}
|
||||||
WriteText(2, "expected \"")
|
source: *s8 = Engine.WorkbookCellText(saved, sheet, row, column)
|
||||||
WriteText(2, expected)
|
actual: string = ""
|
||||||
WriteText(2, "\", saved \"")
|
if source != null { actual = TextFromCString(cast(*u8)source) }
|
||||||
WriteText(2, TextUntilNul(actual_text[:]))
|
if actual != expected {
|
||||||
WriteText(2, "\"\n")
|
WriteText(2, "expected \"")
|
||||||
Fail(message)
|
WriteText(2, expected)
|
||||||
|
WriteText(2, "\", saved \"")
|
||||||
|
WriteText(2, actual)
|
||||||
|
WriteText(2, "\"\n")
|
||||||
|
Fail(message)
|
||||||
|
}
|
||||||
|
Engine.WorkbookFree(saved)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpectSavedCell :: (row: s32, column: s32, expected: string) {
|
ExpectSavedCell :: (row: s32, column: s32, expected: string) {
|
||||||
@@ -746,13 +711,13 @@ DriveHeaders :: (directory: string) -> s32 {
|
|||||||
result = Run(evaluate[:],bytes[:]); Check(result.code==0 && ParseCsv(0,TextView(bytes[:result.length])),"cannot read cleared column")
|
result = Run(evaluate[:],bytes[:]); Check(result.code==0 && ParseCsv(0,TextView(bytes[:result.length])),"cannot read cleared column")
|
||||||
Check(CsvCellText(0,0,1)=="" && CsvCellText(0,1,1)=="" && CsvCellText(0,20,1)=="","delete clears the entire column")
|
Check(CsvCellText(0,0,1)=="" && CsvCellText(0,1,1)=="" && CsvCellText(0,20,1)=="","delete clears the entire column")
|
||||||
Check(CsvCellText(0,0,0)=="11" && CsvCellText(0,20,2)=="212","column delete preserves neighboring columns")
|
Check(CsvCellText(0,0,0)=="11" && CsvCellText(0,20,2)=="212","column delete preserves neighboring columns")
|
||||||
|
Press(GridLeft-30,GridTop+14); Key("Delete"); Save()
|
||||||
|
// Native CSV trims leading empty rows and columns. Check the saved
|
||||||
|
// coordinates directly so export bounds do not change this selection test.
|
||||||
|
ExpectSavedCell(0,0,""); ExpectSavedCell(0,2,"")
|
||||||
|
ExpectSavedCell(1,2,"22"); ExpectSavedCell(20,2,"212")
|
||||||
|
Check(StopApp()==0,"header test app exits cleanly")
|
||||||
}
|
}
|
||||||
Press(GridLeft-30,GridTop+14); Key("Delete"); Save()
|
|
||||||
// Native CSV trims leading empty rows and columns. Check the saved
|
|
||||||
// coordinates directly so export bounds do not change this selection test.
|
|
||||||
ExpectSavedCell(0,0,""); ExpectSavedCell(0,2,"")
|
|
||||||
ExpectSavedCell(1,2,"22"); ExpectSavedCell(20,2,"212")
|
|
||||||
Check(StopApp()==0,"header test app exits cleanly")
|
|
||||||
|
|
||||||
// Right-clicking a row number targets that row, regardless of the active cell.
|
// Right-clicking a row number targets that row, regardless of the active cell.
|
||||||
Check(WriteWholeFile(TextUntilNul(fixture[:]),RowMenuWorkbook),"cannot write row menu fixture"); StartApp(directory)
|
Check(WriteWholeFile(TextUntilNul(fixture[:]),RowMenuWorkbook),"cannot write row menu fixture"); StartApp(directory)
|
||||||
@@ -1346,7 +1311,6 @@ ExpectHiddenRows :: (first: s32, second: s32, total: float64) {
|
|||||||
Check(Engine.WorkbookLoadFile(saved, cast(*s8)*saved_path[0]) != 0, "cannot load hidden-row save")
|
Check(Engine.WorkbookLoadFile(saved, cast(*s8)*saved_path[0]) != 0, "cannot load hidden-row save")
|
||||||
Check(Engine.WorkbookRowHidden(saved, 0, 1) == first, "second row visibility differs")
|
Check(Engine.WorkbookRowHidden(saved, 0, 1) == first, "second row visibility differs")
|
||||||
Check(Engine.WorkbookRowHidden(saved, 0, 2) == second, "third row visibility differs")
|
Check(Engine.WorkbookRowHidden(saved, 0, 2) == second, "third row visibility differs")
|
||||||
unused Engine.WorkbookCellText(saved, 0, 0, 2)
|
|
||||||
cell := Engine.CellAt(*saved.sheets[0], 0, 2)
|
cell := Engine.CellAt(*saved.sheets[0], 0, 2)
|
||||||
Check(cell != null && cell.cached_kind == Engine.VAL_FLOAT && cell.cached_number == total,
|
Check(cell != null && cell.cached_kind == Engine.VAL_FLOAT && cell.cached_number == total,
|
||||||
"hidden rows were included in the visible total")
|
"hidden rows were included in the visible total")
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@ DropDocument :: (path: string) {
|
|||||||
for byte: path {
|
for byte: path {
|
||||||
encoded: [3]u8
|
encoded: [3]u8
|
||||||
if (byte >= 65 && byte <= 90) || (byte >= 97 && byte <= 122) ||
|
if (byte >= 65 && byte <= 90) || (byte >= 97 && byte <= 122) ||
|
||||||
(byte >= 48 && byte <= 57) || byte == 47 || byte == 45 || byte == 46 || byte == 95 || byte == 126 {
|
(byte >= 48 && byte <= 57) || byte == 47 || byte == 45 || byte == 46 || byte == 95 || byte == 126 {
|
||||||
encoded[0] = byte
|
encoded[0] = byte
|
||||||
AppendText(uri[:], TextView(encoded[0:1]))
|
AppendText(uri[:], TextView(encoded[0:1]))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -248,21 +248,6 @@ main :: () -> s32 {
|
|||||||
ExpectSource(table, 0, 0, 0, "<not xml")
|
ExpectSource(table, 0, 0, 0, "<not xml")
|
||||||
ExpectDisplay(table, 0, 0, 1, "42")
|
ExpectDisplay(table, 0, 0, 1, "42")
|
||||||
Engine.WorkbookFree(table)
|
Engine.WorkbookFree(table)
|
||||||
// Ordinary edits refresh dirty dependencies across sheets and invalidate
|
|
||||||
// source/value caches, without a forced full-workbook recalculation.
|
|
||||||
Check(Engine.WorkbookSetCell(book, 1, 20, 0, Engine.CText("5")) != 0, "cannot set dependency input")
|
|
||||||
Check(Engine.WorkbookSetCell(book, 0, 20, 0, Engine.CText("=Notes!A21*2")) != 0, "cannot set cross-sheet formula")
|
|
||||||
ExpectDisplay(book, 0, 20, 0, "10")
|
|
||||||
ExpectSource(book, 1, 20, 0, "5")
|
|
||||||
Check(Engine.WorkbookSetCell(book, 1, 20, 0, Engine.CText("7")) != 0, "cannot update dependency input")
|
|
||||||
ExpectDisplay(book, 0, 20, 0, "14")
|
|
||||||
ExpectSource(book, 1, 20, 0, "7")
|
|
||||||
Check(Engine.WorkbookSetCell(book, 1, 20, 0, Engine.CText("")) != 0, "cannot clear dependency input")
|
|
||||||
ExpectDisplay(book, 0, 20, 0, "0")
|
|
||||||
Check(Engine.WorkbookSetCell(book, 0, 20, 0, Engine.CText("=Notes!A22+1")) != 0, "cannot replace dependency formula")
|
|
||||||
ExpectDisplay(book, 0, 20, 0, "1")
|
|
||||||
Check(Engine.WorkbookSetCell(book, 1, 21, 0, Engine.CText("9")) != 0, "cannot update replacement dependency")
|
|
||||||
ExpectDisplay(book, 0, 20, 0, "10")
|
|
||||||
Engine.WorkbookFree(saved)
|
Engine.WorkbookFree(saved)
|
||||||
Engine.WorkbookFree(copy)
|
Engine.WorkbookFree(copy)
|
||||||
Engine.WorkbookFree(book)
|
Engine.WorkbookFree(book)
|
||||||
|
|||||||
@@ -3,17 +3,9 @@
|
|||||||
#load "test_support.zi";
|
#load "test_support.zi";
|
||||||
using Grid :: #import "grid";
|
using Grid :: #import "grid";
|
||||||
Engine :: #import "engine";
|
Engine :: #import "engine";
|
||||||
Theme :: #import "kryon/theme";
|
|
||||||
#import "kryon/geometry"
|
|
||||||
|
|
||||||
#program_export
|
#program_export
|
||||||
main :: () -> s32 {
|
main :: () -> s32 {
|
||||||
// Document paper and range selection stay light under a dark app theme.
|
|
||||||
unused Theme.InstallTheme(Theme.DefaultTheme(true))
|
|
||||||
paper := Grid.GridCellBackground()
|
|
||||||
Check(paper.r == 255 && paper.g == 255 && paper.b == 255, "dark theme changed spreadsheet paper")
|
|
||||||
selected := Grid.GridSelectedBackground()
|
|
||||||
Check(selected.r > 190 && selected.g > 190 && selected.b > 190, "range selection is not readable on white paper")
|
|
||||||
micros, ok := Grid.GridMicros("-12.3456785")
|
micros, ok := Grid.GridMicros("-12.3456785")
|
||||||
Check(ok && micros == -12345679, "decimal text in millionths, rounded")
|
Check(ok && micros == -12345679, "decimal text in millionths, rounded")
|
||||||
unused_value, bad := Grid.GridMicros("1e5")
|
unused_value, bad := Grid.GridMicros("1e5")
|
||||||
|
|||||||
@@ -1,159 +0,0 @@
|
|||||||
// A minimal host embeds the exported editor beside host-owned UI on a private
|
|
||||||
// display: open a .gnumeric and a .csv, type a value and a formula, undo/redo,
|
|
||||||
// save, close, reopen, and hand keyboard focus between host and editor.
|
|
||||||
#load "test_support.zi";
|
|
||||||
#import "kryon/private_display"
|
|
||||||
#import "kryon/test_driver_client"
|
|
||||||
|
|
||||||
HostAppPath :: "build/preview/desktop/host/workbook-desktop";
|
|
||||||
|
|
||||||
GnumericDocument :: #string END
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<gnm:Workbook xmlns:gnm="http://www.gnumeric.org/v10.dtd">
|
|
||||||
<gnm:SheetNameIndex><gnm:SheetName>Sheet1</gnm:SheetName></gnm:SheetNameIndex>
|
|
||||||
<gnm:Sheets><gnm:Sheet><gnm:Name>Sheet1</gnm:Name><gnm:MaxCol>1</gnm:MaxCol><gnm:MaxRow>0</gnm:MaxRow>
|
|
||||||
<gnm:Cells>
|
|
||||||
<gnm:Cell Row="0" Col="0" ValueType="40">1</gnm:Cell>
|
|
||||||
<gnm:Cell Row="0" Col="1" ValueType="40">2</gnm:Cell>
|
|
||||||
</gnm:Cells>
|
|
||||||
</gnm:Sheet></gnm:Sheets>
|
|
||||||
</gnm:Workbook>
|
|
||||||
END;
|
|
||||||
|
|
||||||
CsvDocument :: "x,y\n1,2\n";
|
|
||||||
|
|
||||||
// Cell centers in the hosted window: the host sidebar is 200 wide, the grid
|
|
||||||
// header 40, a column 96, the table starts at 60, its header is 24 and a row 22.
|
|
||||||
CellA1X :: 288.0;
|
|
||||||
CellB1X :: 384.0;
|
|
||||||
CellRow1Y :: 95.0;
|
|
||||||
|
|
||||||
failures: s32;
|
|
||||||
path_buffer: [4096]u8;
|
|
||||||
csv_buffer: [4096]u8;
|
|
||||||
driver_buffer: [4096]u8;
|
|
||||||
app_log_buffer: [4096]u8;
|
|
||||||
xvfb_buffer: [4096]u8;
|
|
||||||
editor_document_env: [4200]u8;
|
|
||||||
editor_csv_env: [4200]u8;
|
|
||||||
|
|
||||||
Step :: (ok: bool, what: string) {
|
|
||||||
if ok { return }
|
|
||||||
failures += 1
|
|
||||||
WriteText(2, "FAIL: ")
|
|
||||||
WriteText(2, what)
|
|
||||||
WriteText(2, "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
PathJoin :: (directory: string, name: string, output: []u8) -> string {
|
|
||||||
SetText(output, directory)
|
|
||||||
AppendText(output, "/")
|
|
||||||
AppendText(output, name)
|
|
||||||
return TextUntilNul(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
#program_export
|
|
||||||
main :: () -> s32 {
|
|
||||||
Check(IsExecutable(HostAppPath), "build the host app first: make host-test")
|
|
||||||
UnsetEnvironment("DISPLAY")
|
|
||||||
UnsetEnvironment("WAYLAND_DISPLAY")
|
|
||||||
UnsetEnvironment("XAUTHORITY")
|
|
||||||
template: [4096]u8
|
|
||||||
parent: string = Environment("TMPDIR")
|
|
||||||
if parent.count == 0 { parent = "/tmp" }
|
|
||||||
SetText(template[:], parent)
|
|
||||||
AppendText(template[:], "/workbook-host-XXXXXX")
|
|
||||||
work := MakeTemporaryDirectory(template[:])
|
|
||||||
Check(work.count > 0, "cannot create a temporary directory")
|
|
||||||
SetText(cleanup_directory[:], work)
|
|
||||||
|
|
||||||
gnumeric_path := PathJoin(work, "plan.gnumeric", path_buffer[:])
|
|
||||||
csv_path := PathJoin(work, "plan.csv", csv_buffer[:])
|
|
||||||
Check(WriteWholeFile(gnumeric_path, GnumericDocument), "cannot write the gnumeric document")
|
|
||||||
Check(WriteWholeFile(csv_path, CsvDocument), "cannot write the CSV document")
|
|
||||||
|
|
||||||
driver_path := PathJoin(work, "driver", driver_buffer[:])
|
|
||||||
driver := DriverOpen(driver_path)
|
|
||||||
app_log := PathJoin(work, "app.log", app_log_buffer[:])
|
|
||||||
xvfb_log := PathJoin(work, "xvfb.log", xvfb_buffer[:])
|
|
||||||
display := OpenPrivateDisplay(1000, 700, xvfb_log)
|
|
||||||
if !display.valid {
|
|
||||||
WriteText(2, "FAIL: ")
|
|
||||||
WriteText(2, display.error)
|
|
||||||
WriteText(2, "\n")
|
|
||||||
RemoveTree(work)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
arguments: [1]string
|
|
||||||
arguments[0] = HostAppPath
|
|
||||||
environment: [3]string
|
|
||||||
environment[0] = DriverEnvironment(*driver)
|
|
||||||
SetText(editor_document_env[:], "HOST_TEST_GNUMERIC=")
|
|
||||||
AppendText(editor_document_env[:], gnumeric_path)
|
|
||||||
environment[1] = TextUntilNul(editor_document_env[:])
|
|
||||||
SetText(editor_csv_env[:], "HOST_TEST_CSV=")
|
|
||||||
AppendText(editor_csv_env[:], csv_path)
|
|
||||||
environment[2] = TextUntilNul(editor_csv_env[:])
|
|
||||||
app := StartOnDisplay(*display, arguments[:], environment[:], ".", app_log)
|
|
||||||
if !app.started {
|
|
||||||
WriteText(2, "FAIL: the host app did not start\n")
|
|
||||||
ClosePrivateDisplay(*display)
|
|
||||||
RemoveTree(work)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
cleanup_pid = app.pid
|
|
||||||
DriverWatch(*driver, app.pid, app_log)
|
|
||||||
|
|
||||||
Step(DriverWait(*driver, .{label = "state=open"}, 15000), "the host opens a document")
|
|
||||||
Step(DriverWait(*driver, .{label = "focus=editor"}, 5000), "the editor takes focus")
|
|
||||||
Step(DriverWait(*driver, .{label = "A1=1"}, 5000), "A1 shows the document value")
|
|
||||||
Step(DriverWait(*driver, .{label = "B1=2"}, 5000), "B1 shows the document value")
|
|
||||||
|
|
||||||
Step(DriverTap(*driver, CellA1X, CellRow1Y), "tap A1")
|
|
||||||
Step(DriverType(*driver, "9"), "type a value")
|
|
||||||
Step(DriverWait(*driver, .{label = "A1=9"}, 5000), "A1 shows the typed value")
|
|
||||||
|
|
||||||
Step(DriverTap(*driver, CellB1X, CellRow1Y), "tap B1")
|
|
||||||
Step(DriverType(*driver, "=SUM(1,2)"), "type a formula")
|
|
||||||
Step(DriverWait(*driver, .{label = "B1=3"}, 5000), "B1 calculates the formula")
|
|
||||||
Step(DriverKey(*driver, DRIVER_KEY_ENTER, false, false), "commit the formula")
|
|
||||||
Step(DriverWait(*driver, .{label = "editing=no"}, 5000), "the formula is committed")
|
|
||||||
|
|
||||||
Step(DriverKey(*driver, 90, true, false), "undo")
|
|
||||||
Step(DriverWait(*driver, .{label = "B1=2"}, 5000), "undo restores the old value")
|
|
||||||
Step(DriverKey(*driver, 89, true, false), "redo")
|
|
||||||
Step(DriverWait(*driver, .{label = "B1=3"}, 5000), "redo puts the formula back")
|
|
||||||
|
|
||||||
Step(DriverPress(*driver, .{label = "Save", role = "button"}), "press Save")
|
|
||||||
Step(DriverWait(*driver, .{label = "save=1"}, 5000), "the editor saves once")
|
|
||||||
Step(DriverPress(*driver, .{label = "Close", role = "button"}), "press Close")
|
|
||||||
Step(DriverWait(*driver, .{label = "state=closed"}, 5000), "the editor closes")
|
|
||||||
Step(DriverPress(*driver, .{label = "Reopen", role = "button"}), "press Reopen")
|
|
||||||
Step(DriverWait(*driver, .{label = "state=open"}, 5000), "the editor reopens")
|
|
||||||
Step(DriverWait(*driver, .{label = "A1=9"}, 5000), "the saved value is reloaded")
|
|
||||||
Step(DriverWait(*driver, .{label = "B1=3"}, 5000), "the saved formula is reloaded")
|
|
||||||
|
|
||||||
Step(DriverPress(*driver, .{label = "Open CSV", role = "button"}), "open the CSV document")
|
|
||||||
Step(DriverWait(*driver, .{label = "A1=x"}, 5000), "the CSV text is shown")
|
|
||||||
Step(DriverWait(*driver, .{label = "B1=y"}, 5000), "the CSV header is shown")
|
|
||||||
|
|
||||||
Step(DriverPress(*driver, .{label = "Host focus", role = "button"}), "press Host focus")
|
|
||||||
Step(DriverWait(*driver, .{label = "focus=host"}, 5000), "the host takes focus")
|
|
||||||
Step(DriverType(*driver, "7"), "type while the host has focus")
|
|
||||||
Step(DriverWaitIdle(*driver, 3, 3000), "the host consumes the typed key")
|
|
||||||
Step(DriverTap(*driver, CellA1X, CellRow1Y), "click the editor")
|
|
||||||
Step(DriverWait(*driver, .{label = "focus=editor"}, 5000), "the editor takes focus back")
|
|
||||||
Step(DriverWait(*driver, .{label = "A1=x"}, 5000), "the host's key did not reach the cell")
|
|
||||||
Step(DriverWaitGone(*driver, .{label = "A1=7"}, 2000), "the editor ignored the host-focused key")
|
|
||||||
Step(DriverType(*driver, "3"), "type after focus returns")
|
|
||||||
Step(DriverWait(*driver, .{label = "A1=3"}, 5000), "the editor takes keys again")
|
|
||||||
|
|
||||||
Step(StopOwnedProcess(*app, 5000), "the host app stops")
|
|
||||||
ClosePrivateDisplay(*display)
|
|
||||||
RemoveTree(work)
|
|
||||||
cleanup_pid = 0
|
|
||||||
cleanup_directory[0] = 0
|
|
||||||
if failures > 0 { return 1 }
|
|
||||||
Say("host editor: open, edit, undo/redo, save, close/reopen, CSV and focus hand-off passed")
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
+6
-6
@@ -16,7 +16,7 @@ screenshot_channels: s32 = 0;
|
|||||||
|
|
||||||
BigEndian :: (bytes: []u8, at: s32) -> u32 {
|
BigEndian :: (bytes: []u8, at: s32) -> u32 {
|
||||||
return (cast(u32)bytes[at] << 24) | (cast(u32)bytes[at + 1] << 16) |
|
return (cast(u32)bytes[at] << 24) | (cast(u32)bytes[at + 1] << 16) |
|
||||||
(cast(u32)bytes[at + 2] << 8) | cast(u32)bytes[at + 3]
|
(cast(u32)bytes[at + 2] << 8) | cast(u32)bytes[at + 3]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads and decodes a captured frame. Returns false with the reason in
|
// Loads and decodes a captured frame. Returns false with the reason in
|
||||||
@@ -81,7 +81,7 @@ ReadScreenshot :: (path: string, failure: []u8) -> bool {
|
|||||||
if color == 6 { screenshot_channels = 4 }
|
if color == 6 { screenshot_channels = 4 }
|
||||||
stride: s32 = screenshot_width * screenshot_channels
|
stride: s32 = screenshot_width * screenshot_channels
|
||||||
if screenshot_width <= 0 || screenshot_height <= 0 ||
|
if screenshot_width <= 0 || screenshot_height <= 0 ||
|
||||||
stride * screenshot_height > ScreenshotPixelLimit {
|
stride * screenshot_height > ScreenshotPixelLimit {
|
||||||
SetText(failure, "the capture has unsupported dimensions")
|
SetText(failure, "the capture has unsupported dimensions")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -160,8 +160,8 @@ Distance :: (a: s32, b: s32) -> s32 {
|
|||||||
PixelAt :: (x: s32, y: s32) -> u32 {
|
PixelAt :: (x: s32, y: s32) -> u32 {
|
||||||
offset: s32 = (y * screenshot_width + x) * screenshot_channels
|
offset: s32 = (y * screenshot_width + x) * screenshot_channels
|
||||||
return (cast(u32)screenshot_pixels[offset] << 16) |
|
return (cast(u32)screenshot_pixels[offset] << 16) |
|
||||||
(cast(u32)screenshot_pixels[offset + 1] << 8) |
|
(cast(u32)screenshot_pixels[offset + 1] << 8) |
|
||||||
cast(u32)screenshot_pixels[offset + 2]
|
cast(u32)screenshot_pixels[offset + 2]
|
||||||
}
|
}
|
||||||
|
|
||||||
// How many pixels in a rectangle are dark enough to be text.
|
// How many pixels in a rectangle are dark enough to be text.
|
||||||
@@ -173,8 +173,8 @@ DarkPixels :: (left: s32, top: s32, width: s32, height: s32) -> s32 {
|
|||||||
while x < left + width {
|
while x < left + width {
|
||||||
offset: s32 = (y * screenshot_width + x) * screenshot_channels
|
offset: s32 = (y * screenshot_width + x) * screenshot_channels
|
||||||
sum: s32 = cast(s32)screenshot_pixels[offset] +
|
sum: s32 = cast(s32)screenshot_pixels[offset] +
|
||||||
cast(s32)screenshot_pixels[offset + 1] +
|
cast(s32)screenshot_pixels[offset + 1] +
|
||||||
cast(s32)screenshot_pixels[offset + 2]
|
cast(s32)screenshot_pixels[offset + 2]
|
||||||
if sum < 330 { count += 1 }
|
if sum < 330 { count += 1 }
|
||||||
x += 1
|
x += 1
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-36
@@ -50,46 +50,34 @@ main :: () -> s32 {
|
|||||||
unused Good("{\"op\":\"set\",\"id\":1,\"text\":\"12\"}")
|
unused Good("{\"op\":\"set\",\"id\":1,\"text\":\"12\"}")
|
||||||
unused Good("{\"op\":\"set\",\"id\":1,\"col\":1,\"text\":\"=A1*2\"}")
|
unused Good("{\"op\":\"set\",\"id\":1,\"col\":1,\"text\":\"=A1*2\"}")
|
||||||
unused Good("{\"op\":\"evaluate\",\"id\":1}")
|
unused Good("{\"op\":\"evaluate\",\"id\":1}")
|
||||||
|
reply := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1}")
|
||||||
|
Check(Contains(reply, "=A1*224"), "formula and its result cross the service boundary")
|
||||||
expected: [33]u8
|
expected: [33]u8
|
||||||
{
|
Check(StartsWith(reply[5:], ExpectedMask(-1, -1, expected[:])), "visible rows start unhidden")
|
||||||
reply := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1}")
|
|
||||||
Check(Contains(reply, "=A1*224"), "formula and its result cross the service boundary")
|
|
||||||
Check(StartsWith(reply[5:], ExpectedMask(-1, -1, expected[:])), "visible rows start unhidden")
|
|
||||||
}
|
|
||||||
unused Good("{\"op\":\"set-rows-hidden\",\"id\":1,\"row\":2,\"last\":3,\"hidden\":1}")
|
unused Good("{\"op\":\"set-rows-hidden\",\"id\":1,\"row\":2,\"last\":3,\"hidden\":1}")
|
||||||
{
|
reply = Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1}")
|
||||||
reply := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1}")
|
Check(StartsWith(reply[5:], ExpectedMask(2, 3, expected[:])), "hidden row mask crosses the service boundary")
|
||||||
Check(StartsWith(reply[5:], ExpectedMask(2, 3, expected[:])), "hidden row mask crosses the service boundary")
|
|
||||||
}
|
|
||||||
unused Good("{\"op\":\"set-rows-hidden\",\"id\":1,\"row\":2,\"last\":3,\"hidden\":0}")
|
unused Good("{\"op\":\"set-rows-hidden\",\"id\":1,\"row\":2,\"last\":3,\"hidden\":0}")
|
||||||
{
|
reply = Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1}")
|
||||||
reply := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1}")
|
Check(StartsWith(reply[5:], ExpectedMask(-1, -1, expected[:])), "rows can be shown again")
|
||||||
Check(StartsWith(reply[5:], ExpectedMask(-1, -1, expected[:])), "rows can be shown again")
|
|
||||||
}
|
|
||||||
unused Good("{\"op\":\"clone\",\"id\":1}")
|
unused Good("{\"op\":\"clone\",\"id\":1}")
|
||||||
unused Good("{\"op\":\"set\",\"id\":2,\"text\":\"99\"}")
|
unused Good("{\"op\":\"set\",\"id\":2,\"text\":\"99\"}")
|
||||||
unused Good("{\"op\":\"save\",\"id\":1,\"name\":\"test.gnumeric\"}")
|
unused Good("{\"op\":\"save\",\"id\":1,\"name\":\"test.gnumeric\"}")
|
||||||
Check(Contains(Service.Call(*context, *files, "{\"op\":\"save\",\"id\":1,\"name\":\"../escape.gnumeric\"}"), "\"ok\":false"), "reject a parent path")
|
Check(Contains(Service.Call(*context, *files, "{\"op\":\"save\",\"id\":1,\"name\":\"../escape.gnumeric\"}"), "\"ok\":false"), "reject a parent path")
|
||||||
unused Good("{\"op\":\"new\"}")
|
unused Good("{\"op\":\"new\"}")
|
||||||
unused Good("{\"op\":\"load\",\"id\":3,\"name\":\"test.gnumeric\"}")
|
unused Good("{\"op\":\"load\",\"id\":3,\"name\":\"test.gnumeric\"}")
|
||||||
{
|
loaded := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3}")
|
||||||
loaded := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3}")
|
Check(Contains(loaded, "=A1*224"), "native document save and reload")
|
||||||
Check(Contains(loaded, "=A1*224"), "native document save and reload")
|
Check(!Contains(loaded, "99"), "cloned edits do not change the original")
|
||||||
Check(!Contains(loaded, "99"), "cloned edits do not change the original")
|
|
||||||
}
|
|
||||||
Check(Contains(Service.Call(*other, *other_files, "{\"op\":\"info\",\"id\":1}"), "\"ok\":false"), "IDs are local to their app")
|
Check(Contains(Service.Call(*other, *other_files, "{\"op\":\"info\",\"id\":1}"), "\"ok\":false"), "IDs are local to their app")
|
||||||
unused Service.Call(*context, *files, "{\"op\":\"load\",\"id\":3,\"name\":\"missing.gnumeric\"}")
|
unused Service.Call(*context, *files, "{\"op\":\"load\",\"id\":3,\"name\":\"missing.gnumeric\"}")
|
||||||
Check(files.status == 0, "missing document status is distinct")
|
Check(files.status == 0, "missing document status is distinct")
|
||||||
{
|
loaded = Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3}")
|
||||||
loaded := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3}")
|
Check(Contains(loaded, "=A1*224"), "failed load preserves the open document")
|
||||||
Check(Contains(loaded, "=A1*224"), "failed load preserves the open document")
|
|
||||||
}
|
|
||||||
Check(Files.AppFileWrite(*files, "invalid.gnumeric", "not a spreadsheet"), "write invalid fixture")
|
Check(Files.AppFileWrite(*files, "invalid.gnumeric", "not a spreadsheet"), "write invalid fixture")
|
||||||
Check(Contains(Service.Call(*context, *files, "{\"op\":\"load\",\"id\":3,\"name\":\"invalid.gnumeric\"}"), "\"ok\":false"), "invalid document rejected")
|
Check(Contains(Service.Call(*context, *files, "{\"op\":\"load\",\"id\":3,\"name\":\"invalid.gnumeric\"}"), "\"ok\":false"), "invalid document rejected")
|
||||||
{
|
loaded = Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3}")
|
||||||
loaded := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3}")
|
Check(Contains(loaded, "=A1*224"), "invalid import preserves cells")
|
||||||
Check(Contains(loaded, "=A1*224"), "invalid import preserves cells")
|
|
||||||
}
|
|
||||||
unused Good("{\"op\":\"add-sheet\",\"id\":1,\"text\":\"Second\"}")
|
unused Good("{\"op\":\"add-sheet\",\"id\":1,\"text\":\"Second\"}")
|
||||||
unused Good("{\"op\":\"set\",\"id\":1,\"sheet\":1,\"text\":\"=SUM(Sheet1!A1:B1)\"}")
|
unused Good("{\"op\":\"set\",\"id\":1,\"sheet\":1,\"text\":\"=SUM(Sheet1!A1:B1)\"}")
|
||||||
unused Good("{\"op\":\"evaluate\",\"id\":1}")
|
unused Good("{\"op\":\"evaluate\",\"id\":1}")
|
||||||
@@ -106,18 +94,14 @@ main :: () -> s32 {
|
|||||||
unused Good(TextUntilNul(request[:]))
|
unused Good(TextUntilNul(request[:]))
|
||||||
SetText(request[:], "{\"op\":\"set-rows-hidden\",\"id\":1,\"sheet\":2,\"row\":0,\"last\":98,\"hidden\":1}")
|
SetText(request[:], "{\"op\":\"set-rows-hidden\",\"id\":1,\"sheet\":2,\"row\":0,\"last\":98,\"hidden\":1}")
|
||||||
unused Good(TextUntilNul(request[:]))
|
unused Good(TextUntilNul(request[:]))
|
||||||
{
|
reply = Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1,\"sheet\":2,\"row\":96}")
|
||||||
reply := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":1,\"sheet\":2,\"row\":96}")
|
Check(StartsWith(reply[5:], ExpectedMask(0, 2, expected[:])), "hidden state follows view paging")
|
||||||
Check(StartsWith(reply[5:], ExpectedMask(0, 2, expected[:])), "hidden state follows view paging")
|
Check(Subtotal10(reply), "hidden rows are excluded from a 109-row sum")
|
||||||
Check(Subtotal10(reply), "hidden rows are excluded from a 109-row sum")
|
|
||||||
}
|
|
||||||
unused Good("{\"op\":\"save\",\"id\":1,\"name\":\"hidden.gnumeric\"}")
|
unused Good("{\"op\":\"save\",\"id\":1,\"name\":\"hidden.gnumeric\"}")
|
||||||
unused Good("{\"op\":\"load\",\"id\":3,\"name\":\"hidden.gnumeric\"}")
|
unused Good("{\"op\":\"load\",\"id\":3,\"name\":\"hidden.gnumeric\"}")
|
||||||
{
|
reply = Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3,\"sheet\":2,\"row\":96}")
|
||||||
reply := Service.Call(*context, *files, "{\"op\":\"view\",\"id\":3,\"sheet\":2,\"row\":96}")
|
Check(StartsWith(reply[5:], ExpectedMask(0, 2, expected[:])), "hidden rows survive save and load")
|
||||||
Check(StartsWith(reply[5:], ExpectedMask(0, 2, expected[:])), "hidden rows survive save and load")
|
Check(Subtotal10(reply), "hidden-row totals survive save and load")
|
||||||
Check(Subtotal10(reply), "hidden-row totals survive save and load")
|
|
||||||
}
|
|
||||||
Say("spreadsheet service: calculation, clone, save/reload, failed imports and private paths passed")
|
Say("spreadsheet service: calculation, clone, save/reload, failed imports and private paths passed")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// Workbook uses Ziran and its native TSX frontend: no Kry source, no JavaScript
|
// Workbook is authored in Ziran: no Kry source, no code in another language
|
||||||
// runtime, no C/Go/Python/shell sources, no vendored runtime, and no SSH package
|
// (C, Go, Python, shell, JavaScript), no vendored runtime, and no SSH package
|
||||||
// URL may come back. Run it from the repository root.
|
// URL may come back. Run it from the repository root.
|
||||||
#load "test_support.zi";
|
#load "test_support.zi";
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ RequiredFile :: (index: s32) -> string {
|
|||||||
// A file that names a retired format or code in another language.
|
// A file that names a retired format or code in another language.
|
||||||
ForbiddenFile :: (name: string) -> bool {
|
ForbiddenFile :: (name: string) -> bool {
|
||||||
return EndsWith(name, ".kry") || EndsWith(name, ".krb") || EndsWith(name, ".kir") ||
|
return EndsWith(name, ".kry") || EndsWith(name, ".krb") || EndsWith(name, ".kir") ||
|
||||||
EndsWith(name, ".c") || EndsWith(name, ".h") || EndsWith(name, ".go") ||
|
EndsWith(name, ".c") || EndsWith(name, ".h") || EndsWith(name, ".go") ||
|
||||||
EndsWith(name, ".py") || EndsWith(name, ".sh") || EndsWith(name, ".bash") ||
|
EndsWith(name, ".py") || EndsWith(name, ".sh") || EndsWith(name, ".bash") ||
|
||||||
EndsWith(name, ".js") || EndsWith(name, ".mjs") || EndsWith(name, ".ts")
|
EndsWith(name, ".js") || EndsWith(name, ".mjs") || EndsWith(name, ".ts")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reports every forbidden file under path and returns how many it found.
|
// Reports every forbidden file under path and returns how many it found.
|
||||||
@@ -76,7 +76,7 @@ CheckPackageUrls :: () -> s32 {
|
|||||||
value: s32 = equals + 1
|
value: s32 = equals + 1
|
||||||
while value < cast(s32)rest.count && rest[value] == 32 { value += 1 }
|
while value < cast(s32)rest.count && rest[value] == 32 { value += 1 }
|
||||||
if equals < cast(s32)rest.count &&
|
if equals < cast(s32)rest.count &&
|
||||||
!StartsWith(rest[value:cast(s32)rest.count], "\"https://") {
|
!StartsWith(rest[value:cast(s32)rest.count], "\"https://") {
|
||||||
WriteText(2, "package URL must be public HTTPS: ")
|
WriteText(2, "package URL must be public HTTPS: ")
|
||||||
WriteText(2, line)
|
WriteText(2, line)
|
||||||
WriteText(2, "\n")
|
WriteText(2, "\n")
|
||||||
@@ -93,7 +93,7 @@ main :: () -> s32 {
|
|||||||
failures: s32 = 0
|
failures: s32 = 0
|
||||||
failures += Walk(".", true)
|
failures += Walk(".", true)
|
||||||
if failures > 0 {
|
if failures > 0 {
|
||||||
WriteText(2, "code in another language or legacy Kry source remains; Workbook uses Ziran (.zi and native .tsx)\n")
|
WriteText(2, "code in another language or legacy Kry source remains; Workbook is Ziran (.zi)\n")
|
||||||
}
|
}
|
||||||
if PathExists(".gitmodules") || PathExists("vendor") {
|
if PathExists(".gitmodules") || PathExists("vendor") {
|
||||||
WriteText(2, "dependencies are Ziran packages in ziran.toml, not submodules or vendor/\n")
|
WriteText(2, "dependencies are Ziran packages in ziran.toml, not submodules or vendor/\n")
|
||||||
|
|||||||
+134
-98
@@ -1,139 +1,175 @@
|
|||||||
{
|
{
|
||||||
"format": 1,
|
"format": 1,
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
|
||||||
"commit": "b141d9c45db236335351c8a4b2a14b3ade27c937",
|
|
||||||
"dependencies": {},
|
|
||||||
"id": "src_aomedia_googlesource_com_aom_b141d9c45db2",
|
|
||||||
"name": "libaom",
|
|
||||||
"ref": "b141d9c45db236335351c8a4b2a14b3ade27c937",
|
|
||||||
"source": true,
|
|
||||||
"url": "https://aomedia.googlesource.com/aom"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "1aadfad932c98c069a1204261b1856f81f3bc199",
|
|
||||||
"dependencies": {},
|
|
||||||
"id": "src_github_com_AOMediaCodec_libavif_1aadfad932c9",
|
|
||||||
"name": "libavif",
|
|
||||||
"ref": "1aadfad932c98c069a1204261b1856f81f3bc199",
|
|
||||||
"source": true,
|
|
||||||
"url": "https://github.com/AOMediaCodec/libavif.git"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "829a65d769d935c4852f8159e964312c0957260a",
|
|
||||||
"dependencies": {},
|
|
||||||
"id": "src_github_com_libsdl_org_SDL_829a65d769d9",
|
|
||||||
"name": "sdl3",
|
|
||||||
"ref": "829a65d769d935c4852f8159e964312c0957260a",
|
|
||||||
"source": true,
|
|
||||||
"url": "https://github.com/libsdl-org/SDL.git"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"commit": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
|
"commit": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"id": "src_github_com_libsndfile_libsamplerate_c96f5e3de9c4",
|
"id": "p0dd67588478f9a3e",
|
||||||
"name": "libsamplerate",
|
"name": "libsamplerate",
|
||||||
"ref": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
|
"ref": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
|
||||||
"source": true,
|
"source": true,
|
||||||
"url": "https://github.com/libsndfile/libsamplerate.git"
|
"url": "https://github.com/libsndfile/libsamplerate.git"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"commit": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
|
"commit": "829a65d769d935c4852f8159e964312c0957260a",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"id": "src_github_com_videolan_dav1d_54706fc6bc0c",
|
"id": "p16cd0434af3dff7b",
|
||||||
"name": "dav1d",
|
"name": "sdl3",
|
||||||
"ref": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
|
"ref": "829a65d769d935c4852f8159e964312c0957260a",
|
||||||
"source": true,
|
"source": true,
|
||||||
"url": "https://github.com/videolan/dav1d.git"
|
"url": "https://github.com/libsdl-org/SDL.git"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"commit": "1844042d1ca751e62e61df7617dba19c98588339",
|
"commit": "1844042d1ca751e62e61df7617dba19c98588339",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"id": "src_github_com_webmproject_libwebp_1844042d1ca7",
|
"id": "p3b3c785a0e17e605",
|
||||||
"name": "libwebp",
|
"name": "libwebp",
|
||||||
"ref": "1844042d1ca751e62e61df7617dba19c98588339",
|
"ref": "1844042d1ca751e62e61df7617dba19c98588339",
|
||||||
"source": true,
|
"source": true,
|
||||||
"url": "https://github.com/webmproject/libwebp.git"
|
"url": "https://github.com/webmproject/libwebp.git"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"commit": "af027a528c6e42b44b68fdaa90b13a7c1136d161",
|
||||||
|
"dependencies": {"audio": "pd258d453b63edc1f", "avif": "p872d871f84f2284f", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db", "libwebp": "p3b3c785a0e17e605", "raylib": "pcc7aa76725f2fb2f", "sdl3": "p16cd0434af3dff7b", "webp": "pa068bd09450b2a80"},
|
||||||
|
"dependency_refs": {"audio": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b", "avif": "f84c162594e518cb306bfd0ce41783ad55b6c730", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339", "raylib": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", "sdl3": "829a65d769d935c4852f8159e964312c0957260a", "webp": "02145a00a1f0df2a111da04a75f3fef260883897"},
|
||||||
|
"id": "p3cf597cf815203c0",
|
||||||
|
"name": "kryon",
|
||||||
|
"ref": "af027a528c6e42b44b68fdaa90b13a7c1136d161",
|
||||||
|
"url": "https://github.com/kryonlabs/kryon.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "60692b80dce3b32e2de1057c39a4793b500419b6",
|
||||||
|
"dependencies": {"kryon": "p5d654550c4218378"},
|
||||||
|
"dependency_refs": {"kryon": "master"},
|
||||||
|
"id": "p533f113d2c39777d",
|
||||||
|
"name": "Css",
|
||||||
|
"ref": "60692b80dce3b32e2de1057c39a4793b500419b6",
|
||||||
|
"url": "https://github.com/kryonlabs/css.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "1aadfad932c98c069a1204261b1856f81f3bc199",
|
||||||
|
"dependencies": {},
|
||||||
|
"id": "p57c0272208aae8db",
|
||||||
|
"name": "libavif",
|
||||||
|
"ref": "1aadfad932c98c069a1204261b1856f81f3bc199",
|
||||||
|
"source": true,
|
||||||
|
"url": "https://github.com/AOMediaCodec/libavif.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "b9aed7589e9af2935a9cd9cb260e72944c195762",
|
||||||
|
"dependencies": {"audio": "pd258d453b63edc1f", "avif": "pfcfd889420218f37", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db", "libwebp": "p3b3c785a0e17e605", "raylib": "pcc7aa76725f2fb2f", "sdl3": "p16cd0434af3dff7b", "webp": "pa068bd09450b2a80"},
|
||||||
|
"dependency_refs": {"audio": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b", "avif": "2f349f8c4a46c7476c6c02b87ec570e66d3a8f34", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339", "raylib": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", "sdl3": "829a65d769d935c4852f8159e964312c0957260a", "webp": "02145a00a1f0df2a111da04a75f3fef260883897"},
|
||||||
|
"id": "p5d654550c4218378",
|
||||||
|
"name": "kryon",
|
||||||
|
"ref": "master",
|
||||||
|
"url": "https://github.com/kryonlabs/kryon.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "bd278217e2bac754d868b3d6502eac4257658d4b",
|
||||||
|
"dependencies": {"dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa"},
|
||||||
|
"dependency_refs": {"dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937"},
|
||||||
|
"id": "p5d7d12505a42f7b3",
|
||||||
|
"name": "av1",
|
||||||
|
"ref": "bd278217e2bac754d868b3d6502eac4257658d4b",
|
||||||
|
"url": "https://github.com/ziranlang/av1.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "360553150917f352e49e1beb78917370792ccaef",
|
||||||
|
"dependencies": {},
|
||||||
|
"id": "p69c0e968ae5735d9",
|
||||||
|
"name": "image-codec",
|
||||||
|
"ref": "360553150917f352e49e1beb78917370792ccaef",
|
||||||
|
"url": "https://github.com/ziranlang/image-codec.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "b141d9c45db236335351c8a4b2a14b3ade27c937",
|
||||||
|
"dependencies": {},
|
||||||
|
"id": "p74ab3cb6eb3b86fa",
|
||||||
|
"name": "libaom",
|
||||||
|
"ref": "b141d9c45db236335351c8a4b2a14b3ade27c937",
|
||||||
|
"source": true,
|
||||||
|
"url": "https://aomedia.googlesource.com/aom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "f84c162594e518cb306bfd0ce41783ad55b6c730",
|
||||||
|
"dependencies": {"av1": "p5d7d12505a42f7b3", "dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db"},
|
||||||
|
"dependency_refs": {"av1": "bd278217e2bac754d868b3d6502eac4257658d4b", "dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199"},
|
||||||
|
"id": "p872d871f84f2284f",
|
||||||
|
"name": "avif",
|
||||||
|
"ref": "f84c162594e518cb306bfd0ce41783ad55b6c730",
|
||||||
|
"url": "https://github.com/ziranlang/avif.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "02145a00a1f0df2a111da04a75f3fef260883897",
|
||||||
|
"dependencies": {"image_codec": "p69c0e968ae5735d9", "libwebp": "p3b3c785a0e17e605"},
|
||||||
|
"dependency_refs": {"image_codec": "360553150917f352e49e1beb78917370792ccaef", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339"},
|
||||||
|
"id": "pa068bd09450b2a80",
|
||||||
|
"name": "webp",
|
||||||
|
"ref": "02145a00a1f0df2a111da04a75f3fef260883897",
|
||||||
|
"url": "https://github.com/ziranlang/webp.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
|
||||||
|
"dependencies": {},
|
||||||
|
"id": "pb24767b9eb34d961",
|
||||||
|
"name": "dav1d",
|
||||||
|
"ref": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
|
||||||
|
"source": true,
|
||||||
|
"url": "https://github.com/videolan/dav1d.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
|
||||||
|
"dependencies": {},
|
||||||
|
"id": "pcc7aa76725f2fb2f",
|
||||||
|
"name": "raylib",
|
||||||
|
"ref": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
|
||||||
|
"source": true,
|
||||||
|
"url": "https://github.com/raysan5/raylib.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b",
|
||||||
|
"dependencies": {"libopus": "pe1fe9bbe80bf1d6d", "libsamplerate": "p0dd67588478f9a3e"},
|
||||||
|
"dependency_refs": {"libopus": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6", "libsamplerate": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7"},
|
||||||
|
"id": "pd258d453b63edc1f",
|
||||||
|
"name": "audio",
|
||||||
|
"ref": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b",
|
||||||
|
"url": "https://github.com/ziranlang/audio.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"commit": "9cc6872f75447c3a24c16764f9829d0f58751cb0",
|
||||||
|
"dependencies": {},
|
||||||
|
"id": "pe1027b9d16704793",
|
||||||
|
"name": "mingcute",
|
||||||
|
"ref": "master",
|
||||||
|
"url": "https://github.com/kryonlabs/mingcute.git"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"commit": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
|
"commit": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"id": "src_github_com_xiph_opus_ddbe48383984",
|
"id": "pe1fe9bbe80bf1d6d",
|
||||||
"name": "libopus",
|
"name": "libopus",
|
||||||
"ref": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
|
"ref": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
|
||||||
"source": true,
|
"source": true,
|
||||||
"url": "https://github.com/xiph/opus.git"
|
"url": "https://github.com/xiph/opus.git"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"commit": "81ade4bb49db8cc2b02a48b437b7db1db09b895e",
|
"commit": "2f349f8c4a46c7476c6c02b87ec570e66d3a8f34",
|
||||||
"dependencies": {"audio": "waozi_xyz_ziranlang_audio_b5c6b56b7117", "avif": "waozi_xyz_ziranlang_avif_6ff696d436b6", "image_codec": "waozi_xyz_ziranlang_image_codec_3017f0d1cc56", "libaom": "src_aomedia_googlesource_com_aom_b141d9c45db2", "libavif": "src_github_com_AOMediaCodec_libavif_1aadfad932c9", "libwebp": "src_github_com_webmproject_libwebp_1844042d1ca7", "sdl3": "src_github_com_libsdl_org_SDL_829a65d769d9", "webp": "waozi_xyz_ziranlang_webp_4b9a61d32460"},
|
"dependencies": {"av1": "p5d7d12505a42f7b3", "dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db"},
|
||||||
"dependency_refs": {"audio": "b5c6b56b71172c4361ae01e3afdd2118bdac0975", "avif": "6ff696d436b6b4f142eb1e3ecf210de7adfa048f", "image_codec": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339", "sdl3": "829a65d769d935c4852f8159e964312c0957260a", "webp": "4b9a61d32460d481624fe0f83996a7de50327dfe"},
|
"dependency_refs": {"av1": "bd278217e2bac754d868b3d6502eac4257658d4b", "dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199"},
|
||||||
"id": "waozi_xyz_kryonlabs_kryon_81ade4bb49db",
|
"id": "pfcfd889420218f37",
|
||||||
"name": "kryon",
|
|
||||||
"ref": "81ade4bb49db8cc2b02a48b437b7db1db09b895e",
|
|
||||||
"url": "https://git.waozi.xyz/kryonlabs/kryon.git"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "9cc6872f75447c3a24c16764f9829d0f58751cb0",
|
|
||||||
"dependencies": {},
|
|
||||||
"id": "waozi_xyz_kryonlabs_mingcute_9cc6872f7544",
|
|
||||||
"name": "mingcute",
|
|
||||||
"ref": "9cc6872f75447c3a24c16764f9829d0f58751cb0",
|
|
||||||
"url": "https://git.waozi.xyz/kryonlabs/mingcute.git"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "b5c6b56b71172c4361ae01e3afdd2118bdac0975",
|
|
||||||
"dependencies": {"libopus": "src_github_com_xiph_opus_ddbe48383984", "libsamplerate": "src_github_com_libsndfile_libsamplerate_c96f5e3de9c4"},
|
|
||||||
"dependency_refs": {"libopus": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6", "libsamplerate": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7"},
|
|
||||||
"id": "waozi_xyz_ziranlang_audio_b5c6b56b7117",
|
|
||||||
"name": "audio",
|
|
||||||
"ref": "b5c6b56b71172c4361ae01e3afdd2118bdac0975",
|
|
||||||
"url": "https://git.waozi.xyz/ziranlang/audio.git"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "bed54d12dc5a8cf8e6a514b2a49d3592d6cecb65",
|
|
||||||
"dependencies": {"dav1d": "src_github_com_videolan_dav1d_54706fc6bc0c", "image_codec": "waozi_xyz_ziranlang_image_codec_3017f0d1cc56", "libaom": "src_aomedia_googlesource_com_aom_b141d9c45db2"},
|
|
||||||
"dependency_refs": {"dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937"},
|
|
||||||
"id": "waozi_xyz_ziranlang_av1_bed54d12dc5a",
|
|
||||||
"name": "av1",
|
|
||||||
"ref": "bed54d12dc5a8cf8e6a514b2a49d3592d6cecb65",
|
|
||||||
"url": "https://git.waozi.xyz/ziranlang/av1.git"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "6ff696d436b6b4f142eb1e3ecf210de7adfa048f",
|
|
||||||
"dependencies": {"av1": "waozi_xyz_ziranlang_av1_bed54d12dc5a", "dav1d": "src_github_com_videolan_dav1d_54706fc6bc0c", "image_codec": "waozi_xyz_ziranlang_image_codec_3017f0d1cc56", "libaom": "src_aomedia_googlesource_com_aom_b141d9c45db2", "libavif": "src_github_com_AOMediaCodec_libavif_1aadfad932c9"},
|
|
||||||
"dependency_refs": {"av1": "bed54d12dc5a8cf8e6a514b2a49d3592d6cecb65", "dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199"},
|
|
||||||
"id": "waozi_xyz_ziranlang_avif_6ff696d436b6",
|
|
||||||
"name": "avif",
|
"name": "avif",
|
||||||
"ref": "6ff696d436b6b4f142eb1e3ecf210de7adfa048f",
|
"ref": "2f349f8c4a46c7476c6c02b87ec570e66d3a8f34",
|
||||||
"url": "https://git.waozi.xyz/ziranlang/avif.git"
|
"url": "https://github.com/ziranlang/avif.git"
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b",
|
|
||||||
"dependencies": {},
|
|
||||||
"id": "waozi_xyz_ziranlang_image_codec_3017f0d1cc56",
|
|
||||||
"name": "image-codec",
|
|
||||||
"ref": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b",
|
|
||||||
"url": "https://git.waozi.xyz/ziranlang/image-codec.git"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"commit": "4b9a61d32460d481624fe0f83996a7de50327dfe",
|
|
||||||
"dependencies": {"image_codec": "waozi_xyz_ziranlang_image_codec_3017f0d1cc56", "libwebp": "src_github_com_webmproject_libwebp_1844042d1ca7"},
|
|
||||||
"dependency_refs": {"image_codec": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339"},
|
|
||||||
"id": "waozi_xyz_ziranlang_webp_4b9a61d32460",
|
|
||||||
"name": "webp",
|
|
||||||
"ref": "4b9a61d32460d481624fe0f83996a7de50327dfe",
|
|
||||||
"url": "https://git.waozi.xyz/ziranlang/webp.git"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"root": {
|
"root": {
|
||||||
"dependencies": {"kryon": "waozi_xyz_kryonlabs_kryon_81ade4bb49db", "mingcute": "waozi_xyz_kryonlabs_mingcute_9cc6872f7544"},
|
"dependencies": {"css": "p533f113d2c39777d", "kryon": "p3cf597cf815203c0", "mingcute": "pe1027b9d16704793"},
|
||||||
"dependency_refs": {"kryon": "81ade4bb49db8cc2b02a48b437b7db1db09b895e", "mingcute": "9cc6872f75447c3a24c16764f9829d0f58751cb0"},
|
"dependency_refs": {"css": "60692b80dce3b32e2de1057c39a4793b500419b6", "kryon": "af027a528c6e42b44b68fdaa90b13a7c1136d161", "mingcute": "master"},
|
||||||
"name": "workbook"
|
"name": "workbook"
|
||||||
},
|
},
|
||||||
"toolchain": {
|
"toolchain": {
|
||||||
"commit": "101b3d2f4e40278cbde18821a097765488bd32d8",
|
"commit": "9524616df1a1b6e63a3789b3aea055714a526c88",
|
||||||
"ref": "101b3d2f4e40278cbde18821a097765488bd32d8",
|
"ref": "master",
|
||||||
"url": "https://git.waozi.xyz/ziranlang/ziran.git"
|
"url": "https://github.com/ziranlang/ziran.git"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-9
@@ -1,21 +1,25 @@
|
|||||||
[package]
|
[package]
|
||||||
tool = "kryon"
|
tool = "kryon"
|
||||||
name = "workbook"
|
name = "workbook"
|
||||||
entry = "src/desktop.tsx"
|
entry = "src/app.zi"
|
||||||
module_roots = ["src", "tests", "previews"]
|
module_roots = ["src", "tests"]
|
||||||
bridge_modules = ["app"]
|
bridge_modules = ["app"]
|
||||||
|
|
||||||
[toolchain]
|
[toolchain]
|
||||||
git = "https://git.waozi.xyz/ziranlang/ziran.git"
|
git = "https://github.com/ziranlang/ziran.git"
|
||||||
ref = "101b3d2f4e40278cbde18821a097765488bd32d8"
|
ref = "master"
|
||||||
|
|
||||||
[dependencies.kryon]
|
[dependencies.kryon]
|
||||||
git = "https://git.waozi.xyz/kryonlabs/kryon.git"
|
git = "https://github.com/kryonlabs/kryon.git"
|
||||||
ref = "81ade4bb49db8cc2b02a48b437b7db1db09b895e"
|
ref = "af027a528c6e42b44b68fdaa90b13a7c1136d161"
|
||||||
|
|
||||||
[dependencies.mingcute]
|
[dependencies.mingcute]
|
||||||
git = "https://git.waozi.xyz/kryonlabs/mingcute.git"
|
git = "https://github.com/kryonlabs/mingcute.git"
|
||||||
ref = "9cc6872f75447c3a24c16764f9829d0f58751cb0"
|
ref = "master"
|
||||||
|
|
||||||
|
[dependencies.css]
|
||||||
|
git = "https://github.com/kryonlabs/css.git"
|
||||||
|
ref = "60692b80dce3b32e2de1057c39a4793b500419b6"
|
||||||
|
|
||||||
[install]
|
[install]
|
||||||
bin = "workbook"
|
bin = "workbook"
|
||||||
@@ -36,4 +40,3 @@ categories = "Office;Spreadsheet;"
|
|||||||
service = "src/service.zi"
|
service = "src/service.zi"
|
||||||
grid = "src/grid.zi"
|
grid = "src/grid.zi"
|
||||||
engine = "src/engine.zi"
|
engine = "src/engine.zi"
|
||||||
editor = "src/editor_api.zi"
|
|
||||||
Reference in new issue
Block a user