Skip to content

Commit

Permalink
update color default note
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddlingbits committed Mar 26, 2024
1 parent 16e05bb commit cffbf14
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
13 changes: 8 additions & 5 deletions examples/stdio-div/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<!doctype html>
<head>
<title>stdio-div example</title>
</head>
<body>
<div id="twr_iodiv" tabindex="0">Loading... <br></div>

<!-- also see package.json 'alias' -->
<script type="importmap">
Expand All @@ -15,11 +12,17 @@
}
</script>

</head>
<body>
<div id="twr_iodiv" tabindex="0">Loading... <br></div>

<script type="module">
import {twrWasmModuleAsync} from "tiny-wasm-runtime";

let amod;

try {
const amod = new twrWasmModuleAsync({forecolor:"DarkGreen",backcolor:"LightGray", fontsize:12});
amod = new twrWasmModuleAsync({forecolor:"DarkGreen",backcolor:"LightGray", fontsize:18});

document.getElementById("twr_iodiv").innerHTML ="<br>";
document.getElementById("twr_iodiv").addEventListener("keydown",(ev)=>{amod.keyDownDiv(ev)});
Expand All @@ -28,7 +31,7 @@
await amod.executeC(["stdio_div"]);
}
catch(ex) {
console.log("unexpected exception");
amod.divLog("Unexpected Exception.");
throw ex;
}

Expand Down
3 changes: 1 addition & 2 deletions notes-to-self.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
for 1.0?
should i get rid of font default? on a div and canvas you can set a font.
struct IoConsole* twr_wasm_get_windowcon(); should this be renamed - create?
rename struct IoConsole * twr_get_stdio_con(); to twr_wasm style...?
change twrWasmModule to not use 'await' on executeC, malloc, etc calls?
d2d - set default font as current font
D2D ImageData should probably not use mem address as index? Address could get reused.
get source maps working reliably in bundled builds
add source to module, also perhaps this is needed for above
in the npm package add source?
rename executeC?
----

add buffer size to io_gets()
Expand Down
10 changes: 7 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ With an index.html like the following. This time we are using twrWasmModuleAsyn
<title>stdio-div example</title>
</head>
<body>
<div id="twr_iodiv" tabindex="0">Loading... <br></div>
<div id="twr_iodiv" style="background-color:LightGray;color:DarkGreen" tabindex="0">Loading... <br></div>
<script type="module">
import {twrWasmModuleAsync} from "tiny-wasm-runtime";
let amod;
try {
const amod = new twrWasmModuleAsync({forecolor:"DarkGreen",backcolor:"LightGray", fontsize:12});
amod = new twrWasmModuleAsync();
document.getElementById("twr_iodiv").innerHTML ="<br>";
document.getElementById("twr_iodiv").addEventListener("keydown",(ev)=>{amod.keyDownDiv(ev)});
Expand All @@ -182,7 +184,7 @@ With an index.html like the following. This time we are using twrWasmModuleAsyn
await amod.executeC(["stdio_div"]);
}
catch(ex) {
console.log("unexpected exception");
amod.divLog("unexpected exception");
throw ex;
}
Expand Down Expand Up @@ -684,6 +686,8 @@ let amod=new twrWasmModuleAsync({
});
~~~

For an \<div id="twr_iodiv"> it is simpler to set the color and font in the div tag per the normal HTML method. But for \<div id="twr_iocanvas">, that method won't work and you need to use the constructor options for color and fontsize.

These are the options:
~~~
export type TStdioVals="div"|"canvas"|"null"|"debug";
Expand Down
2 changes: 1 addition & 1 deletion source/twr-wasm-ts/twrcanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class twrCanvas implements ICanvas {
this.props.canvasWidth=element.width;
//console.log("this.props.canvasHeight, this.props.canvasWidth",this.props.canvasHeight,this.props.canvasWidth);

// reset after dims changed. Not sure if ctx is needed to rest, but others do
// reset after dims changed. Not sure if ctx is needed to reset, but others do
let c2=element.getContext("2d");
if (!c2) throw new Error("canvas 2D context not found in twrCanvas.constructor (2nd time)");
this.ctx=c2;
Expand Down

0 comments on commit cffbf14

Please sign in to comment.