<commit_before>package imgui.internal.api

import glm_.func.common.max
import glm_.parseInt
import imgui.*
import imgui.ImGui.clearActiveID
import imgui.ImGui.closePopupsOverWindow
import imgui.ImGui.io
import imgui.api.g
import imgui.classes.DrawList
import imgui.font.Font
import imgui.internal.sections.NavLayer
import imgui.internal.classes.ShrinkWidthItem
import imgui.internal.classes.Window
import imgui.internal.hash
import imgui.static.findWindowFocusIndex
import imgui.static.navRestoreLastChildNavWindow
import java.util.*
import java.util.regex.Pattern
import imgui.WindowFlag as Wf


@Suppress("UNCHECKED_CAST")

internal interface internal {

    // Windows

    /** We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
     *  If this ever crash because g.CurrentWindow is NULL it means that either
     *  - ImGui::NewFrame() has never been called, which is illegal.
     *  - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. */

    /** ~GetCurrentWindowRead */
    val currentWindowRead: Window?
        get() = g.currentWindow

    /** ~GetCurrentWindow */
    val currentWindow: Window
        get() = g.currentWindow?.apply { writeAccessed = true } ?: throw Error("""
                We should always have a CurrentWindow in the stack (there is an implicit \"Debug\" window)
                If this ever crash because ::currentWindow is NULL it means that either
                - ::newFrame() has never been called, which is illegal.
                - You are calling ImGui functions after ::render() and before the next ::newFrame(), which is also illegal.
                - You are calling ImGui functions after ::endFrame()/::render() and before the next ImGui::newFrame(), which is also illegal.
                """.trimIndent())

    fun findWindowByID(id: ID): Window? = g.windowsById[id]

    fun findWindowByName(name: String): Window? = g.windowsById[hash(name)]


    // Windows: Display Order and Focus Order

    /** Moving window to front of display (which happens to be back of our sorted list)  ~ FocusWindow  */
    fun focusWindow(window: Window? = null) {

        if (g.navWindow !== window) {
            g.navWindow = window
            if (window != null && g.navDisableMouseHover)
                g.navMousePosDirty = true
            g.navInitRequest = false
            g.navId = window?.navLastIds?.get(0) ?: 0 // Restore NavId
            g.navFocusScopeId = 0
            g.navIdIsAlive = false
            g.navLayer = NavLayer.Main
            //IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL);
        }

        // Close popups if any
        closePopupsOverWindow(window, false)

        // Passing NULL allow to disable keyboard focus
        if (window == null) return

        // Move the root window to the top of the pile
        val focusFrontWindow = window.rootWindow!! // NB: In docking branch this is window->RootWindowDockStop
        val displayFrontWindow = window.rootWindow!!

        // Steal focus on active widgets
        if (focusFrontWindow.flags has Wf._Popup) // FIXME: This statement may be unnecessary? Need further testing before removing it..
            if (g.activeId != 0 && g.activeIdWindow != null && g.activeIdWindow!!.rootWindow != focusFrontWindow)
                clearActiveID()

        // Bring to front
        focusFrontWindow.bringToFocusFront()
        if ((window.flags or displayFrontWindow.flags) hasnt Wf.NoBringToFrontOnFocus)
            displayFrontWindow.bringToDisplayFront()
    }

    fun focusTopMostWindowUnderOne(underThisWindow: Window? = null, ignoreWindow: Window? = null) {
        var startIdx = g.windowsFocusOrder.lastIndex
        underThisWindow?.let {
            val underThisWindowIdx = findWindowFocusIndex(it)
            if (underThisWindowIdx != -1)
                startIdx = underThisWindowIdx - 1
        }
        for (i in startIdx downTo 0) {
            // We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user.
            val window = g.windowsFocusOrder[i]
            if (window !== ignoreWindow && window.wasActive && window.flags hasnt Wf._ChildWindow)
                if ((window.flags and (Wf.NoMouseInputs or Wf.NoNavInputs)) != (Wf.NoMouseInputs or Wf.NoNavInputs)) {
                    focusWindow(navRestoreLastChildNavWindow(window))
                    return
                }
        }
        focusWindow()
    }

    // the rest of the window related functions is inside the corresponding class


    // Fonts, drawing<commit_msg>:construction:   FocusWindow(NULL) correctly steal active id from previous window. (#1738) amend b0a9bbf<commit_after>package imgui.internal.api

import glm_.func.common.max
import glm_.parseInt
import imgui.*
import imgui.ImGui.clearActiveID
import imgui.ImGui.closePopupsOverWindow
import imgui.ImGui.io
import imgui.api.g
import imgui.classes.DrawList
import imgui.font.Font
import imgui.internal.sections.NavLayer
import imgui.internal.classes.ShrinkWidthItem
import imgui.internal.classes.Window
import imgui.internal.hash
import imgui.static.findWindowFocusIndex
import imgui.static.navRestoreLastChildNavWindow
import java.util.*
import java.util.regex.Pattern
import imgui.WindowFlag as Wf


@Suppress("UNCHECKED_CAST")

internal interface internal {

    // Windows

    /** We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
     *  If this ever crash because g.CurrentWindow is NULL it means that either
     *  - ImGui::NewFrame() has never been called, which is illegal.
     *  - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal. */

    /** ~GetCurrentWindowRead */
    val currentWindowRead: Window?
        get() = g.currentWindow

    /** ~GetCurrentWindow */
    val currentWindow: Window
        get() = g.currentWindow?.apply { writeAccessed = true } ?: throw Error("""
                We should always have a CurrentWindow in the stack (there is an implicit \"Debug\" window)
                If this ever crash because ::currentWindow is NULL it means that either
                - ::newFrame() has never been called, which is illegal.
                - You are calling ImGui functions after ::render() and before the next ::newFrame(), which is also illegal.
                - You are calling ImGui functions after ::endFrame()/::render() and before the next ImGui::newFrame(), which is also illegal.
                """.trimIndent())

    fun findWindowByID(id: ID): Window? = g.windowsById[id]

    fun findWindowByName(name: String): Window? = g.windowsById[hash(name)]


    // Windows: Display Order and Focus Order

    /** Moving window to front of display (which happens to be back of our sorted list)  ~ FocusWindow  */
    fun focusWindow(window: Window? = null) {

        if (g.navWindow !== window) {
            g.navWindow = window
            if (window != null && g.navDisableMouseHover)
                g.navMousePosDirty = true
            g.navInitRequest = false
            g.navId = window?.navLastIds?.get(0) ?: 0 // Restore NavId
            g.navFocusScopeId = 0
            g.navIdIsAlive = false
            g.navLayer = NavLayer.Main
            //IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL);
        }

        // Close popups if any
        closePopupsOverWindow(window, false)

        // Move the root window to the top of the pile
        assert(window == null || window.rootWindow != null)
        val focusFrontWindow = window?.rootWindow // NB: In docking branch this is window->RootWindowDockStop
        val displayFrontWindow = window?.rootWindow

        // Steal focus on active widgets
        if (g.activeId != 0 && g.activeIdWindow?.rootWindow !== focusFrontWindow)
            clearActiveID()

        // Passing NULL allow to disable keyboard focus
        if (window == null)
            return

        // Bring to front
        focusFrontWindow!!.bringToFocusFront()
        if ((window.flags or displayFrontWindow!!.flags) hasnt Wf.NoBringToFrontOnFocus)
            displayFrontWindow.bringToDisplayFront()
    }

    fun focusTopMostWindowUnderOne(underThisWindow: Window? = null, ignoreWindow: Window? = null) {
        var startIdx = g.windowsFocusOrder.lastIndex
        underThisWindow?.let {
            val underThisWindowIdx = findWindowFocusIndex(it)
            if (underThisWindowIdx != -1)
                startIdx = underThisWindowIdx - 1
        }
        for (i in startIdx downTo 0) {
            // We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user.
            val window = g.windowsFocusOrder[i]
            if (window !== ignoreWindow && window.wasActive && window.flags hasnt Wf._ChildWindow)
                if ((window.flags and (Wf.NoMouseInputs or Wf.NoNavInputs)) != (Wf.NoMouseInputs or Wf.NoNavInputs)) {
                    focusWindow(navRestoreLastChildNavWindow(window))
                    return
                }
        }
        focusWindow()
    }

    // the rest of the window related functions is inside the corresponding class


    // Fonts, drawing
{'fraction_non_alphanumeric': 0.09023511967803431, 'fraction_numerical': 0.0021181952976064393, 'mean_word_length': 2.5782493368700266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6714469', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2495, 'n_words': 822}