Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UncheckedArray #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Patitotective
Copy link

@Patitotective Patitotective commented Apr 10, 2022

Edited imgui.nim:

  • ImVector.data: UncheckedArray[T] -> ptr UncheckedArray[T]
  • ImDrawList.cmdLists: UncheckedArray[ptr ImDrawList] -> ptr UncheckedArray[ptr ImDrawList]

Usage Example

import nimgl/imgui, nimgl/imgui/[impl_opengl, impl_glfw]
import nimgl/[opengl, glfw]

proc main() =
  doAssert glfwInit()

  glfwWindowHint(GLFWContextVersionMajor, 3)
  glfwWindowHint(GLFWContextVersionMinor, 3)
  glfwWindowHint(GLFWOpenglForwardCompat, GLFW_TRUE)
  glfwWindowHint(GLFWOpenglProfile, GLFW_OPENGL_CORE_PROFILE)
  glfwWindowHint(GLFWResizable, GLFW_FALSE)

  var w: GLFWWindow = glfwCreateWindow(1280, 720)
  if w == nil:
    quit(-1)

  w.makeContextCurrent()

  doAssert glInit()

  let context = igCreateContext()
  #let io = igGetIO()

  doAssert igGlfwInitForOpenGL(w, true)
  doAssert igOpenGL3Init()

  igStyleColorsCherry()

  while not w.windowShouldClose:
    glfwPollEvents()

    igOpenGL3NewFrame()
    igGlfwNewFrame()
    igNewFrame()

    # Simple window
    igBegin("Hello, world!")

    var filter: ImGuiTextFilter # Before it complained Error: invalid type: 'UncheckedArray[ImGuiTextRange]' in this context: 'ImGuiTextFilter' for var
    filter.addr.draw()
    
    for line in ["aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world"]:
      if filter.addr.passFilter(line):
        igBulletText("%s", line)

    igEnd()
    # End simple window

    igRender()

    glClearColor(0.45f, 0.55f, 0.60f, 1.00f)
    glClear(GL_COLOR_BUFFER_BIT)

    igOpenGL3RenderDrawData(igGetDrawData())

    w.swapBuffers()

  igOpenGL3Shutdown()
  igGlfwShutdown()
  context.igDestroyContext()

  w.destroyWindow()
  glfwTerminate()

main()

Edited `imgui.nim` so `ImVector.data` is of type `ptr UncheckedArray[T]` instead of `UncheckedArray[T]`
@Patitotective Patitotective changed the title Fixed data field in ImVector Fixed UncheckedArray Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant