Skip to content

Commit 7d7bfa4

Browse files
committed
Editor; add simple preview (toggle with cmd/ctrl p) to view layout in the default luxe rendering
1 parent 690030f commit 7d7bfa4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tools/editor/Main.hx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,30 @@ class Main extends luxe.Game {
10021002
trace('\n\n$_str\n\n');
10031003
} //do_save
10041004

1005+
var ui_preview: LoaderItems;
1006+
function recursive_mouse_input(_control:mint.Control, _state:Bool) {
1007+
_control.mouse_input = _state;
1008+
for(_child in _control.children) recursive_mouse_input(_child, _state);
1009+
}
1010+
function do_preview() {
1011+
if(ui_preview != null) {
1012+
for(_item in ui_preview.roots) _item.destroy();
1013+
ui_preview = null;
1014+
} else {
1015+
var _view_w = ui_canvas.w - ui_tools.w;
1016+
var _view_h = ui_canvas.h;
1017+
ui_preview = JSONLoader.parse(ui_canvas, 'preview', export(), 0, 0);
1018+
var _root = ui_preview.roots[0];
1019+
if(_root == null) {
1020+
ui_preview = null;
1021+
return;
1022+
}
1023+
if(_root.w < _view_w) _root.x_local = (_view_w/2)-(_root.w/2);
1024+
if(_root.h < _view_h) _root.y_local = (_view_h/2)-(_root.h/2);
1025+
recursive_mouse_input(_root, true);
1026+
}
1027+
}
1028+
10051029
override function onkeyup(e:luxe.Input.KeyEvent) {
10061030

10071031
if(e.keycode == Key.escape && parenting!=null) {
@@ -1010,6 +1034,10 @@ class Main extends luxe.Game {
10101034
ui_info.text = '...';
10111035
}
10121036

1037+
if(e.keycode == Key.key_p && (e.mod.ctrl || e.mod.meta)) {
1038+
do_preview();
1039+
}
1040+
10131041
if(e.keycode == Key.escape && e.mod.shift) {
10141042
Luxe.shutdown();
10151043
return;

0 commit comments

Comments
 (0)