Skip to content

bug: Cant use Computed on Box position #30

Open
@DNAScanner

Description

Bug description Cant set Box rectangle.column / rectangle.row via Computed

Expected behavior Auto update the Box' position using Signal and Computed

Reproduction Code to reproduce the behavior:

import {crayon} from "https://deno.land/x/crayon@3.3.3/mod.ts";
import {Computed, Signal, Tui, handleInput, handleKeyboardControls, handleMouseControls} from "https://deno.land/x/tui@2.1.1/mod.ts";
import {Box} from "https://deno.land/x/tui@2.1.1/src/components/mod.ts";

const tui = new Tui({
	refreshRate: 1000 / 60, // Run in 60FPS
});

tui.dispatch(); // Close Tui on CTRL+C

handleInput(tui);
handleMouseControls(tui);
handleKeyboardControls(tui);

const x = new Signal(15);
const y = new Signal(15);

const box = new Box({
	parent: tui,
	zIndex: 0,
	theme: {
		base: crayon.bgBlue,
	},
	rectangle: {
		column: new Computed(() => y.value),
		row: new Computed(() => x.value),
		height: 5,
		width: 10,
	},
});

tui.on("keyPress", (event) => {
	switch (event.key) {
		case "w":
		case "up":
			y.value += 1;
			console.log("up");
			break;

		case "s":
		case "down":
			y.value -= 1;
			console.log("down");
			break;

		case "a":
		case "left":
			x.value -= 1;
			console.log("left");
			break;

		case "d":
		case "right":
			y.value += 1;
			console.log("right");
			break;
	}
});

tui.run();

Information (please complete) It seems, that the rectangle.column and rectangle.row, dont currently support Computed properties as their values.

  • OS: Windows_NT DNAScanner 6.2 9200 x86_64 MS/Windows
  • Deno version:

deno 1.36.3 (release, x86_64-pc-windows-msvc)
v8 11.6.189.12
typescript 5.1.6

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions