# HG changeset patch # User Sam # Date 1707149482 -25200 # Node ID c5999345f42c6cbe921d40f3dd87c139299bda0b # Parent 740d2f0d1264ae129f24c19979001cf243600475 add: panels diff -r 740d2f0d1264 -r c5999345f42c semicongine/panel.nim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/semicongine/panel.nim Mon Feb 05 23:11:22 2024 +0700 @@ -0,0 +1,55 @@ +import ./core + +const + SHADER_ATTRIB_PREFIX = "semicon_text_" + MAX_TEXT_MATERIALS = 10 + +var instanceCounter = 0 + +type + Panel* = object + position: Vec2f + size: Vec2f + color*: Vec4f + + horizontalAlignment: HorizontalAlignment = Center + verticalAlignment: VerticalAlignment = Center + aspect_ratio: float32 + texture: Vec4f + dirty: bool + mesh: Mesh + +proc position*(panel: Panel): Vec2f = + panel.position +proc `position=`*(panel: var Panel, value: Vec2f) = + if value != panel.position: + panel.position = value + panel.dirty = true + +proc size*(panel: Panel): Vec2f = + panel.size +proc `size=`*(panel: var Panel, value: Vec2f) = + if value != panel.size: + panel.size = value + panel.dirty = true + +proc horizontalAlignment*(panel: Panel): HorizontalAlignment = + panel.horizontalAlignment +proc `horizontalAlignment=`*(panel: var Panel, value: HorizontalAlignment) = + if value != panel.horizontalAlignment: + panel.horizontalAlignment = value + panel.dirty = true + +proc verticalAlignment*(panel: Panel): VerticalAlignment = + panel.verticalAlignment +proc `verticalAlignment=`*(panel: var Panel, value: VerticalAlignment) = + if value != panel.verticalAlignment: + panel.verticalAlignment = value + panel.dirty = true + +proc aspect_ratio*(panel: Panel): float32 = + panel.aspect_ratio +proc `aspect_ratio=`*(panel: var Panel, value: float32) = + if value != panel.aspect_ratio: + panel.aspect_ratio = value + panel.dirty = true diff -r 740d2f0d1264 -r c5999345f42c tests/test_panel.nim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_panel.nim Mon Feb 05 23:11:22 2024 +0700 @@ -0,0 +1,28 @@ +import std/unicode + +import semicongine + + +proc main() = + # setup engine + var engine = initEngine("Test panels") + engine.initRenderer([]) + + # build scene + var scene = Scene(name: "main") + var panel = initPanel(position: newVec2f(0, 0), size: newVec2f(0.1, 0.1)) + + scene.add panel + engine.loadScene(scene) + + while engine.updateInputs() == Running and not engine.keyIsDown(Escape): + if engine.windowWasResized(): + var winSize = engine.getWindow().size + panel.aspect_ratio = winSize[0] / winSize[1] + + engine.renderScene(scene) + engine.destroy() + + +when isMainModule: + main()