0da4e6b000f1 — Leonard Ritter 2 months ago
* refreshed nanovg bindings and test
M externals/build_cimgui.py +2 -0
@@ 14,6 14,8 @@ class Builder(BuilderBase):
     #GIT_REVISION = "1d32b3804d834da4d05f02d6d81e2f6b4b94138e"
     # jun 30, 2020, master
     GIT_REVISION = "c1f0030b20488a940f0813f413d84313652bb0b2"
+    # april 7, 2021, master
+    #GIT_REVISION = "6a98f4bbedec967d02f3395f319feceec311ecb2"
 
     def run_any_build(self):
         self.copy2(os.path.join(self.TARGETDIR, '..', 'imgui', 'imgui.h'),

          
M externals/build_imgui.py +3 -1
@@ 13,7 13,9 @@ class Builder(BuilderBase):
     # 1.75+ docking branch
     #GIT_REVISION = "103c5edaaa832ccded2523ea328dc4398ba7b456"
     # 1.77+ docking branch
-    GIT_REVISION = "4f5aac319e3561284833db90f35d218de8b282c1"
+    #GIT_REVISION = "4f5aac319e3561284833db90f35d218de8b282c1"
+    # 1.80+ docking branch
+    GIT_REVISION = "80b5fb51edba2fd3dea76ec3e88153e2492243d1"
 
     def run_any_build(self):
         self.copy2(os.path.join(self.TARGETDIR, 'imgui.h'),

          
M externals/build_nanovg.py +3 -0
@@ 6,7 6,10 @@ from build_common import BuilderBase
 class Builder(BuilderBase):
     NAME = 'nanovg'
     GIT_URL = "https://github.com/memononen/nanovg"
+    # oct 25, 2015
     GIT_REVISION = "cb6fd9100d1f316fc14a5b49df40d3defefd799d"
+    # dec 25, 2020
+    GIT_REVISION = "077b65e0cf3e22ee4f588783e319b19b0a608065"
 
     def run_any_build(self):
         self.copy2(os.path.join(self.TARGETDIR, 'src', 'nanovg.h'),

          
M genie.lua +1 -0
@@ 76,6 76,7 @@ solution "Tukan"
             "build/src/imgui/imgui.cpp",
             "build/src/imgui/imgui_draw.cpp",
             "build/src/imgui/imgui_demo.cpp",
+            "build/src/imgui/imgui_tables.cpp",
             "build/src/imgui/imgui_widgets.cpp",
 
             "build/src/cimgui/*.cpp",

          
M lib/tukan/GLMain.sc +9 -7
@@ 103,11 103,13 @@ struct GLMain
                 on-event event
                 repeat quit
 
-    fn size (self)
-        local w = 0
-        local h = 0
-        SDL_GetWindowSize self.window &w &h
-        _ (deref w) (deref h)
+    size :=
+        Accessor
+            inline (self key)
+                local w = 0
+                local h = 0
+                SDL_GetWindowSize self.window &w &h
+                ivec2 w h
 
     inline __drop (self)
         _shutdown self.window self.glcontext

          
@@ 119,7 121,7 @@ struct GLMain
     fn run (self on-event on-draw)
         loop ()
             if (handle-events self on-event)
-                false
+                break;
             else
                 let swap? = (on-draw)
                 static-if (none? swap?)

          
@@ 127,7 129,7 @@ struct GLMain
                 else
                     if swap?
                         swap self
-                true
+                ;
 
 do
     let GLMain

          
M lib/tukan/hash.sc +1 -1
@@ 119,7 119,7 @@ fn vec3hashuv (p)
 
 ################################################################################
 
-#inline... mod_inverse_2 (a : u64)
+inline... mod_inverse_2 (a : u64)
     x := (a * a) + a - 1:u64 # 4
     x := x * (2:u64 - a * x) # 8
     x := x * (2:u64 - a * x) # 16

          
M lib/tukan/imgui/init.sc +8 -4
@@ 408,13 408,17 @@ typedef+ ImMemoryEditor
         igMemoryEditor_DrawWindow &self title mem_data mem_size base_display_addr
 
 typedef+ (mutable pointer ImGuiViewport)
-    fn GetWorkPos (self)
+    inline GetWorkPos (self)
+        self.WorkPos
+    inline GetWorkSize (self)
+        self.WorkSize
+    fn GetWorkCenter (self)
         local out : ImVec2
-        ImGuiViewport_GetWorkPos &out self
+        ImGuiViewport_GetWorkCenter &out self
         ImVec2->vec2 out
-    fn GetWorkSize (self)
+    fn GetCenter (self)
         local out : ImVec2
-        ImGuiViewport_GetWorkSize &out self
+        ImGuiViewport_GetCenter &out self
         ImVec2->vec2 out
 
 typedef+ ImVec2

          
M lib/tukan/nanovg/C.sc +4 -2
@@ 3,10 3,11 @@ using import glm
 
 import ..core
 using import ..gl
+using import ..globals
 
 let nvg =
     include
-        options "-I" (module-dir .. "/../../cdefs")
+        options "-I" cdefs-dir "-I" include-dir
         """"#include "nanovg.h"
             #define GLuint unsigned
             #define NANOVG_GL3

          
@@ 42,7 43,8 @@ do
         GL.Clear
             | GL.STENCIL_BUFFER_BIT
                 GL.DEPTH_BUFFER_BIT
-        nvgBeginFrame vg size.x size.y 1
+        fsize := (vec2 size)
+        nvgBeginFrame vg fsize.x fsize.y 1
 
     typedef+ NVGcolor
         inline __rimply (T cls)

          
M testing/test_cadag_gui.sc +67 -54
@@ 26,20 26,27 @@ from GUIDAG let AnyId NoId
 do
     from (methodsof GUIDAG) let define-type
 
-    define-type "str" (RIFF "TEXT") (tuple (chars = (array char)))
-    define-type "vbox" (RIFF "VBOX") (tuple (items = (array AnyId)))
-    define-type "hbox" (RIFF "HBOX") (tuple (items = (array AnyId)))
+    define-type "text" (RIFF "TEXT") (tuple (chars = (array char)))
+    define-type "cell" (RIFF "CELL") (tuple (values = (array AnyId)))
 
     ;
 
 #-------------------------------------------------------------------------------
 
+struct LayoutInfo plain
+    size : vec2 # original computed size
+    offset : vec2 # offset of the node within the current tree
+
 struct App
     module : GUIDAG
     root : AnyId
+    # column:line
+    cursor : uvec2
+    # pointer coordinates
+    #pointer : ivec2
 
-    # temporaries
-    rects : (Array vec4)
+    # layout temporaries
+    layout : (Array LayoutInfo)
 
 global app : App
 

          
@@ 99,6 106,9 @@ global dockgui =
         height = 540
         resizable = true
 
+let CELL_MARGIN = 2.0
+let CELL_ROUNDING = 3.0
+
 inline set-value (arr id value)
     idx := id as u32
     if ((countof arr) <= idx)

          
@@ 117,18 127,18 @@ type+ App
 
     fn setup-test-dag (self)
         from self let module
-        from (methodsof module.builder) let str vbox hbox
+        from (methodsof module.builder) let text cell
         let longstr =
-            str "The quick brown fox jumped over the lazy dog"
+            text "The quick brown fox jumped over the lazy dog"
         let abcd =
-            hbox
-                str "A"
-                str "B"
-                str "C"
-                str "D"
+            cell
+                text "A"
+                text "B"
+                text "C"
+                text "D"
         self.root =
-            vbox longstr
-                hbox abcd abcd abcd
+            cell longstr
+                cell abcd abcd abcd
                 longstr
         'dump module self.root
         ;

          
@@ 136,40 146,41 @@ type+ App
 
     fn on-define-dock (self dockgui)
         # collect sizes
-        from self let rects module root
-        'clear rects
+        WithBegin "GUIDAG";
+        PushFont dockgui.FixedFont
+        from self let layout module root
+        'clear layout
         'descend module root
             on-leave =
-                capture (module id) {&rects}
+                capture (module id) {&layout}
                     let handle = ('handleof module id)
                     inline get (id)
-                        rects @ id
+                        layout @ id
                     vvv bind size
                     dispatch handle
-                    case str (str)
-                        vec4 0 0
-                            CalcTextSize (& (str.chars @ 0))
-                    case hbox (hbox)
+                    case text (text)
+                        CalcTextSize (& (text.chars @ 0))
+                    #case hbox (hbox)
                         vec4 0 0
                             fold (w h = 0.0 0.0) for src in ('sources handle)
-                                let __ __ cw ch = (unpack (get src))
-                                _ (w + cw) (max h ch)
-                    case vbox (vbox)
-                        vec4 0 0
-                            fold (w h = 0.0 0.0) for src in ('sources handle)
-                                let __ __ cw ch = (unpack (get src))
-                                _ (max w cw) (h + ch)
+                                let l = (get src)
+                                _ (w + l.size.x) (max h l.size.y)
+                    case cell (cell)
+                        + (2 * CELL_MARGIN)
+                            vec2
+                                fold (w h = 0.0 0.0) for src in ('sources handle)
+                                    let x y = (unpack ((get src) . size))
+                                    _ (max w x) (h + y)
                     default
-                        vec4 0
-                    set-value rects id size
+                        vec2 0
+                    set-value layout id
+                        LayoutInfo
+                            size = size
                     ;
-        WithBegin "GUIDAG";
-        #Text "second"
-        # draw rects
         dl := (GetWindowDrawList)
         do
             let wp = (GetCursorScreenPos)
-            let x y w h = (unpack (rects @ root))
+            let x y = (unpack (layout @ root . offset))
             x = wp.x
             y = wp.y
             ;

          
@@ 178,7 189,7 @@ type+ App
         #local seen : (Set u64)
         'descend module root
             on-enter-param =
-                capture (module parentid index id) {&rects dl &hstack}
+                capture (module parentid index id) {&layout dl &hstack}
                     hstack =
                         hpush (hpush hstack ((hash index) as integer))
                             (hash id) as integer

          
@@ 186,28 197,29 @@ type+ App
                         return true
                     let handle = ('handleof module parentid)
                     inline get (id)
-                        rects @ id
-                    let rc = (get parentid)
+                        layout @ id
+                    let parentl = (get parentid)
                     dispatch handle
-                    case hbox (hbox)
+                    #case hbox (hbox)
                         if (index == 0)
-                            let pos = (rc.xy as vec2)
-                            let sz = (rc.zw as vec2)
+                            let pos = parentl.offset
+                            let sz = parentl.size
                             'AddRect dl pos (pos + sz) 0xff808080
                         let src = (get (hbox.items @ index))
                         src.x = rc.x
                         src.y = rc.y
                         rc.x += src.z
                         ;
-                    case vbox (vbox)
+                    case cell (cell)
                         if (index == 0)
-                            let pos = (rc.xy as vec2)
-                            let sz = (rc.zw as vec2)
+                            let pos = parentl.offset
+                            let sz = parentl.size
+                            let margin = 1
                             'AddRect dl pos (pos + sz) 0xff808080
-                        let src = (get (vbox.items @ index))
-                        src.x = rc.x
-                        src.y = rc.y
-                        rc.y += src.w
+                                rounding = CELL_ROUNDING
+                        let src = (get (cell.values @ index))
+                        src.offset = parentl.offset + CELL_MARGIN
+                        parentl.offset.y += src.size.y
                         ;
                     default;
                     true

          
@@ 218,21 230,22 @@ type+ App
                             (hash index) as integer
                     ;
             on-leave =
-                capture (module id) {&rects dl &hstack}
+                capture (module id) {&layout dl &hstack}
                     let hid = (deref hstack)
                     #assert (not (hid in seen))
                     #'insert seen hid
                     let handle = ('handleof module id)
                     inline get (id)
-                        rects @ id
+                        layout @ id
                     dispatch handle
-                    case str (str)
-                        let rc = (get id)
-                        let pos = (rc.xy as vec2)
-                        'AddText dl pos 0xffffffff (& (str.chars @ 0))
+                    case text (text)
+                        let l = (get id)
+                        let pos = l.offset
+                        'AddText dl pos 0xffffffff (& (text.chars @ 0))
                     default;
                     ;
         #'ChannelsMerge dl
+        PopFont;
 
     fn init (self)
         #on-module-changed self

          
M testing/test_nanovg.sc +16 -12
@@ 1,14 1,16 @@ 
 
 using import glm
 using import glsl
-
-using import ..tukan.sdl
-using import ..tukan.GLMain
+using import Capture
 
-using import ..tukan.gl
-using import ..tukan.nanovg
+import ..lib.tukan.use
+using import tukan.sdl
+using import tukan.GLMain
 
-let glmain =
+using import tukan.gl
+using import tukan.nanovg
+
+local glmain =
     GLMain
         title = "NanoVG test"
         width = 960

          
@@ 19,7 21,7 @@ global vg = (NanoVG.create NanoVG.Antial
 
 global monofont =
     'create-font vg "fixed"
-        .. module-dir "/../assets/core/fonts/UbuntuMono-R.ttf"
+        .. module-dir "/../share/tukan/fonts/UbuntuMono-R.ttf"
 
 global cursor = (ivec2 100 100)
 

          
@@ 51,16 53,18 @@ fn render-view (size)
 
     'end-frame vg
 
-@@ 'on GLMain.on-event
-fn (event glmain)
+capture on-event (event) {}
     if event.type == SDL_MOUSEMOTION
         cursor =
             ivec2
                 event.motion.x
                 event.motion.y
 
-@@ 'on GLMain.on-draw
-fn (time size glmain)
-    render-view size
+capture on-draw () {&glmain}
+    render-view glmain.size
+    ;
 
 'run glmain
+    on-event
+    on-draw
+