1use serde_json::{json, Value};
10
11use re_render::ui::widgets::{Ui, UiInput};
12use re_render::ui::{DockEdge, FontAtlas, PanelPlacement, Rect, Theme};
13
14use crate::context::EditorContext;
15use crate::layout::{Command, Menu};
16
17const LOG_CAP: usize = 200;
19
20#[derive(Default)]
22pub struct PanelState {
23 pub selected: Option<u32>,
26 pub log: Vec<String>,
28 pub cmdline: String,
30 pub assistant_line: String,
32 pub open_menu: Option<String>,
34 pub tab_pick: Option<String>,
37 pub edits: std::collections::HashMap<String, String>,
39 pub scrub: Option<(String, [f32; 2])>,
42 pub popup: Option<Rect>,
44 pub drag_panel: Option<String>,
46 pub drag_ended: bool,
48 pub drop: Option<(String, DockEdge)>,
50}
51
52impl PanelState {
53 pub fn log(&mut self, line: impl Into<String>) {
55 self.log.push(line.into());
56 if self.log.len() > LOG_CAP {
57 self.log.remove(0);
58 }
59 }
60}
61
62pub fn run_command(ctx: &EditorContext, st: &mut PanelState, cmd: &Command) {
65 if cmd.capability.is_empty() {
66 return;
67 }
68 let args = if cmd.args.is_null() {
69 json!({})
70 } else {
71 cmd.args.clone()
72 };
73 match ctx.call(&cmd.capability, args.clone()) {
74 Ok(v) => st.log(format!("{} → {}", cmd.capability, summarize(&v))),
75 Err(e) => st.log(format!("{} FEHLER: {e}", cmd.capability)),
76 }
77}
78
79fn summarize(v: &Value) -> String {
81 let s = match v {
82 Value::String(s) => s.clone(),
83 other => other.to_string(),
84 };
85 if s.chars().count() > 120 {
86 let cut: String = s.chars().take(117).collect();
87 format!("{cut}…")
88 } else {
89 s
90 }
91}
92
93fn menu_width(atlas: &FontAtlas, text: &str, pad: f32) -> f32 {
97 atlas.measure(0, text, 0.0)[0].ceil() + pad * 2.0
98}
99
100pub fn menu_bar_layout(
105 menus: &[Menu],
106 atlas: &FontAtlas,
107 area: Rect,
108 pad: f32,
109 theme: &Theme,
110) -> Vec<(String, Rect)> {
111 let mut x = area.x + pad;
112 menus
113 .iter()
114 .map(|m| {
115 let w = menu_width(atlas, theme.label(&m.id), pad);
116 let r = Rect::new(x, area.y, w, area.h);
117 x += w + pad;
118 (m.id.clone(), r)
119 })
120 .collect()
121}
122
123pub fn draw_menu_bar(
126 ui: &mut Ui,
127 area: Rect,
128 menus: &[Menu],
129 theme: &Theme,
130 atlas: &FontAtlas,
131 st: &mut PanelState,
132) {
133 ui.draw.rect(area, theme.colors.header);
134 let slots = menu_bar_layout(menus, atlas, area, theme.metrics.pad, theme);
135 for (id, r) in slots {
136 let open = st.open_menu.as_deref() == Some(id.as_str());
137 let label = theme.label(&id).to_string();
138 if ui.button(&format!("menubar/{id}"), r, &label) {
139 st.open_menu = if open { None } else { Some(id.clone()) };
140 }
141 }
142}
143
144pub fn draw_menu_popup(
148 ui: &mut Ui,
149 menus: &[Menu],
150 theme: &Theme,
151 atlas: &FontAtlas,
152 bar: Rect,
153 ctx: &EditorContext,
154 st: &mut PanelState,
155) {
156 let Some(open_id) = st.open_menu.clone() else {
157 st.popup = None;
158 return;
159 };
160 let Some(menu) = menus.iter().find(|m| m.id == open_id) else {
161 st.popup = None;
162 return;
163 };
164 let slots = menu_bar_layout(menus, atlas, bar, theme.metrics.pad, theme);
165 let Some(a) = slots.iter().find(|(id, _)| *id == open_id).map(|(_, r)| *r) else {
166 st.popup = None;
167 return;
168 };
169
170 let row = theme.metrics.row_h;
171 let w = {
172 let widest = menu
173 .items
174 .iter()
175 .filter(|i| !i.separator)
176 .map(|i| atlas.measure(0, theme.label(&i.id), 0.0)[0])
177 .fold(0.0f32, f32::max);
178 (widest.ceil() + theme.metrics.pad * 4.0).max(160.0)
179 };
180 let h = menu.items.len() as f32 * row + 2.0;
181 let pop = Rect::new(a.x, bar.bottom(), w, h);
182 st.popup = Some(pop);
183
184 ui.draw.rect(pop, theme.colors.panel);
185 ui.draw.stroke(pop, 1.0, theme.colors.border);
186 let mut y = pop.y + 1.0;
187 let mut fired: Option<Command> = None;
188 for (i, item) in menu.items.iter().enumerate() {
189 let r = Rect::new(pop.x + 1.0, y, pop.w - 2.0, row);
190 if item.separator {
191 ui.separator(r);
192 } else {
193 let label = theme.label(&item.id).to_string();
194 if ui.selectable(&format!("menu/{open_id}/{i}"), r, &label, false) {
195 fired = Some(item.clone());
196 }
197 }
198 y += row;
199 }
200 if let Some(cmd) = fired {
201 run_command(ctx, st, &cmd);
202 st.open_menu = None;
203 st.popup = None;
204 }
205}
206
207pub fn draw_toolbar(
209 ui: &mut Ui,
210 area: Rect,
211 toolbar: &[Command],
212 theme: &Theme,
213 atlas: &FontAtlas,
214 ctx: &EditorContext,
215 st: &mut PanelState,
216) {
217 ui.draw.rect(area, theme.colors.panel);
218 let pad = theme.metrics.pad;
219 let mut x = area.x + pad;
220 for (i, cmd) in toolbar.iter().enumerate() {
221 let label = theme.label(&cmd.id).to_string();
222 let w = atlas.measure(0, &label, 0.0)[0].ceil() + pad * 2.0;
223 let r = Rect::new(x, area.y + 2.0, w, (area.h - 4.0).max(1.0));
224 if ui.button(&format!("toolbar/{i}/{}", cmd.capability), r, &label) {
225 run_command(ctx, st, cmd);
226 }
227 x += w + pad * 0.5;
228 }
229}
230
231pub fn draw_status_bar(
233 ui: &mut Ui,
234 area: Rect,
235 theme: &Theme,
236 atlas: &FontAtlas,
237 ctx: &EditorContext,
238 st: &PanelState,
239) {
240 ui.draw.rect(area, theme.colors.header);
241 let p = theme.metrics.pad;
242 let line_h = atlas.measure(0, "Ag", 0.0)[1];
243 let ty = area.y + ((area.h - line_h) * 0.5).max(0.0);
244 ui.draw.text(
245 atlas,
246 0,
247 theme.label("status.hint"),
248 area.x + p,
249 ty,
250 line_h,
251 theme.colors.text_dim,
252 );
253 let info = ctx.call("project.info", json!({})).unwrap_or(Value::Null);
255 let mut right = String::new();
256 if let Some(name) = info.get("name").and_then(|v| v.as_str()) {
257 if !name.is_empty() {
258 right.push_str(name);
259 if info.get("dirty").and_then(|v| v.as_bool()).unwrap_or(false) {
260 right.push_str(" •");
261 }
262 }
263 }
264 if let Some(sel) = st.selected {
265 right.push_str(&format!(" sel:#{sel}"));
266 }
267 if !right.is_empty() {
268 let w = atlas.measure(0, &right, 0.0)[0];
269 ui.draw.text(
270 atlas,
271 0,
272 &right,
273 (area.right() - w - p).max(area.x),
274 ty,
275 line_h,
276 theme.colors.text,
277 );
278 }
279}
280
281fn panel_frame(
286 ui: &mut Ui,
287 pl: &PanelPlacement,
288 theme: &Theme,
289 atlas: &FontAtlas,
290 st: &mut PanelState,
291) -> Rect {
292 let r = pl.rect;
293 ui.draw.rect(r, theme.colors.panel);
294 ui.draw.stroke(r, 1.0, theme.colors.border);
295 let title = theme.label(&format!("panel.{}", pl.panel)).to_string();
296 let th = theme.metrics.row_h;
297 let head = Rect::new(r.x, r.y, r.w, th);
298 ui.draw.rect(head, theme.colors.header);
299 let line_h = atlas.measure(0, "Ag", 0.0)[1];
300 ui.draw.text(
301 atlas,
302 1,
303 &title,
304 r.x + theme.metrics.pad,
305 head.y + ((head.h - line_h) * 0.5).max(0.0),
306 line_h,
307 theme.colors.text,
308 );
309 for (id, tr) in &pl.tabs {
313 let label = theme.label(&format!("panel.{id}")).to_string();
314 let active = id == &pl.panel;
315 let (clicked, d) = ui.tab_drag(&format!("tab/{id}"), *tr, &label, active, 6.0);
316 if clicked {
317 st.tab_pick = Some(id.clone());
318 }
319 if d.claimed && d.moved && st.drag_panel.is_none() {
320 st.drag_panel = Some(id.clone());
321 }
322 if st.drag_panel.as_deref() == Some(id.as_str()) {
323 st.drag_ended = d.ended;
324 }
325 }
326 Rect::new(r.x, r.y + th, r.w, (r.h - th).max(0.0))
327}
328
329pub fn drop_zones(placements: &[PanelPlacement], dragging: &str) -> Vec<(Rect, String, DockEdge)> {
335 let mut out = Vec::new();
336 for pl in placements {
337 if pl.panel == dragging {
338 continue;
339 }
340 let r = pl.rect;
341 let d = (r.w.min(r.h) * 0.28).clamp(24.0, 140.0);
342 let bands = [
343 (Rect::new(r.x, r.y, d, r.h), DockEdge::Left),
344 (Rect::new(r.right() - d, r.y, d, r.h), DockEdge::Right),
345 (Rect::new(r.x, r.y, r.w, d), DockEdge::Top),
346 (Rect::new(r.x, r.bottom() - d, r.w, d), DockEdge::Bottom),
347 ];
348 for (z, e) in bands {
349 out.push((z, pl.panel.clone(), e));
350 }
351 out.push((r, pl.panel.clone(), DockEdge::Center));
352 }
353 out
354}
355
356pub fn drop_target_at(
358 zones: &[(Rect, String, DockEdge)],
359 p: [f32; 2],
360) -> Option<(Rect, String, DockEdge)> {
361 zones
362 .iter()
363 .find(|(r, _, _)| r.contains(p[0], p[1]))
364 .cloned()
365}
366
367pub fn draw_drop_zones(
371 ui: &mut Ui,
372 zones: &[(Rect, String, DockEdge)],
373 active: Option<Rect>,
374 theme: &Theme,
375) {
376 let mut faint = theme.colors.accent;
377 faint[3] = 0.45;
378 let mut glow = theme.colors.accent;
379 glow[3] = 0.28;
380 for (r, _, e) in zones {
381 if *e != DockEdge::Center {
382 ui.draw.stroke(*r, 1.0, faint);
383 }
384 }
385 if let Some(a) = active {
386 ui.draw.rect(a, glow);
387 ui.draw.stroke(a, 2.0, theme.colors.accent);
388 }
389}
390
391pub fn draw_drag_ghost(ui: &mut Ui, theme: &Theme, atlas: &FontAtlas, label: &str, p: [f32; 2]) {
393 let line_h = atlas.measure(0, "Ag", 0.0)[1];
394 let w = atlas.measure(0, label, 0.0)[0].ceil() + theme.metrics.pad * 2.0;
395 let r = Rect::new(p[0] + 10.0, p[1] + 6.0, w, line_h + theme.metrics.pad);
396 ui.draw.rect(r, theme.colors.panel);
397 ui.draw.stroke(r, 1.0, theme.colors.accent);
398 ui.draw.text(
399 atlas,
400 0,
401 label,
402 r.x + theme.metrics.pad,
403 r.y + theme.metrics.pad * 0.5,
404 line_h,
405 theme.colors.text,
406 );
407}
408
409fn entity_name(ctx: &EditorContext, e: u32) -> String {
411 ctx.call(
412 "ecs.entity.get",
413 json!({ "entity": e, "component": "Name" }),
414 )
415 .ok()
416 .and_then(|v| v.get("wert")?.get("value")?.as_str().map(str::to_string))
417 .unwrap_or_else(|| format!("Entity #{e}"))
418}
419
420pub fn draw_outliner(
423 ui: &mut Ui,
424 pl: &PanelPlacement,
425 theme: &Theme,
426 atlas: &FontAtlas,
427 ctx: &EditorContext,
428 st: &mut PanelState,
429) {
430 let body = panel_frame(ui, pl, theme, atlas, st);
431 let entities: Vec<u32> = ctx
432 .call("ecs.entities", json!({}))
433 .ok()
434 .and_then(|v| v.get("entities")?.as_array().cloned())
435 .map(|a| {
436 a.iter()
437 .filter_map(|e| e.as_u64().map(|x| x as u32))
438 .collect()
439 })
440 .unwrap_or_default();
441 if entities.is_empty() {
442 let line_h = atlas.measure(0, "Ag", 0.0)[1];
443 ui.draw.text(
444 atlas,
445 0,
446 "—",
447 body.x + theme.metrics.pad,
448 body.y + theme.metrics.pad,
449 line_h,
450 theme.colors.text_dim,
451 );
452 return;
453 }
454 let row = theme.metrics.row_h;
455 let content_h = entities.len() as f32 * row;
456 let off = ui.scroll("outliner/scroll", body, content_h);
457 ui.draw.push_clip(body);
458 for (i, e) in entities.iter().enumerate() {
459 let name = entity_name(ctx, *e);
460 let r = Rect::new(
461 body.x,
462 body.y + i as f32 * row - off,
463 (body.w - 5.0).max(0.0),
464 row,
465 );
466 if ui.selectable(&format!("outliner/{e}"), r, &name, st.selected == Some(*e)) {
467 st.selected = Some(*e);
468 st.edits.clear();
469 let _ = ctx.call("editor.selection.set", json!({ "ids": [e] }));
470 }
471 }
472 ui.draw.pop_clip();
473}
474
475pub fn draw_inspector(
479 ui: &mut Ui,
480 pl: &PanelPlacement,
481 theme: &Theme,
482 atlas: &FontAtlas,
483 ctx: &EditorContext,
484 st: &mut PanelState,
485) {
486 let body = panel_frame(ui, pl, theme, atlas, st);
487 let Some(e) = st.selected else {
488 let line_h = atlas.measure(0, "Ag", 0.0)[1];
489 ui.draw.text(
490 atlas,
491 0,
492 "—",
493 body.x + theme.metrics.pad,
494 body.y + theme.metrics.pad,
495 line_h,
496 theme.colors.text_dim,
497 );
498 return;
499 };
500 let comps: Vec<String> = ctx
501 .call("ecs.entity.components", json!({ "entity": e }))
502 .ok()
503 .and_then(|v| v.get("components")?.as_array().cloned())
504 .map(|a| {
505 a.iter()
506 .filter_map(|c| c.as_str().map(str::to_string))
507 .collect()
508 })
509 .unwrap_or_default();
510 let pad = theme.metrics.pad;
511 let row = theme.metrics.row_h;
512 let line_h = atlas.measure(0, "Ag", 0.0)[1];
513 let mut y = body.y + pad * 0.5;
514 ui.draw.push_clip(body);
515 for comp in &comps {
516 if y > body.bottom() {
517 break;
518 }
519 let hr = Rect::new(body.x + 1.0, y, (body.w - 2.0).max(0.0), row);
520 let open = ui.header(&format!("insp/{e}/{comp}"), hr, comp);
521 y += row;
522 if !open {
523 continue;
524 }
525 let wert = ctx
526 .call("ecs.entity.get", json!({ "entity": e, "component": comp }))
527 .ok()
528 .and_then(|v| v.get("wert").cloned());
529 let Some(wert) = wert else { continue };
530 if comp == "Name" {
531 let key = format!("{e}/{comp}/value");
534 let cur = wert
535 .get("value")
536 .and_then(|v| v.as_str())
537 .unwrap_or("")
538 .to_string();
539 let buf = st.edits.entry(key).or_insert(cur);
540 let fr = Rect::new(body.x + pad * 2.0, y, (body.w - pad * 4.0).max(40.0), row);
541 if ui.text_field(&format!("insp/{e}/name/value"), fr, buf) {
542 let _ = ctx.call(
543 "ecs.entity.set",
544 json!({ "entity": e, "component": "Name", "wert": { "value": buf } }),
545 );
546 }
547 y += row + pad * 0.5;
548 } else {
549 match &wert {
555 Value::Object(map) => {
556 let label_w = (body.w * 0.45).max(70.0);
557 for (k, v) in map {
558 if y > body.bottom() {
559 break;
560 }
561 match v {
562 Value::Number(n) => {
563 y = number_row(
564 ui,
565 body,
566 y,
567 label_w,
568 row,
569 pad,
570 e,
571 comp,
572 k,
573 &Value::Number(n.clone()),
574 &wert,
575 ctx,
576 st,
577 );
578 }
579 Value::Array(a) if !a.is_empty() && a.iter().all(Value::is_number) => {
580 for (i, n) in a.iter().enumerate() {
581 let path = format!("{k}[{i}]");
582 y = number_row(
583 ui, body, y, label_w, row, pad, e, comp, &path, n, &wert,
584 ctx, st,
585 );
586 }
587 }
588 other => {
589 let line = format!("{k}: {}", summarize(other));
590 ui.draw.text(
591 atlas,
592 0,
593 &line,
594 body.x + pad * 2.0,
595 y,
596 line_h,
597 theme.colors.text_dim,
598 );
599 y += line_h + 2.0;
600 }
601 }
602 }
603 y += pad * 0.5;
604 }
605 Value::Number(n) => {
606 let label_w = (body.w * 0.45).max(70.0);
607 y = number_row(
608 ui,
609 body,
610 y,
611 label_w,
612 row,
613 pad,
614 e,
615 comp,
616 "value",
617 &Value::Number(n.clone()),
618 &wert,
619 ctx,
620 st,
621 );
622 y += pad * 0.5;
623 }
624 other => {
625 let line = summarize(other);
626 ui.draw.text(
627 atlas,
628 0,
629 &line,
630 body.x + pad * 2.0,
631 y,
632 line_h,
633 theme.colors.text_dim,
634 );
635 y += line_h + 2.0;
636 y += pad * 0.5;
637 }
638 }
639 }
640 }
641 ui.draw.pop_clip();
642}
643
644#[allow(clippy::too_many_arguments)]
647fn number_row(
648 ui: &mut Ui,
649 body: Rect,
650 y: f32,
651 label_w: f32,
652 row: f32,
653 pad: f32,
654 e: u32,
655 comp: &str,
656 path: &str,
657 leaf: &Value,
658 wert: &Value,
659 ctx: &EditorContext,
660 st: &mut PanelState,
661) -> f32 {
662 let is_int = leaf.is_i64() || leaf.is_u64();
663 let step = if is_int { 0.05 } else { scrub_step(comp, path) };
664 let lr = Rect::new(body.x + 4.0, y, (label_w - 6.0).max(30.0), row);
665 let s = ui.scrub(&format!("scrub/{e}/{comp}/{path}"), lr, step);
666 let key = format!("{e}/{comp}/{path}");
667 if !st.edits.contains_key(&key) {
668 st.edits.insert(key.clone(), leaf_text(leaf));
669 }
670 let mut buf = st.edits.get(&key).cloned().unwrap_or_default();
671 let vorher = buf.clone();
672 let mut touched = false;
673 if s.dragging || s.ended {
674 let base = buf
675 .trim()
676 .parse::<f64>()
677 .unwrap_or_else(|_| leaf.as_f64().unwrap_or(0.0));
678 buf = fmt_leaf(is_int, base + f64::from(s.delta));
679 touched = true;
680 }
681 if s.dragging {
685 st.scrub = Some((buf.clone(), [lr.right() + 2.0, y + row + 3.0]));
686 } else if s.ended {
687 st.scrub = None;
688 }
689 let fr = Rect::new(
690 lr.right() + 2.0,
691 y,
692 (body.right() - pad - lr.right()).max(40.0),
693 row,
694 );
695 let mut shown = if s.dragging { vorher } else { buf.clone() };
696 if ui.text_field(&format!("insp/{e}/{comp}/{path}"), fr, &mut shown) {
697 touched = true;
698 buf = shown;
699 }
700 if touched && buf.trim().parse::<f64>().is_ok() {
701 let _ = ctx.call(
702 "ecs.entity.set",
703 json!({ "entity": e, "component": comp, "wert": patched_value(wert, path, &buf, is_int) }),
704 );
705 }
706 st.edits.insert(key, buf);
707 y + row + 2.0
708}
709
710fn scrub_step(comp: &str, path: &str) -> f32 {
712 if comp == "Transform" {
713 if path.starts_with("rotation") {
714 0.25
715 } else {
716 0.01
717 }
718 } else {
719 0.01
720 }
721}
722
723fn leaf_text(v: &Value) -> String {
725 if v.is_i64() || v.is_u64() {
726 v.as_i64().map(|i| i.to_string()).unwrap_or_default()
727 } else {
728 fmt_num(v.as_f64().unwrap_or(0.0))
729 }
730}
731
732fn fmt_num(v: f64) -> String {
735 let f = v as f32;
736 if f.abs() < 1e15 && (f as f64 - f.round() as f64).abs() < 1e-9 {
737 (f.round() as i64).to_string()
738 } else {
739 f.to_string()
740 }
741}
742
743fn fmt_leaf(is_int: bool, v: f64) -> String {
744 if is_int {
745 (v.round() as i64).to_string()
746 } else {
747 fmt_num(v)
748 }
749}
750
751fn split_leaf(path: &str) -> (&str, Option<usize>) {
753 if let Some(rest) = path.strip_suffix(']') {
754 if let Some(b) = rest.rfind('[') {
755 if let Ok(i) = rest[b + 1..].parse() {
756 return (&rest[..b], Some(i));
757 }
758 }
759 }
760 (path, None)
761}
762
763fn patched_value(wert: &Value, path: &str, text: &str, is_int: bool) -> Value {
766 let n: f64 = text.trim().parse().unwrap_or(0.0);
767 let leaf = if is_int {
768 json!(n.round() as i64)
769 } else {
770 json!(n)
771 };
772 let (k, idx) = split_leaf(path);
773 let mut out = wert.clone();
774 match (&mut out, idx) {
775 (Value::Object(o), None) => {
776 o.insert(k.to_string(), leaf);
777 }
778 (Value::Object(o), Some(i)) => {
779 if let Some(a) = o.get_mut(k).and_then(Value::as_array_mut) {
780 if i < a.len() {
781 a[i] = leaf;
782 }
783 }
784 }
785 (Value::Number(_), _) => out = leaf,
786 _ => {}
787 }
788 out
789}
790
791pub fn draw_console(
794 ui: &mut Ui,
795 pl: &PanelPlacement,
796 theme: &Theme,
797 atlas: &FontAtlas,
798 input: &UiInput,
799 ctx: &EditorContext,
800 st: &mut PanelState,
801) {
802 let body = panel_frame(ui, pl, theme, atlas, st);
803 let pad = theme.metrics.pad;
804 let row = theme.metrics.row_h;
805 let line_h = atlas.measure(0, "Ag", 0.0)[1];
806 let cmd_r = Rect::new(
808 body.x + pad,
809 body.bottom() - row - pad,
810 (body.w - pad * 2.0).max(10.0),
811 row,
812 );
813 let log_r = Rect::new(
814 body.x,
815 body.y,
816 body.w,
817 (cmd_r.y - body.y - pad * 0.5).max(0.0),
818 );
819
820 let content_h = st.log.len() as f32 * (line_h + 2.0);
821 let off = ui.scroll("console/scroll", log_r, content_h);
822 ui.draw.push_clip(log_r);
823 for (i, line) in st.log.iter().rev().enumerate() {
824 let y = log_r.y + i as f32 * (line_h + 2.0) - off;
826 if y > log_r.bottom() {
827 continue;
828 }
829 ui.draw.text(
830 atlas,
831 0,
832 line,
833 log_r.x + pad,
834 y,
835 line_h,
836 theme.colors.text_dim,
837 );
838 }
839 ui.draw.pop_clip();
840
841 let mut buf = st.cmdline.clone();
842 ui.text_field("console/cmd", cmd_r, &mut buf);
843 if input.enter && !buf.is_empty() {
844 exec_line(ctx, st, &buf);
845 buf.clear();
846 }
847 st.cmdline = buf;
848}
849
850fn exec_line(ctx: &EditorContext, st: &mut PanelState, line: &str) {
852 let (name, rest) = match line.find(char::is_whitespace) {
853 Some(i) => (&line[..i], line[i..].trim()),
854 None => (line, ""),
855 };
856 let args: Value = if rest.is_empty() {
857 json!({})
858 } else {
859 match serde_json::from_str(rest) {
860 Ok(v) => v,
861 Err(e) => {
862 st.log(format!("argumente: {e}"));
863 return;
864 }
865 }
866 };
867 run_command(
868 ctx,
869 st,
870 &Command {
871 id: name.to_string(),
872 capability: name.to_string(),
873 args,
874 separator: false,
875 },
876 );
877}
878
879pub fn draw_assistant(
883 ui: &mut Ui,
884 pl: &PanelPlacement,
885 theme: &Theme,
886 atlas: &FontAtlas,
887 input: &UiInput,
888 st: &mut PanelState,
889) {
890 let body = panel_frame(ui, pl, theme, atlas, st);
891 let pad = theme.metrics.pad;
892 let row = theme.metrics.row_h;
893 let line_h = atlas.measure(0, "Ag", 0.0)[1];
894 ui.draw.text(
895 atlas,
896 0,
897 "KI-Assistent: noch kein Provider verbunden (M4 P2).",
898 body.x + pad,
899 body.y + pad,
900 line_h,
901 theme.colors.text_dim,
902 );
903 let mut buf = st.assistant_line.clone();
904 let fr = Rect::new(
905 body.x + pad,
906 body.bottom() - row - pad,
907 (body.w - pad * 2.0).max(10.0),
908 row,
909 );
910 ui.text_field("assistant/input", fr, &mut buf);
911 if input.enter && !buf.is_empty() {
912 st.log(format!("assistant → {buf}"));
913 buf.clear();
914 }
915 st.assistant_line = buf;
916}
917
918pub fn draw_viewport_frame(ui: &mut Ui, pl: &PanelPlacement, theme: &Theme, atlas: &FontAtlas) {
921 let r = pl.rect;
922 ui.draw.stroke(r, 1.0, theme.colors.border);
923 let label = theme.label("panel.viewport").to_string();
924 let line_h = atlas.measure(0, "Ag", 0.0)[1];
925 let pad = theme.metrics.pad;
926 let w = atlas.measure(0, &label, 0.0)[0] + pad;
927 ui.draw.rect(
928 Rect::new(r.x + pad, r.y + pad, w, line_h + pad * 0.5),
929 [0.0, 0.0, 0.0, 0.45],
930 );
931 ui.draw.text(
932 atlas,
933 0,
934 &label,
935 r.x + pad * 1.5,
936 r.y + pad * 0.75,
937 line_h,
938 theme.colors.text_dim,
939 );
940}
941
942pub fn draw_vfx(
947 ui: &mut Ui,
948 pl: &PanelPlacement,
949 theme: &Theme,
950 atlas: &FontAtlas,
951 input: &UiInput,
952 ctx: &EditorContext,
953 st: &mut PanelState,
954) {
955 let body = panel_frame(ui, pl, theme, atlas, st);
956 let pad = theme.metrics.pad;
957 let row = theme.metrics.row_h;
958 let line_h = atlas.measure(0, "Ag", 0.0)[1];
959 let data = ctx.call("vfx.get", json!({})).unwrap_or(Value::Null);
960
961 let acts: [(&str, &str, Value); 10] = [
963 ("vfx.add.emit", "vfx.node.add", json!({ "typ": "emit" })),
964 (
965 "vfx.add.gravity",
966 "vfx.node.add",
967 json!({ "typ": "gravity" }),
968 ),
969 ("vfx.add.drag", "vfx.node.add", json!({ "typ": "drag" })),
970 ("vfx.add.swirl", "vfx.node.add", json!({ "typ": "swirl" })),
971 (
972 "vfx.add.ramp",
973 "vfx.node.add",
974 json!({ "typ": "size_ramp", "keys": [[0.0, 1.0], [1.0, 0.1]] }),
975 ),
976 ("vfx.remove", "vfx.node.remove", json!({})),
977 ("vfx.action.validate", "vfx.validate", json!({})),
978 ("vfx.action.play", "vfx.play", json!({})),
979 ("vfx.action.stop", "vfx.stop", json!({})),
980 (
981 "vfx.action.save",
982 "vfx.save",
983 json!({ "path": "effekt.fxgraph.json" }),
984 ),
985 ];
986 let mut ax = body.x + pad;
987 let ay = body.y + pad;
988 for (key, cap, args) in &acts {
989 let label = theme.label(key);
990 let mut a = args.clone();
991 if *cap == "vfx.node.remove" {
992 if let Some(sel) = data.get("selected") {
995 a = json!({ "id": sel });
996 }
997 }
998 let w = atlas.measure(0, label, 0.0)[0] + pad * 2.0;
999 if ax + w > body.right() - pad {
1000 break;
1001 }
1002 if ui.button(key, Rect::new(ax, ay, w, row), label) {
1003 match ctx.call(cap, a) {
1004 Ok(v) => st.log(format!("{cap} → {}", summarize(&v))),
1005 Err(e) => st.log(format!("{cap} FEHLER: {e}")),
1006 }
1007 }
1008 ax += w + pad * 0.5;
1009 }
1010
1011 let n_knoten = data.get("knoten").and_then(|v| v.as_u64()).unwrap_or(0);
1013 let n_kanten = data.get("kanten").and_then(|v| v.as_u64()).unwrap_or(0);
1014 let n_teilchen = data.get("teilchen").and_then(|v| v.as_u64()).unwrap_or(0);
1015 let stats = format!(
1016 "{} {n_knoten} · {} {n_kanten} · {} {n_teilchen}",
1017 theme.label("vfx.stat.nodes"),
1018 theme.label("vfx.stat.links"),
1019 theme.label("vfx.stat.alive"),
1020 );
1021 let stats_y = ay + row + pad * 0.5;
1022 ui.draw.text(
1023 atlas,
1024 0,
1025 &stats,
1026 body.x + pad,
1027 stats_y,
1028 line_h,
1029 theme.colors.text_dim,
1030 );
1031
1032 let area = Rect::new(
1034 body.x,
1035 stats_y + line_h + pad,
1036 body.w,
1037 (body.bottom() - stats_y - line_h - pad * 2.0).max(0.0),
1038 );
1039 let zeige: Vec<&Value> = data
1040 .get("zeige")
1041 .and_then(|v| v.as_array())
1042 .map(|a| a.iter().collect())
1043 .unwrap_or_default();
1044 if zeige.is_empty() {
1045 ui.draw.text(
1046 atlas,
1047 0,
1048 theme.label("vfx.hint"),
1049 area.x + pad,
1050 area.y + pad,
1051 line_h,
1052 theme.colors.text_dim,
1053 );
1054 return;
1055 }
1056
1057 let node_h = pad * 2.0 + line_h * 2.0 + 2.0;
1059 let gap = 26.0;
1060 let mut rects: Vec<(u32, Rect)> = Vec::with_capacity(zeige.len());
1061 let mut x = area.x + pad;
1062 let mut y = area.y + pad;
1063 let right = area.right() - pad - 6.0;
1064 for k in &zeige {
1065 let titel = theme.label(k.get("titel").and_then(|v| v.as_str()).unwrap_or(""));
1066 let text = k.get("text").and_then(|v| v.as_str()).unwrap_or("");
1067 let w = (atlas.measure(1, titel, 0.0)[0].max(atlas.measure(0, text, 0.0)[0]) + pad * 2.0)
1068 .max(96.0)
1069 .ceil();
1070 if x + w > right && x > area.x + pad {
1071 x = area.x + pad;
1072 y += node_h + gap;
1073 }
1074 let id = k.get("id").and_then(|v| v.as_u64()).unwrap_or(0) as u32;
1075 rects.push((id, Rect::new(x, y, w, node_h)));
1076 x += w + gap;
1077 }
1078 let content_h = (y - area.y) + node_h + pad * 2.0;
1079 let off = ui.scroll("vfx/graph", area, content_h);
1080
1081 ui.draw.push_clip(area);
1082 let links: Vec<(u32, u32)> = data
1084 .get("kanten_ids")
1085 .and_then(|v| v.as_array())
1086 .map(|a| {
1087 a.iter()
1088 .filter_map(|l| {
1089 let p = l.as_array()?;
1090 Some((p.first()?.as_u64()? as u32, p.get(1)?.as_u64()? as u32))
1091 })
1092 .collect()
1093 })
1094 .unwrap_or_default();
1095 let selected = data
1096 .get("selected")
1097 .and_then(|v| v.as_u64())
1098 .map(|v| v as u32);
1099 for (from, to) in &links {
1100 let (Some((_, a)), Some((_, b))) = (
1101 rects.iter().find(|(i, _)| i == from),
1102 rects.iter().find(|(i, _)| i == to),
1103 ) else {
1104 continue;
1105 };
1106 let x0 = a.right();
1107 let y0 = a.y + a.h * 0.5 - off;
1108 let x1 = b.x;
1109 let y1 = b.y + b.h * 0.5 - off;
1110 let mid = (x0 + x1) * 0.5;
1111 let farbe = if Some(*from) == selected || Some(*to) == selected {
1112 theme.colors.accent
1113 } else {
1114 theme.colors.border
1115 };
1116 ui.draw.line(x0, y0, mid, y0, 1.0, farbe);
1117 ui.draw.line(mid, y0, mid, y1, 1.0, farbe);
1118 ui.draw.line(mid, y1, x1, y1, 1.0, farbe);
1119 }
1120 for (id, r) in &rects {
1121 let rr = Rect::new(r.x, r.y - off, r.w, r.h);
1122 let titel_key = zeige
1123 .iter()
1124 .find(|k| k.get("id").and_then(|v| v.as_u64()) == Some(*id as u64))
1125 .and_then(|k| k.get("titel"))
1126 .and_then(|v| v.as_str())
1127 .unwrap_or("");
1128 let text = zeige
1129 .iter()
1130 .find(|k| k.get("id").and_then(|v| v.as_u64()) == Some(*id as u64))
1131 .and_then(|k| k.get("text"))
1132 .and_then(|v| v.as_str())
1133 .unwrap_or("");
1134 ui.draw.rect(rr, theme.colors.header);
1135 ui.draw.stroke(
1136 rr,
1137 if Some(*id) == selected { 1.5 } else { 1.0 },
1138 if Some(*id) == selected {
1139 theme.colors.accent
1140 } else {
1141 theme.colors.border
1142 },
1143 );
1144 ui.draw.text(
1145 atlas,
1146 1,
1147 theme.label(titel_key),
1148 rr.x + pad,
1149 rr.y + pad * 0.5,
1150 line_h,
1151 theme.colors.text,
1152 );
1153 ui.draw.text(
1154 atlas,
1155 0,
1156 text,
1157 rr.x + pad,
1158 rr.y + pad * 0.5 + line_h + 2.0,
1159 line_h,
1160 theme.colors.text_dim,
1161 );
1162 if input.pressed {
1164 if let Some(p) = input.pointer {
1165 if rr.contains(p[0], p[1]) {
1166 let args = if selected == Some(*id) {
1167 json!({})
1168 } else {
1169 json!({ "id": *id })
1170 };
1171 let _ = ctx.call("vfx.select", args);
1172 }
1173 }
1174 }
1175 }
1176 ui.draw.pop_clip();
1177}
1178
1179fn draw_unknown(
1182 ui: &mut Ui,
1183 pl: &PanelPlacement,
1184 theme: &Theme,
1185 atlas: &FontAtlas,
1186 st: &mut PanelState,
1187) {
1188 let body = panel_frame(ui, pl, theme, atlas, st);
1189 let line_h = atlas.measure(0, "Ag", 0.0)[1];
1190 let msg = format!("unbekanntes Panel: {}", pl.panel);
1191 ui.draw.text(
1192 atlas,
1193 0,
1194 &msg,
1195 body.x + theme.metrics.pad,
1196 body.y + theme.metrics.pad,
1197 line_h,
1198 theme.colors.accent,
1199 );
1200}
1201
1202pub fn draw_panel(
1204 ui: &mut Ui,
1205 pl: &PanelPlacement,
1206 theme: &Theme,
1207 atlas: &FontAtlas,
1208 input: &UiInput,
1209 ctx: &EditorContext,
1210 st: &mut PanelState,
1211) {
1212 match pl.panel.as_str() {
1213 "outliner" => draw_outliner(ui, pl, theme, atlas, ctx, st),
1214 "inspector" => draw_inspector(ui, pl, theme, atlas, ctx, st),
1215 "console" => draw_console(ui, pl, theme, atlas, input, ctx, st),
1216 "assistant" => draw_assistant(ui, pl, theme, atlas, input, st),
1217 "viewport" => draw_viewport_frame(ui, pl, theme, atlas),
1218 "vfx" => draw_vfx(ui, pl, theme, atlas, input, ctx, st),
1219 _ => draw_unknown(ui, pl, theme, atlas, st),
1220 }
1221}
1222
1223#[cfg(test)]
1224mod tests {
1225 use super::*;
1226 use crate::layout::Preset;
1227 use glam::Vec3;
1228 use re_render::ui::dock_layout;
1229 use re_render::ui::widgets::UiState;
1230
1231 const FONT: &[u8] = include_bytes!("../../../assets/fonts/inter/Inter-Regular.ttf");
1232 const FONT_BOLD: &[u8] = include_bytes!("../../../assets/fonts/inter/Inter-Bold.ttf");
1233
1234 fn atlas() -> FontAtlas {
1235 FontAtlas::build(&[FONT, FONT_BOLD], 15.0, "äöüÄÖÜß—→…", 1024, 512).expect("Atlas")
1236 }
1237
1238 fn input() -> UiInput {
1239 UiInput {
1240 pointer: None,
1241 pressed: false,
1242 released: false,
1243 scroll: 0.0,
1244 chars: String::new(),
1245 backspace: false,
1246 enter: false,
1247 shift: false,
1248 ctrl: false,
1249 }
1250 }
1251
1252 #[test]
1257 fn ue5_preset_malt_alle_panels_und_deutsche_menuetitel() {
1258 let preset = Preset::embedded("ue5").expect("ue5-Preset");
1259 let ctx = EditorContext::new(Vec3::ZERO);
1260 preset
1261 .manifest
1262 .validate_against(|c| ctx.has(c))
1263 .expect("ue5-Manifest-Bindings");
1264 let atlas = atlas();
1265 let theme = &preset.theme;
1266 let area = Rect::new(0.0, 0.0, 1280.0, 720.0);
1269 let slots = menu_bar_layout(
1270 &preset.manifest.menu_bar,
1271 &atlas,
1272 Rect::new(0.0, 0.0, 1280.0, theme.metrics.row_h),
1273 theme.metrics.pad,
1274 theme,
1275 );
1276 assert_eq!(slots.len(), preset.manifest.menu_bar.len());
1277 for (id, r) in &slots {
1278 let label = theme.label(id);
1279 assert_ne!(label, id.as_str(), "Menütitel zeigt rohe ID {id}");
1280 let text_w = atlas.measure(0, label, 0.0)[0].ceil();
1281 assert!(
1282 r.w >= text_w,
1283 "Slot {id} ({:.1}) schmaler als sein Titel {label} ({:.1})",
1284 r.w,
1285 text_w
1286 );
1287 }
1288 let mut state = UiState::default();
1290 let mut pst = PanelState::default();
1291 let inp = input();
1292 let chrome = theme.metrics.row_h * 2.0 + 4.0;
1293 let dock = Rect::new(0.0, chrome, 1280.0, 720.0 - chrome - theme.metrics.row_h);
1294 let placements = dock_layout(
1295 &preset.manifest.dock,
1296 dock,
1297 theme.metrics.tab_h,
1298 theme.metrics.splitter,
1299 );
1300 assert_eq!(placements.len(), 4);
1301 let mut ui = Ui::new(area, theme, &atlas, None, &mut state, &inp);
1302 for pl in &placements {
1303 draw_panel(&mut ui, pl, theme, &atlas, &inp, &ctx, &mut pst);
1304 }
1305 ui.end();
1306 assert!(!ui.draw.cmds().is_empty(), "Draw-List ist leer");
1307 }
1308
1309 #[test]
1313 fn default_preset_malt_alle_panels() {
1314 let preset = Preset::embedded_default();
1315 let ctx = EditorContext::new(Vec3::ZERO);
1316 preset
1317 .manifest
1318 .validate_against(|c| ctx.has(c))
1319 .expect("Manifest-Bindings");
1320 let atlas = atlas();
1321 let theme = &preset.theme;
1322 let area = Rect::new(0.0, 0.0, 1280.0, 720.0);
1323 let mut state = UiState::default();
1324 let mut pst = PanelState::default();
1325 let inp = input();
1326
1327 let chrome = theme.metrics.row_h * 2.0 + 4.0;
1328 let dock = Rect::new(0.0, chrome, 1280.0, 720.0 - chrome - theme.metrics.row_h);
1329 let placements = dock_layout(
1330 &preset.manifest.dock,
1331 dock,
1332 theme.metrics.tab_h,
1333 theme.metrics.splitter,
1334 );
1335 assert_eq!(
1336 placements.len(),
1337 4,
1338 "vier Dock-Zellen (Tab-Gruppe zählt eine aktive)"
1339 );
1340
1341 let mut ui = Ui::new(area, theme, &atlas, None, &mut state, &inp);
1342 for pl in &placements {
1343 draw_panel(&mut ui, pl, theme, &atlas, &inp, &ctx, &mut pst);
1344 }
1345 ui.end();
1346 assert!(!ui.draw.cmds().is_empty(), "Draw-List ist leer");
1347 }
1350
1351 #[test]
1352 fn konsole_fuehrt_kommandozeile_als_capability_call() {
1353 let ctx = EditorContext::new(Vec3::ZERO);
1354 let mut st = PanelState::default();
1355 exec_line(&ctx, &mut st, "project.new {\"name\":\"Konsole\"}");
1356 assert!(
1357 st.log.iter().any(|l| l.contains("project.new")),
1358 "{:?}",
1359 st.log
1360 );
1361 let info = ctx.call("project.info", json!({})).unwrap();
1362 assert_eq!(info["name"], json!("Konsole"));
1363 exec_line(&ctx, &mut st, "project.new {kein json");
1365 assert!(st.log.iter().any(|l| l.contains("argumente")));
1366 }
1367
1368 #[test]
1369 fn run_command_loggt_fehler_stattzu_crashen() {
1370 let ctx = EditorContext::new(Vec3::ZERO);
1371 let mut st = PanelState::default();
1372 run_command(
1373 &ctx,
1374 &mut st,
1375 &Command {
1376 id: "x".into(),
1377 capability: "gibt.es.nicht".into(),
1378 args: json!({}),
1379 separator: false,
1380 },
1381 );
1382 assert!(st.log.iter().any(|l| l.contains("FEHLER")));
1383 }
1384
1385 #[test]
1386 fn dropzonen_kanten_schlagen_mitte() {
1387 let ps = vec![PanelPlacement {
1388 panel: "viewport".into(),
1389 rect: Rect::new(100.0, 0.0, 400.0, 300.0),
1390 tabs: vec![],
1391 }];
1392 let zones = drop_zones(&ps, "console");
1393 assert!(
1394 !zones.iter().any(|(_, t, _)| t == "console"),
1395 "eigenes Panel hat keine Zonen"
1396 );
1397 let hit = drop_target_at(&zones, [110.0, 150.0]).expect("linker Randstreifen");
1398 assert_eq!(hit.2, DockEdge::Left);
1399 let hit = drop_target_at(&zones, [300.0, 150.0]).expect("Flächenmitte");
1400 assert_eq!(hit.2, DockEdge::Center);
1401 assert!(
1402 drop_target_at(&zones, [10.0, 10.0]).is_none(),
1403 "außerhalb ist kein Ziel"
1404 );
1405 }
1406
1407 #[test]
1408 fn patched_value_setzt_blatt_und_laesst_rest() {
1409 let wert = json!({ "translation": [1.0, 2.0, 3.0], "rotation": [0.0, 0.0, 0.0, 1.0] });
1410 let p = patched_value(&wert, "translation[1]", "2.5", false);
1411 assert_eq!(p["translation"][1], json!(2.5));
1412 assert_eq!(p["translation"][2], json!(3.0), "Nachbarn bleiben");
1413 assert_eq!(p["rotation"][3], json!(1.0), "andere Schlüssel bleiben");
1414 let i = patched_value(&json!({ "energie": 40 }), "energie", "40.7", true);
1415 assert_eq!(i["energie"], json!(41), "integer-Blatt rundet");
1416 }
1417
1418 #[test]
1421 fn inspektor_scrubbt_zahlenblatt_ueber_capability() {
1422 use re_core::transform::Transform;
1423 let ctx = EditorContext::new(Vec3::ZERO);
1424 let id = {
1425 let mut w = ctx.world.lock().unwrap();
1426 let ent = w.spawn();
1427 w.insert(
1428 ent,
1429 Transform {
1430 translation: [1.0, 0.0, 0.0],
1431 ..Default::default()
1432 },
1433 );
1434 ent.index()
1435 };
1436 let vorher = ctx
1437 .call(
1438 "ecs.entity.get",
1439 json!({ "entity": id, "component": "Transform" }),
1440 )
1441 .unwrap()["wert"]
1442 .clone();
1443
1444 let a = atlas();
1445 let t = Theme::default();
1446 let row = t.metrics.row_h;
1447 let pad = t.metrics.pad;
1448 let pl = PanelPlacement {
1449 panel: "inspector".into(),
1450 rect: Rect::new(0.0, 0.0, 300.0, 400.0),
1451 tabs: vec![],
1452 };
1453 let mut st = UiState::default();
1454 let mut pst = PanelState {
1455 selected: Some(id),
1456 ..Default::default()
1457 };
1458 let first_leaf_y = row + pad * 0.5 + row + row * 0.5; let frame = |pointer: Option<[f32; 2]>,
1462 pressed: bool,
1463 released: bool,
1464 st: &mut UiState,
1465 pst: &mut PanelState| {
1466 let i = UiInput {
1467 pointer,
1468 pressed,
1469 released,
1470 ..Default::default()
1471 };
1472 let mut ui = Ui::new(Rect::new(0.0, 0.0, 300.0, 400.0), &t, &a, None, st, &i);
1473 draw_inspector(&mut ui, &pl, &t, &a, &ctx, pst);
1474 ui.end();
1475 };
1476 frame(Some([40.0, first_leaf_y]), true, false, &mut st, &mut pst);
1479 frame(Some([60.0, first_leaf_y]), false, false, &mut st, &mut pst);
1480 frame(Some([70.0, first_leaf_y]), false, false, &mut st, &mut pst);
1481 let (chip, anker) = pst.scrub.clone().expect("Wert-Kästchen läuft mit");
1482 assert!(
1483 anker[1] > first_leaf_y,
1484 "Kästchen-Anker sitzt unter der Zeile"
1485 );
1486 assert!(
1487 chip.trim().parse::<f64>().is_ok(),
1488 "Kästchen zeigt eine Zahl: {chip}"
1489 );
1490 frame(Some([70.0, first_leaf_y]), false, true, &mut st, &mut pst);
1491
1492 let nachher = ctx
1493 .call(
1494 "ecs.entity.get",
1495 json!({ "entity": id, "component": "Transform" }),
1496 )
1497 .unwrap()["wert"]
1498 .clone();
1499 assert_ne!(
1500 vorher, nachher,
1501 "Scrubben muss die Welt über die Capability ändern"
1502 );
1503 assert!(pst.scrub.is_none(), "nach dem Loslass kein Chip mehr");
1504 }
1505
1506 #[test]
1510 fn vfx_preset_malt_graph_und_kanten() {
1511 let preset = Preset::embedded("vfx").expect("vfx-Preset");
1512 let ctx = EditorContext::new(Vec3::ZERO);
1513 preset
1514 .manifest
1515 .validate_against(|c| ctx.has(c))
1516 .expect("vfx-Manifest-Bindings");
1517 let e = ctx
1519 .call("vfx.node.add", json!({ "typ": "emit", "burst": 12 }))
1520 .unwrap()["id"]
1521 .as_u64()
1522 .unwrap();
1523 let g = ctx
1524 .call("vfx.node.add", json!({ "typ": "gravity" }))
1525 .unwrap()["id"]
1526 .as_u64()
1527 .unwrap();
1528 let r = ctx
1529 .call(
1530 "vfx.node.add",
1531 json!({ "typ": "size_ramp", "keys": [[0.0, 1.0], [1.0, 0.1]] }),
1532 )
1533 .unwrap()["id"]
1534 .as_u64()
1535 .unwrap();
1536 ctx.call("vfx.link", json!({ "from": e, "to": g })).unwrap();
1537 ctx.call("vfx.link", json!({ "from": g, "to": r })).unwrap();
1538 ctx.call("vfx.play", json!({})).unwrap();
1539 for _ in 0..20 {
1540 ctx.call("vfx.step", json!({ "dt": 1.0 / 60.0 })).unwrap();
1541 }
1542
1543 let atlas = atlas();
1544 let theme = &preset.theme;
1545 let area = Rect::new(0.0, 0.0, 1280.0, 800.0);
1546 let mut state = UiState::default();
1547 let mut pst = PanelState::default();
1548 let inp = input();
1549 let chrome = theme.metrics.row_h * 2.0 + 4.0;
1550 let dock = Rect::new(0.0, chrome, 1280.0, 800.0 - chrome - theme.metrics.row_h);
1551 let placements = dock_layout(
1552 &preset.manifest.dock,
1553 dock,
1554 theme.metrics.tab_h,
1555 theme.metrics.splitter,
1556 );
1557 assert_eq!(placements.len(), 4);
1558 assert!(
1559 placements.iter().any(|p| p.panel == "vfx"),
1560 "vfx-Panel ist die aktive Tab-Zelle"
1561 );
1562 let mut ui = Ui::new(area, theme, &atlas, None, &mut state, &inp);
1563 for pl in &placements {
1564 draw_panel(&mut ui, pl, theme, &atlas, &inp, &ctx, &mut pst);
1565 }
1566 ui.end();
1567 assert!(!ui.draw.cmds().is_empty(), "Draw-List ist leer");
1568
1569 if let Ok(out) = std::env::var("RE_VFX_PNG") {
1570 let rgba =
1571 re_render::rasterize(&ui.draw, Some(&atlas), 1280, 800, theme.colors.background);
1572 let img = image::RgbaImage::from_raw(1280, 800, rgba).expect("puffer");
1573 img.save(&out).expect("PNG");
1574 }
1575 }
1576}