dymokomi/luced-3d
Source of release 0.11.5
0.11.5 / 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
pub func menu_tests() -> unit!:
for name in node_catalog.kinds(): assert(ui.icon_known(tool_icons.asset_name(name)))
for name in ["Move", "Rotate", "Scale", "Pivot", "Snap", "Fill", "Dissolve", "Flatten", "Frame", "Select", "Extrude"]:
assert(ui.icon_known(tool_icons.asset_name(name)))
for mode in 0..<7: assert(ui.icon_known(shading_menu.mode_asset(mode)))
let editor = Luce3D()
editor.app.layout(1000.0, 700.0)
let graph = editor.panels.graph
let area = graph.layout().bounds()
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = area.x + area.width - 5.0, y = area.y + area.height - 5.0, button = 1))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = area.x + area.width - 5.0, y = area.y + area.height - 5.0, button = 1))
editor.app.layout(1000.0, 700.0)
let menu = editor.panels.search
assert(menu.is_open() and menu.query() == "" and menu.result_count() == 6)
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.view.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.view.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(10)
assert(editor.workspace.view.render_samples == 1024)
shading.choose(6)
assert(editor.workspace.view.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")