diff --git a/examples/web/index.ts b/examples/web/index.ts index dc36af2ccd5d4a0329c69de529cb84c047c236b6..7f88a378cb959d69e6b5fc5da16969ef7580ffa8 100644 --- a/examples/web/index.ts +++ b/examples/web/index.ts @@ -81,7 +81,6 @@ class Emulator { private videoBuff: DataView | null = null; private toastTimeout: number | null = null; private paused: boolean = false; - private background_index: number = 0; private nextTickTime: number = 0; private fps: number = 0; private frameStart: number = new Date().getTime(); @@ -666,14 +665,6 @@ class Emulator { } }); - const buttonTheme = document.getElementById("button-theme")!; - buttonTheme.addEventListener("click", () => { - this.background_index = - (this.background_index + 1) % BACKGROUNDS.length; - const background = BACKGROUNDS[this.background_index]; - this.setBackground(background); - }); - const buttonUploadFile = document.getElementById( "button-upload-file" ) as HTMLInputElement; @@ -788,8 +779,6 @@ class Emulator { } async initBase() { - const background = BACKGROUNDS[this.background_index]; - this.setBackground(background); this.setVersion(info.version); } @@ -957,13 +946,6 @@ class Emulator { //Component.get<KeyValue>("diag:framerate").value = `${value} FPS`; } - setBackground(value: string) { - document.body.style.backgroundColor = `#${value}`; - document.getElementById( - "footer-background" - )!.style.backgroundColor = `#${value}f2`; - } - toggleRunning() { if (this.paused) { this.resume(); @@ -1101,7 +1083,7 @@ const wasm = async () => { }; (async () => { - startApp("app"); + startApp("app", BACKGROUNDS); const emulator = new Emulator(); await emulator.main(); diff --git a/examples/web/react/app.css b/examples/web/react/app.css index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..26a7e3d79f7e0f5897a88081f9226b1b3fd3ded1 100644 --- a/examples/web/react/app.css +++ b/examples/web/react/app.css @@ -0,0 +1,5 @@ +.app { + color: #ffffff; + font-family: VT323, Roboto, Open Sans, Arial, Helvetica, sans-serif; + margin: 0px 0px 0px 0px; +} diff --git a/examples/web/react/app.tsx b/examples/web/react/app.tsx index 214d4c25a31112d59be1a64b5f9d6b6ebb288c3e..11f5198d7f13246b2dff565c738fff2bab7ac444 100644 --- a/examples/web/react/app.tsx +++ b/examples/web/react/app.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { FC, useEffect, useState } from "react"; import ReactDOM from "react-dom/client"; import { @@ -17,14 +17,29 @@ import { import "./app.css"; -export const App = () => { +type AppProps = { + backgrounds?: string[]; +}; + +export const App: FC<AppProps> = ({ backgrounds = ["264653"] }) => { const [count, setCount] = useState(0); + const [backgroundIndex, setBackgroundIndex] = useState(0); const getText = () => `Hello World ${count}`; + const getBackground = () => backgrounds[backgroundIndex]; const onClick = () => setCount(count + 1); + const onThemeClick = () => { + setBackgroundIndex((backgroundIndex + 1) % backgrounds.length); + }; + useEffect(() => { + document.body.style.backgroundColor = `#${getBackground()}`; + }); return ( - <> - <Footer> - Built with â¤ï¸ by <a href="https://joao.me" target="_blank">João Magalhães</a> + <div className="app"> + <Footer color={getBackground()}> + Built with â¤ï¸ by{" "} + <a href="https://joao.me" target="_blank"> + João Magalhães + </a> </Footer> <PanelSplit left={<div>This is the left panel</div>}> <Title @@ -75,6 +90,12 @@ export const App = () => { imageAlt="tobias" onClick={onClick} /> + <Button + text={"Theme"} + image={require("../res/marker.svg")} + imageAlt="marker" + onClick={onThemeClick} + /> <Info> <Pair key="tobias" @@ -109,18 +130,18 @@ export const App = () => { </Info> </Section> </PanelSplit> - </> + </div> ); }; -export const startApp = (element: string) => { +export const startApp = (element: string, backgrounds: string[]) => { const elementRef = document.getElementById(element); if (!elementRef) { return; } const root = ReactDOM.createRoot(elementRef); - root.render(<App />); + root.render(<App backgrounds={backgrounds} />); }; export default App; diff --git a/examples/web/react/components/footer/footer.css b/examples/web/react/components/footer/footer.css index 4a6ae541f66ea38b3a19f0eb6d5483dd8552a297..2958e0d4de1d56efae112c0387b8c0142ad47062 100644 --- a/examples/web/react/components/footer/footer.css +++ b/examples/web/react/components/footer/footer.css @@ -1,4 +1,18 @@ -.footer { +.footer > .footer-background { + bottom: 0px; + filter: blur(1.0rem); + -o-filter: blur(1.0rem); + -ms-filter: blur(1.0rem); + -moz-filter: blur(1.0rem); + -khtml-filter: blur(1.0rem); + -webkit-filter: blur(1.0rem); + height: 40px; + left: 0px; + position: fixed; + width: 100%; +} + +.footer > .footer-contents { bottom: 0px; height: 40px; left: 0px; @@ -8,12 +22,3 @@ text-align: center; width: 100%; } - -.footer > .footer-background { - filter: blur(1.0rem); - -o-filter: blur(1.0rem); - -ms-filter: blur(1.0rem); - -moz-filter: blur(1.0rem); - -khtml-filter: blur(1.0rem); - -webkit-filter: blur(1.0rem); -} diff --git a/examples/web/react/components/footer/footer.tsx b/examples/web/react/components/footer/footer.tsx index 66c9369ad2d475c478996e3a15491bc5a8bc0589..e33c01e5fa2a8a0c370e72afc6df13c14b11c172 100644 --- a/examples/web/react/components/footer/footer.tsx +++ b/examples/web/react/components/footer/footer.tsx @@ -1,18 +1,28 @@ -import React, { FC, ReactNode } from "react"; - -import "./footer.css"; - -type FooterProps = { - children: ReactNode; - style?: string[]; -}; - -export const Footer: FC<FooterProps> = ({ children, style = [] }) => { - const classes = () => ["footer", ...style].join(" "); - return <div className={classes()}> - <div className="footer-background"></div> - <div className="footer-contents">{children}</div> - </div> -}; - -export default Footer; +import React, { FC, ReactNode } from "react"; + +import "./footer.css"; + +type FooterProps = { + children: ReactNode; + color?: string; + style?: string[]; +}; + +export const Footer: FC<FooterProps> = ({ + children, + color = "ffffff", + style = [] +}) => { + const classes = () => ["footer", ...style].join(" "); + return ( + <div className={classes()}> + <div + className="footer-background" + style={{ backgroundColor: `#${color}f2` }} + ></div> + <div className="footer-contents">{children}</div> + </div> + ); +}; + +export default Footer;