diff --git a/assets/chrome.png b/assets/chrome.png new file mode 100644 index 0000000..193aa20 Binary files /dev/null and b/assets/chrome.png differ diff --git a/assets/file-image.png b/assets/file-image.png new file mode 100644 index 0000000..8b20c8d Binary files /dev/null and b/assets/file-image.png differ diff --git a/assets/home.png b/assets/home.png new file mode 100644 index 0000000..6d4e49c Binary files /dev/null and b/assets/home.png differ diff --git a/src/ui/desktop.ts b/src/ui/desktop.ts index 1c3d41d..aad5cb7 100644 --- a/src/ui/desktop.ts +++ b/src/ui/desktop.ts @@ -1,6 +1,11 @@ import Component from "./component"; +import DesktopShortcut from "./desktop_shortcut"; +import Window from "./window"; export default class Desktop extends Component { + shortcuts: DesktopShortcut[] = []; + windows: Window[] = []; + constructor() { super(); this.element.id = "desktop"; @@ -8,28 +13,43 @@ export default class Desktop extends Component { this.element.style.width = "100%"; this.element.style.display = "grid"; this.element.style.gap = "10px"; + this.element.style.padding = "10px"; this.element.style.display = "grid"; this.element.style.gridAutoFlow = "column"; this.element.style.gridTemplateColumns = - "repeat(auto-fill, minmax(80px, 1fr))"; + "repeat(auto-fill, minmax(60px, 1fr))"; this.element.style.gridTemplateRows = - "repeat(auto-fill, minmax(80px, 1fr))"; - - for (let i = 0; i < 50; i++) { - const component = new Component(); - component.element.innerText = String(i); - component.element.style.border = "1px solid white"; - } + "repeat(auto-fill, minmax(60px, 1fr))"; } - addApplicationIcon() { - // reaches into the OS and adds an icon to the desktop - // this is a placeholder for now + updateDesktop() { + this.element.replaceChildren(...this.shortcuts.map((e) => e.element)); + } + + addApplicationShortcut(shortcut: DesktopShortcut) { + this.shortcuts.push(shortcut); + this.updateDesktop(); + } + + addOpenedWindow(w: Window) { + this.windows.push(w); + this.element.appendChild(w.start()); + } + + initDesktopShortcuts() { + this.addApplicationShortcut( + new DesktopShortcut("../../assets/home.png", "Home"), + ); + this.addApplicationShortcut( + new DesktopShortcut("../../assets/file-image.png", "img_12131995.png"), + ); + this.addOpenedWindow(new Window()); } start() { + this.initDesktopShortcuts(); return this.element; } } diff --git a/src/ui/desktop_shortcut.ts b/src/ui/desktop_shortcut.ts new file mode 100644 index 0000000..91b165a --- /dev/null +++ b/src/ui/desktop_shortcut.ts @@ -0,0 +1,44 @@ +import Component from "./component"; + +export default class DesktopShortcut extends Component { + icon: string; + title: string; + + constructor(icon: string, title: string) { + super(); + this.icon = icon; + this.title = title; + + this.element.style.borderRadius = "10px"; + this.element.style.cursor = "pointer"; + this.element.style.color = "white"; + this.element.style.justifyContent = "center"; + this.element.style.display = "flex"; + this.element.style.flexDirection = "column"; + this.element.style.alignItems = "center"; + this.element.style.padding = "6px"; + + this.element.addEventListener("mouseover", () => { + this.element.style.border = "1px solid #0000005f"; + }); + + this.element.addEventListener("mouseout", () => { + this.element.style.border = "1px solid #00000000"; + }); + + const _icon = document.createElement("img"); + const _title = document.createElement("p"); + + _icon.src = this.icon; + _icon.style.width = "30px"; + + _title.textContent = this.title; + _title.style.margin = "0"; + _title.style.fontSize = "12px"; + _title.style.marginTop = "4px"; + _title.style.wordWrap = "anywhere"; + + this.addChild(_icon); + this.addChild(_title); + } +} diff --git a/src/ui/index.ts b/src/ui/index.ts index 0682e17..634963a 100644 --- a/src/ui/index.ts +++ b/src/ui/index.ts @@ -36,10 +36,10 @@ export default class UI extends Component { desktop_container.id = "desktop_container"; desktop_container.style.display = "flex"; desktop_container.style.height = `calc(100vh - ${this.topbar.element.clientHeight}px)`; - this.addChild(desktop_container); desktop_container.appendChild(this.navbar.start()); desktop_container.appendChild(this.desktop.start()); + this.addChild(desktop_container); return this.element; } diff --git a/src/ui/window.ts b/src/ui/window.ts index b1010ea..ba64988 100644 --- a/src/ui/window.ts +++ b/src/ui/window.ts @@ -1,14 +1,19 @@ export default class Window { - element: HTMLDialogElement = document.createElement("dialog"); + element: HTMLDivElement = document.createElement("div"); initial_size = { w: 500, h: 500 } as const; constructor() { - this.element.style.backgroundColor = "black"; - this.element.style.width = `${this.initial_size.w}`; - this.element.style.height = `${this.initial_size.h}`; + this.element.style.backgroundColor = "#ccc"; + this.element.style.width = `${this.initial_size.w}px`; + this.element.style.height = `${this.initial_size.h}px`; + this.element.style.position = "absolute"; + this.element.style.zIndex = "10"; + this.element.style.borderRadius = "10px"; + this.element.style.boxShadow = + "0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)"; } - start(): HTMLDialogElement { + start(): HTMLDivElement { return this.element; } }