Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets for NTK #17

Open
aurium opened this issue Nov 28, 2015 · 6 comments
Open

Widgets for NTK #17

aurium opened this issue Nov 28, 2015 · 6 comments

Comments

@aurium
Copy link

aurium commented Nov 28, 2015

What about depending on Zebra to define interactive window elements and structure? I mean by default, as a feature.

@sidorares
Copy link
Owner

sidorares commented Nov 28, 2015

Interesting. Need to figure out how easy is to use components from Zebra without DOM.
Also canvas is very partially implemented here ntk

@sidorares sidorares changed the title Widigets for NTK Widgets for NTK Dec 11, 2015
@RossComputerGuy
Copy link

I can integrate the widget code from my desktop environment's toolkit.

@sidorares
Copy link
Owner

@SpaceboyRoss01 what toolkit is that?

@RossComputerGuy
Copy link

Well, I finished writing a widget class. I haven't fully written it https://github.com/Ross-Technologies/RDE-Toolkit.

const EventEmitter = require("events");

function isMouseInWidget(w,ev) {
	ev.x -= w.x;
	ev.y -= w.y;
	return (ev.x >= 0 && ev.x < w.width) && (ev.y >= 0 && ev.y < w.height);
}

class Widget extends EventEmitter {
	constructor(window,opts={}) {
		super();
		this.window = window;
		this.widgets = {};
		
		this.width = opts.width || 0;
		this.height = opts.height || 0;
		this.x = opts.x || 0;
		this.y = opts.y || 0;
		this.id = opts.id || null;
		this.active = false;
		
		this.windows.on("keydown",ev => {
			if(this.active) this.emit("keydown",ev);
		});
		
		this.windows.on("keyup",ev => {
			if(this.active) this.emit("keyup",ev);
		});
		
		this.windows.on("mousedown",ev => {
			if(isMouseInWidget(this,ev)) {
				ev.x -= this.x;
				ev.y -= this.y;
				this.emit("mousedown",ev);
			}
		});
		
		this.windows.on("mouseup",ev => {
			if(isMouseInWidget(this,ev)) {
				ev.x -= this.x;
				ev.y -= this.y;
				this.emit("mouseup",ev);
			}
		});
		
		this.windows.on("mousemove",ev => {
			if(isMouseInWidget(this,ev)) {
				ev.x -= this.x;
				ev.y -= this.y;
				this.emit("mousemove",ev);
			}
		});
		
		this.windows.on("mouseover",ev => {
			if(isMouseInWidget(this,ev)) {
				ev.x -= this.x;
				ev.y -= this.y;
				this.emit("mouseover",ev);
			}
		});
		
		this.windows.on("mouseout",ev => {
			if(isMouseInWidget(this,ev)) {
				ev.x -= this.x;
				ev.y -= this.y;
				this.emit("mouseout",ev);
			}
		});
	}
	findWidgetByID(id) {
		for(var wID in this.widgets) {
			if(wID == id) return this.widgets[wID];
		}
	}
	render() {
		// Render this widget before the child widgets
		this.emit("render");
		for(var wID in this.widgets) this.widgets[wID].render();
	}
}
module.exports = Widget;

@RossComputerGuy
Copy link

In a fork I made (https://github.com/Ross-Technologies/ntk) I added widgets.

@sidorares
Copy link
Owner

thanks, I'll have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants