borodust / bodge-ui

High-level immediate mode user interface library based on Nuklear IM GUI library
MIT License
15 stars 1 forks source link

How do you get text out of a text-edit element? #15

Closed jonprairie closed 4 years ago

jonprairie commented 4 years ago

I'm trying out bodge-ui-window, I created a text-edit element and tried navigating to it via the slime-inspector: main-window->nuklear-context->panels->children->text-edit. I brought it over to the slime repl and called text-of on it and it drops me into the slime debugger:

The value
  (%NUKLEAR:LEN 4 %NUKLEAR:BUFFER
   (%NUKLEAR:SIZE 32 %NUKLEAR:CALLS 4 %NUKLEAR:NEEDED 4
    %NUKLEAR:ALLOCATED 4 %NUKLEAR:GROW-FACTOR 2.0
    %NUKLEAR:MEMORY
    (%NUKLEAR:SIZE 32 %NUKLEAR:PTR
     #.(SB-SYS:INT-SAP #X7FFFC856C180))
    %NUKLEAR:TYPE :DYNAMIC %NUKLEAR:POOL
    (%NUKLEAR:FREE #.(SB-SYS:INT-SAP #X7FFFEE125170)
                   %NUKLEAR:ALLOC
                   #.(SB-SYS:INT-SAP #X7FFFEE125180)
                   %NUKLEAR:USERDATA
                   #.(SB-SYS:INT-SAP #X7FFFC8568298))
    %NUKLEAR:MARKER (%NUKLEAR:OFFSET 0 %NUKLEAR:ACTIVE 0)))

is not of type
  SB-SYS:SYSTEM-AREA-POINTER
when binding SB-ALIEN::VALUE
   [Condition of type TYPE-ERROR]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {10025703E3}>)

Backtrace:
  0: (%NUKLEAR:STR-LEN-CHAR (%NUKLEAR:LEN 4 %NUKLEAR:BUFFER (%NUKLEAR:SIZE 32 %NUKLEAR:CALLS 4 %NUKLEAR:NEEDED 4 ...)))
  1: ((:METHOD TEXT-OF (TEXT-EDIT)) #<TEXT-EDIT {1009F1FEF3}>) [fast-method]
  2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (TEXT-OF *) #<NULL-LEXENV>)
  3: (EVAL (TEXT-OF *))
 --more--

I'm not sure what I'm doing wrong, is this expected? Is there a standard way to get the text out of a text-edit element?

Thanks for taking a look!

borodust commented 4 years ago

You are probably using outdated version from main quicklisp dist. Do

(ql-dist:install-dist "http://bodge.borodust.org/dist/org.borodust.bodge.testing.txt")

And try again.

jonprairie commented 4 years ago

I tried adding the testing dist and running ql:update-all-dists, then loading the system in a clean slime repl and it still blows up. I did a ql:where-is-system on bodge-ui just to make sure and it returned #P"/home/jonnyp/quicklisp/dists/org.borodust.bodge.testing/software/bodge-ui-20200418160241/", which looks right to me.

For reference, here's the test code I'm using:

(defpackage #:ctj.testing
  (:nicknames :test)
  (:use :cl :bodge-ui :bodge-ui-window :bodge-host))

(in-package :test)

(defparameter *game-window* nil)

(defparameter *window-width* 800)
(defparameter *window-height* 600)

(defpanel
    (main-panel
     (:title "Main Menu")
     (:origin 100 100)
     (:width 200)
     (:height 400)
     (:options))
  (vertical-layout
   (button :label "Continue")
   (button :label "New Game")
   (button :label "Load Game")
   (button :label "Options")
   (button :label "Exit" :on-click (lambda (panel) (close-window *game-window*)))))

(defpanel
    (new-game
     (:title "New Game")
     (:origin 400 100)
     (:width 200)
     (:height 400)
     (:options))
  (vertical-layout
   (float-property
    :start 1200
    :end 2200
    :step 1
    :increment 1f0
    :value 1500)
   (text-edit)))

(defclass main-window (ui-window) ()
  (:default-initargs
   :title "testing"
    :width *window-width*
    :height *window-height*
    :panels '(main-panel new-game)
    :floating t))

(defun run () (open-window (setf *game-window* (make-instance 'main-window))))

Then I inspect *game-window* and drill down through ui-context -> panels -> new-game -> children -> vertical-layout -> children -> text-edit, I bring the text-edit element over to the slime repl and call text-of on it, and that's where it's blowing up for me.

I tried exploring a bit, messing with the text-of method, but I'm hopeless with C and couldn't follow what was happening in the nuklear stuff with the claw wrapper x).

borodust commented 4 years ago

Indeed, I thought I've fixed the problem earlier, but apparently that's the different one. Fixed in https://github.com/borodust/bodge-ui/commit/fba64e80cd8031e9bd443dc7fbada4bb36162189 I also updated drawing example of bodge-ui-window to demonstrate how to get text from text-edit. Fix should be in testing dist in an hour. Don't forget to

(ql:update-all-dists)

Thanks for the report! Feel free to reopen the issue if problem ain't gone for you after testing dist update.

borodust commented 4 years ago

If you are wondering what was happening, actual fix is in this line: https://github.com/borodust/bodge-ui/commit/fba64e80cd8031e9bd443dc7fbada4bb36162189#diff-3c73591d7526e1e6bd0e2d323d305bbdR28 Structure was passed as an argument to %nk:str-len-char, but this function expects a pointer to the structure instead.

jonprairie commented 4 years ago

Updated and tested, everything's looking good. Thanks!