Switch to rollup for bundling
This commit is contained in:
parent
fc8d282509
commit
cfe9c55c9a
16 changed files with 131 additions and 7 deletions
8
js/gui/button.mjs
Normal file
8
js/gui/button.mjs
Normal file
|
@ -0,0 +1,8 @@
|
|||
import * as gui from './index.mjs';
|
||||
|
||||
export class GuiButton extends gui.GuiElement {
|
||||
constructor(x, y, text, onclick) {
|
||||
let textSize = gui.measureText(text, 'Arial 14pt');
|
||||
super(x, y, ...textSize);
|
||||
}
|
||||
}
|
25
js/gui/element.mjs
Normal file
25
js/gui/element.mjs
Normal file
|
@ -0,0 +1,25 @@
|
|||
const defaultOptions = {
|
||||
draw: true // Whether the element itself will be rendered.
|
||||
}
|
||||
|
||||
export default class GuiElement {
|
||||
constructor(x, y, w, h, options) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.children = new Set();
|
||||
this.parent = null;
|
||||
|
||||
this.options = Object.assign(options, defaultOptions);
|
||||
}
|
||||
|
||||
append(element) {
|
||||
this.children.add(element);
|
||||
element.parent = this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.children.clear();
|
||||
}
|
||||
}
|
8
js/gui/frame.mjs
Normal file
8
js/gui/frame.mjs
Normal file
|
@ -0,0 +1,8 @@
|
|||
import * as gui from './index.mjs';
|
||||
import GuiElement from './element.mjs';
|
||||
|
||||
export default class GuiFrame extends GuiElement {
|
||||
constructor(x, y, w, h, options) {
|
||||
super(x, y, w, h, options);
|
||||
}
|
||||
}
|
17
js/gui/index.mjs
Normal file
17
js/gui/index.mjs
Normal file
|
@ -0,0 +1,17 @@
|
|||
import {context} from '../graphics/index.mjs';
|
||||
import * as modules from './modules.mjs';
|
||||
|
||||
export const elements = new Set();
|
||||
export let root;
|
||||
|
||||
export function init() {
|
||||
elements.clear();
|
||||
root = modules.root();
|
||||
console.log(root);
|
||||
}
|
||||
|
||||
export function measureText(msg, font) {
|
||||
context.font = font;
|
||||
let measurement = context.measureText(msg);
|
||||
return [measurement.width, measurement.height];
|
||||
}
|
11
js/gui/misc.mjs
Normal file
11
js/gui/misc.mjs
Normal file
|
@ -0,0 +1,11 @@
|
|||
import * as gui from './index.mjs';
|
||||
import GuiElement from './element.mjs';
|
||||
|
||||
export class GuiImage extends gui.GuiElement {
|
||||
constructor(src, x, y, w, h) {
|
||||
w = w || src.width;
|
||||
h = h || src.height;
|
||||
super(x, y, w, h);
|
||||
this.image = src;
|
||||
}
|
||||
}
|
13
js/gui/modules.mjs
Normal file
13
js/gui/modules.mjs
Normal file
|
@ -0,0 +1,13 @@
|
|||
import * as gui from './index.mjs';
|
||||
import {canvas} from '../graphics/index.mjs';
|
||||
import GuiFrame from './frame.mjs';
|
||||
|
||||
export function root() {
|
||||
return new GuiFrame(0, 0, canvas.width, canvas.height, {
|
||||
draw: false
|
||||
});
|
||||
}
|
||||
|
||||
export function titleScreen() {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue