Added window draw order
This commit is contained in:
parent
8481da2d51
commit
80f6e8ea80
6 changed files with 20 additions and 6 deletions
|
|
@ -8,6 +8,6 @@ The windows components are used to view and interact with running applications.
|
||||||
|
|
||||||
- [x] Maximize (fullscreen)
|
- [x] Maximize (fullscreen)
|
||||||
- [ ] Minimize
|
- [ ] Minimize
|
||||||
- [x] Resize
|
- [ ] Resize
|
||||||
- [x] Multiple windows of the same app
|
- [x] Multiple windows of the same app
|
||||||
- [ ] Draw order
|
- [x] Draw order
|
||||||
|
|
@ -7,7 +7,7 @@ import { useWindowsManager } from "../../hooks/windows/WindowsManagerContext.js"
|
||||||
import Draggable from "react-draggable";
|
import Draggable from "react-draggable";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
export function Window({ id, app, size, position, focused = false }) {
|
export function Window({ id, app, size, position, focused = false, onInteract }) {
|
||||||
const windowsManager = useWindowsManager();
|
const windowsManager = useWindowsManager();
|
||||||
const nodeRef = useRef(null);
|
const nodeRef = useRef(null);
|
||||||
const [maximized, setMaximized] = useState(false);
|
const [maximized, setMaximized] = useState(false);
|
||||||
|
|
@ -47,6 +47,7 @@ export function Window({ id, app, size, position, focused = false }) {
|
||||||
cancel="button"
|
cancel="button"
|
||||||
nodeRef={nodeRef}
|
nodeRef={nodeRef}
|
||||||
disabled={maximized}
|
disabled={maximized}
|
||||||
|
onMouseDown={onInteract}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={classNames.join(" ")}
|
className={classNames.join(" ")}
|
||||||
|
|
@ -55,6 +56,7 @@ export function Window({ id, app, size, position, focused = false }) {
|
||||||
width: maximized ? screenWidth : size.x,
|
width: maximized ? screenWidth : size.x,
|
||||||
height: maximized ? screenHeight : size.y,
|
height: maximized ? screenHeight : size.y,
|
||||||
}}
|
}}
|
||||||
|
onClick={onInteract}
|
||||||
>
|
>
|
||||||
<div className={`${styles.Header} Handle`}>
|
<div className={`${styles.Header} Handle`}>
|
||||||
<ReactSVG className={styles["Window-icon"]} src={process.env.PUBLIC_URL + `/media/applications/icons/${app.id}.svg`}/>
|
<ReactSVG className={styles["Window-icon"]} src={process.env.PUBLIC_URL + `/media/applications/icons/${app.id}.svg`}/>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
background-color: var(--background-color-c);
|
background-color: var(--background-color-c);
|
||||||
animation: pop-in 200ms ease-in-out;
|
/* animation: pop-in 200ms ease-in-out; */
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes pop-in {
|
@keyframes pop-in {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
import { Window } from "./Window.jsx";
|
import { Window } from "./Window.jsx";
|
||||||
import { useWindows } from "../../hooks/windows/WindowsContext.js";
|
import { useWindows } from "../../hooks/windows/WindowsContext.js";
|
||||||
|
import { useWindowsManager } from "../../hooks/windows/WindowsManagerContext.js";
|
||||||
|
|
||||||
export function WindowsView() {
|
export function WindowsView() {
|
||||||
const windows = useWindows();
|
const windows = useWindows();
|
||||||
|
const windowsManager = useWindowsManager();
|
||||||
|
|
||||||
return (<div>
|
return (<div>
|
||||||
{windows.map(({ id, app, size, position}) =>
|
{windows.sort((windowA, windowB) =>
|
||||||
|
windowA.lastInteraction - windowB.lastInteraction
|
||||||
|
).map(({ id, app, size, position }, index) =>
|
||||||
<Window
|
<Window
|
||||||
|
onInteract={() => { windowsManager.focus(windows[index]); }}
|
||||||
id={id}
|
id={id}
|
||||||
key={id}
|
key={id}
|
||||||
app={app}
|
app={app}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ export default class WindowsManager {
|
||||||
id,
|
id,
|
||||||
app,
|
app,
|
||||||
size,
|
size,
|
||||||
position
|
position,
|
||||||
|
lastInteraction: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
this.updateWindows(this.windows);
|
this.updateWindows(this.windows);
|
||||||
|
|
@ -47,6 +48,11 @@ export default class WindowsManager {
|
||||||
// console.log(this);
|
// console.log(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focus(window) {
|
||||||
|
window.lastInteraction = new Date().valueOf();
|
||||||
|
this.updateWindows(this.windows);
|
||||||
|
}
|
||||||
|
|
||||||
isAppActive(appId) {
|
isAppActive(appId) {
|
||||||
let active = false;
|
let active = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ export function WindowsProvider({ children, windowsManager }) {
|
||||||
const [windows, setWindows] = useState([]);
|
const [windows, setWindows] = useState([]);
|
||||||
|
|
||||||
const updateWindows = useCallback((updatedWindows) => {
|
const updateWindows = useCallback((updatedWindows) => {
|
||||||
|
// console.log(updatedWindows);
|
||||||
setWindows(Object.values(updatedWindows));
|
setWindows(Object.values(updatedWindows));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue