DTextEntry troubles

Hello there.

I’m having troubles with the DTextEntry not focusing. The DTextEntry is parented to a DPanel, if I try using DTextEntry:MakePopup(), it replaces it using the toscreen positions, which ends up being on the top left of the screen. If I try to replace the DTextEntry positions with localtoscreen positions, it just offsets it a small bit to the right or left, and not doing what I’m asking it to do.

This code includes the panel on which the DTextEntry is parent to and the DTextEntry


local function switchTab(wp, tab)
    if tab.canSwitch and not tab.canSwitch() then return false end

    wp:Clear(function()
      tab.run(wp) --Run the tab
      wp:FadeInChildren()
    end)

    return true
  end

  local curStep
  local payload = {}
  parent.steps = {
    ["Character Details"] = { --There's other things in the table but they don't really matter
      index = 2,
      run = function(panel)
        local mdl = panel:Add("DModelPanel")
        mdl:SetSize(panel:GetWide()*0.5,panel:GetTall()-70)
        mdl:SetModel(payload.model)
        function mdl:LayoutEntity(ent)
          self:RunAnimation()
          ent:SetAngles(Angle(0,45,0))
          ent:ResetSequence(2)
        end

        local infos = panel:Add("DPanel")
        infos:SetSize(panel:GetWide()/2-20,panel:GetTall()/1.5)
        infos:SetPos(panel:GetWide()/2-10,0)
        infos:CenterVertical()
        function infos:Paint(w,h)
          draw.RoundedBox(4,0,0,w,h,Color(150,150,150,80))
        end

        local fn = infos:Add("DLabel")
        fn:SetText("Firstname")
        fn:SetFont("nutMediumFont")
        fn:SetColor(color_white)
        fn:SizeToContents()
        fn:CenterHorizontal()
        fn:CenterVertical(0.3)

        local x,y = fn:LocalToScreen(fn:GetPos())
        local fnEdit = infos:Add("DTextEntry")
        fnEdit:SetSize(200,30)
        fnEdit:SetPos(x-100,y+fn:GetTall()+10)
        fnEdit:SetMouseInputEnabled(true)
        fnEdit:SetKeyBoardInputEnabled(true)
      end,
      canSwitch = function()
        if payload.model then
          return true
        end

        return false
      end
    },
  }

  parent.wp = parent:Add("DPanel") --The panel the tabs will be displayed on
  parent.wp:SetSize(parent:GetWide(),parent:GetTall()*0.8)
  function parent.wp:FadeInChildren()
    for _,pnl in pairs(self:GetChildren()) do
      pnl:SetAlpha(0)
      pnl:AlphaTo(255,0.2)
    end
  end
  function parent.wp:Clear(callback)
    for _,pnl in pairs(self:GetChildren()) do
      pnl:AlphaTo(0,0.2,0,function()
        if pnl and IsValid(pnl) then
          pnl:Remove()
        end
      end)
    end

    if callback then
      timer.Simple(0.2,function()
        callback()
      end)
    end
  end
  function parent.wp:Paint(w,h) end

  local stepPanel = parent:Add("DPanel") --The panel to display how many steps there is and navigate through them
  stepPanel:SetSize(300,60)
  stepPanel:CenterHorizontal()
  stepPanel:CenterVertical(0.9)
  stepPanel.displayText = ""
  stepPanel.textChangeTime = CurTime()
  function stepPanel:Paint(w,h)
    if self.textChangeTime >= CurTime() then
      draw.DrawText(self.displayText,"nutSmallFont",w/2,h-self:GetTall()*0.25,color_white,TEXT_ALIGN_CENTER)
    else
      local dt = CurTime()-self.textChangeTime
      draw.DrawText(self.displayText,"nutSmallFont",w/2,h-self:GetTall()*0.25,Color(255,255,255,Lerp(dt,255,0)),TEXT_ALIGN_CENTER)
    end
  end

  local count = 0
  for k,v in SortedPairsByMemberValue(parent.steps,"index") do --Display tabs
    local s = stepPanel:Add("DButton")
    s:SetText("")
    s:SetPos(0 + (stepPanel:GetWide()/table.Count(parent.steps)) * count, 0)
    s:SetSize(stepPanel:GetWide()/table.Count(parent.steps),stepPanel:GetTall())
    s:CenterVertical()
    parent.steps[k].panel = s
    function s:Think()
      if self:IsHovered() then
        stepPanel.displayText = k
        stepPanel.textChangeTime = CurTime()+2
      end
    end
    function s:Paint(w,h)
      draw.NoTexture()
      if self == curStep then
        surface.SetDrawColor(255,255,255)
        draw.Circle(w/2, h/2-10, 10, 6)
      else
        surface.SetDrawColor(160,160,160)
        draw.Circle(w/2, h/2-10, 8, 6)
      end
    end
    function s:DoClick()
      if switchTab(parent.wp, v) then
        curStep = s
      end
    end

    --Setting default
    if v.default then
      s.DoClick(s)
    end

    count = count + 1
  end

Sorry for any grammar mistake English is not my main language :slight_smile:
~Robert

Thanks for any help

Where is the rest of the code? And please embed code into your post using code tags.

There you go, I put a lot more code and embedded it in the thread. Sorry I’m a bit conservative about my code :stuck_out_tongue: