1. Welcome to the Starbound support forums. Please check the support FAQs before posting: http://playstarbound.com/support

Bug/Issue Canvas & TextBox

Discussion in 'Starbound Support' started by Degranon, May 9, 2018.

  1. Degranon

    Degranon Scruffy Nerf-Herder

    Hey there, modding report here!

    ISSUE:
    When having a canvas, which catches the key presses, and a textbox, you seem to be unable to write anything inside it. Moreover:
    1. The textbox callback is being triggered by writing keys
    2. You can manipulate the text with Ctrl+C Ctrl+V and backspace inside the textbox
    3. Focusing the textbox with widget.focus and blurring the canvas with widget.blur doesn't help with the issue.
    WAY TO REPRODUCE:
    There's a simple example of the issue:

    Code:
    {
      "gui" : {
        "background": {
          "type": "background",
          "fileBody": "/interface/monstercontroller/body.png"
        },
        "keyCanvas": {
          "type": "canvas",
          "rect": [0, 0, 1, 1],
          "focus": true,
          "captureKeyboardEvents" : true
        },
        "chatTextBox": {
          "type": "textbox",
          "position": [400, 150], 
          "hint": "Write here",
          "hAnchor": "mid",
          "visible": false,
          "enterKey": "say",
          "escapeKey": "cancel"
        }
      },
      "scriptWidgetCallbacks": ["chatTextBox", "say", "cancel"],
      "canvasKeyCallbacks" : {
        "keyCanvas" : "canvasKeyEvent"
      },
      "scripts": ["/interface/monstercontroller/monstercontrollergui.lua"]
    }
    lua:
    Code:
    function canvasKeyEvent(key, isKeyDown)
        if self.controls[key] then
            self.controls[key](isKeyDown)
        end
    end
    
    self.controls = {
            -- enterKey
            [3] = function()
                widget.setVisible("chatTextBox", true)
                widget.blur("keyCanvas")
                widget.focus("chatTextBox")
            end
    
    POSSIBLE FIXES:
    I believe it's something related to canvas capturing the keypresses, so, for example, making a function to toggle the capturing on and off would fix the issue
     

Share This Page