dymokomi/luced-3d
Source of release 0.11.6
0.11.6 / tests / editor / menu_tests.luc
from app import Luce3D
from luce_ui.ui import Event
from luce_window.input import EventKind, Key
from luce_ui import ui
import tool_icons
import shading_menu
from viewport_chrome import view_buttons_width
import node_catalog
import edit_types
import snapping
import sketch_tools
pub func menu_tests() -> unit!:
# Every node names an icon of its own: none falls back to Geo's mesh.
var fallen = ""
for name in node_catalog.kinds():
let icon = tool_icons.asset_name(name)
assert(ui.icon_known(icon), name)
if icon == "mesh" and name != "Geo": fallen += name + "; "
assert(fallen == "", fallen)
for (name, icon) in [("Output", "output-node"), ("Input", "input-node"), ("CAD", "context-cad"), ("GSplats", "context-gsplats"), ("Edit Mesh", "edit-mesh"),
("Edit CAD", "edit-cad"), ("Press Pull", "press-pull"), ("Script", "script-node"), ("Cache", "cache-node"), ("Image Texture", "image-texture"), ("Math", "shader-node")]:
assert(tool_icons.asset_name(name) == icon, name)
for name in ["Move", "Rotate", "Scale", "Pivot", "Snap", "Fill", "Dissolve", "Flatten", "Frame", "Select", "Extrude", "Hulls"]:
assert(ui.icon_known(tool_icons.asset_name(name)), name)
for mode in 0..<shading_menu.mode_names().length: assert(ui.icon_known(shading_menu.mode_asset(mode)), shading_menu.mode_names()[mode])
for icon in edit_types.level_icons() + snapping.snap_icons(): assert(ui.icon_known(icon), icon)
for menu in 0..<sketch_tools.menu_names().length:
for tool in sketch_tools.tools(menu):
assert(ui.icon_known(tool.icon), tool.name)
for variant in tool.variants: assert(ui.icon_known(variant.icon), variant.name)
let editor = Luce3D()
editor.app.layout(1000.0, 700.0)
let graph = editor.panels.graph
let area = graph.layout().bounds()
# Tab at the view's corner: the node menu stays inside the window.
editor.app.focus(graph.layout())
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + area.width - 5.0, y = area.y + area.height - 5.0))
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.tab))
editor.app.layout(1000.0, 700.0)
let menu = editor.panels.search
assert(menu.is_open() and menu.query() == "" and menu.result_count() == 14)
let bounds = menu.layout().bounds()
assert(bounds.x >= 0.0 and bounds.y >= 0.0 and bounds.x + bounds.width <= 1000.1 and bounds.y + bounds.height <= 700.1)
# Browse a submenu, then search globally rather than within that category.
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.down))
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.right))
for scalar in [70, 105, 108, 101]:
editor.app.dispatch(Event(kind = EventKind.text_input, codepoint = scalar))
assert(menu.result_count() == 1)
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.enter))
assert(not menu.is_open() and (editor.workspace.selected() else trap("node")).kind == "File")
editor.app.focus(graph.layout())
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.tab))
editor.app.layout(1000.0, 700.0)
assert(menu.is_open())
let selected = editor.workspace.network.selected
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = 2.0, y = 2.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = 2.0, y = 2.0, button = 0))
assert(not menu.is_open() and editor.workspace.network.selected == selected)
editor.app.focus(graph.layout())
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.tab))
editor.app.layout(1000.0, 700.0)
assert(menu.is_open())
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.escape))
assert(not menu.is_open())
let view = editor.panels.view.layout().bounds()
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = view.x + view.width - view_buttons_width() - 22.0, y = view.y + 20.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = view.x + view.width - view_buttons_width() - 22.0, y = view.y + 20.0, button = 0))
editor.app.layout(1000.0, 700.0)
let shading = editor.panels.shading
assert(shading.layout().is_visible())
let popup = shading.layout().bounds()
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = popup.x + 60.0, y = popup.y + 20.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = popup.x + 60.0, y = popup.y + 20.0, button = 0))
assert(editor.workspace.view.display_mode == 0 and not shading.layout().is_visible())
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = view.x + view.width - view_buttons_width() - 22.0, y = view.y + 20.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = view.x + view.width - view_buttons_width() - 22.0, y = view.y + 20.0, button = 0))
editor.app.layout(1000.0, 700.0)
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = 2.0, y = 2.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = 2.0, y = 2.0, button = 0))
assert(not shading.layout().is_visible())
# The view buttons: Frame, Grid, Control hulls; the last toggles hulls.
let hulls = view.x + view.width - view_buttons_width() + 2.0 * 38.0 + 16.0
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = hulls, y = view.y + 20.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = hulls, y = view.y + 20.0, button = 0))
assert(not editor.workspace.display.hulls_visible)
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = hulls, y = view.y + 20.0, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = hulls, y = view.y + 20.0, button = 0))
assert(editor.workspace.display.hulls_visible)
# Render: the mode, with its sample cap as an option row a click steps.
shading.choose(5)
assert(editor.workspace.view.display_mode == 5)
shading.choose(11)
assert(editor.workspace.display.render_samples == 1024)
# Draft: the mode, its pull direction and angle as rows a click steps.
shading.choose(10)
assert(editor.workspace.view.display_mode == 10)
shading.choose(11)
shading.choose(12)
assert(editor.workspace.display.draft_axis == 2 and editor.workspace.display.draft_angle == 2.0)
shading.choose(5)
shading.choose(6)
assert(editor.workspace.display.normals_visible)
shading.choose(4)
assert(editor.workspace.view.display_mode == 4)
editor.workspace.view.distance = 1000.0
editor.workspace.view.zoom(0.1)
assert(editor.workspace.view.distance > 900.0)
let projection = editor.workspace.view.camera.projection()
assert(projection.near > 1.0 and projection.far > 1000.0)
editor.close()
print("PASS node menus, categories, filtering, bounds, shading selection and outside dismissal")