Skip to content

Commit

Permalink
Merge pull request #2 from AustinEast/docking-impl
Browse files Browse the repository at this point in the history
Update Dear Imgui to 1.79 with Docking Feature
  • Loading branch information
haddock7 authored Oct 22, 2020
2 parents e17499b + 87d20a2 commit e9893e3
Show file tree
Hide file tree
Showing 14 changed files with 10,240 additions and 2,452 deletions.
12 changes: 12 additions & 0 deletions extension/docking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#define HL_NAME(n) hlimgui_##n

#include <hl.h>
#include "imgui/imgui.h"
#include "utils.h"

HL_PRIM void HL_NAME(dock_space)(int id, vdynamic* size, ImGuiDockNodeFlags* flags)
{
ImGui::DockSpace(ImGuiID(id), getImVec2(size), convertPtr(flags, 0));
}

DEFINE_PRIM(_VOID, dock_space, _I32 _DYN _REF(_I32));
4 changes: 3 additions & 1 deletion extension/hlimgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ HL_PRIM vdynamic* HL_NAME(initialize)(vclosure* render_fn)
ImGuiIO& io = ImGui::GetIO();

// set render draw function
io.RenderDrawListsFn = renderDrawLists;
s_render_function = render_fn;
hl_add_root(&s_render_function);

Expand Down Expand Up @@ -202,6 +201,9 @@ HL_PRIM void HL_NAME(end_frame)()
HL_PRIM void HL_NAME(render)()
{
ImGui::Render();

ImDrawData* draw_data = ImGui::GetDrawData();
renderDrawLists(draw_data);
}

DEFINE_PRIM(_DYN, initialize, _FUN(_VOID, _DYN));
Expand Down
13 changes: 7 additions & 6 deletions extension/imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h)
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include
// the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
//-----------------------------------------------------------------------------
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -75,12 +76,12 @@
*/

//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bit indices).
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
//#define ImDrawIdx unsigned int

//---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
//struct ImDrawList;
//struct ImDrawCmd;
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
Expand Down
7,184 changes: 6,384 additions & 800 deletions extension/imgui/imgui.cpp

Large diffs are not rendered by default.

900 changes: 645 additions & 255 deletions extension/imgui/imgui.h

Large diffs are not rendered by default.

1,204 changes: 891 additions & 313 deletions extension/imgui/imgui_demo.cpp

Large diffs are not rendered by default.

711 changes: 470 additions & 241 deletions extension/imgui/imgui_draw.cpp

Large diffs are not rendered by default.

624 changes: 476 additions & 148 deletions extension/imgui/imgui_internal.h

Large diffs are not rendered by default.

1,924 changes: 1,268 additions & 656 deletions extension/imgui/imgui_widgets.cpp

Large diffs are not rendered by default.

80 changes: 55 additions & 25 deletions extension/imgui/imstb_textedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
// STB_TEXTEDIT_K_RIGHT keyboard input to move cursor right
// STB_TEXTEDIT_K_UP keyboard input to move cursor up
// STB_TEXTEDIT_K_DOWN keyboard input to move cursor down
// STB_TEXTEDIT_K_PGUP keyboard input to move cursor up a page
// STB_TEXTEDIT_K_PGDOWN keyboard input to move cursor down a page
// STB_TEXTEDIT_K_LINESTART keyboard input to move cursor to start of line // e.g. HOME
// STB_TEXTEDIT_K_LINEEND keyboard input to move cursor to end of line // e.g. END
// STB_TEXTEDIT_K_TEXTSTART keyboard input to move cursor to start of text // e.g. ctrl-HOME
Expand All @@ -170,14 +172,10 @@
// STB_TEXTEDIT_K_TEXTSTART2 secondary keyboard input to move cursor to start of text
// STB_TEXTEDIT_K_TEXTEND2 secondary keyboard input to move cursor to end of text
//
// Todo:
// STB_TEXTEDIT_K_PGUP keyboard input to move cursor up a page
// STB_TEXTEDIT_K_PGDOWN keyboard input to move cursor down a page
//
// Keyboard input must be encoded as a single integer value; e.g. a character code
// and some bitflags that represent shift states. to simplify the interface, SHIFT must
// be a bitflag, so we can test the shifted state of cursor movements to allow selection,
// i.e. (STB_TEXTED_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow.
// i.e. (STB_TEXTEDIT_K_RIGHT|STB_TEXTEDIT_K_SHIFT) should be shifted right-arrow.
//
// You can encode other things, such as CONTROL or ALT, in additional bits, and
// then test for their presence in e.g. STB_TEXTEDIT_K_WORDLEFT. For example,
Expand Down Expand Up @@ -337,6 +335,10 @@ typedef struct
// each textfield keeps its own insert mode state. to keep an app-wide
// insert mode, copy this value in/out of the app state

int row_count_per_page;
// page size in number of row.
// this value MUST be set to >0 for pageup or pagedown in multilines documents.

/////////////////////
//
// private data
Expand Down Expand Up @@ -855,12 +857,16 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
break;

case STB_TEXTEDIT_K_DOWN:
case STB_TEXTEDIT_K_DOWN | STB_TEXTEDIT_K_SHIFT: {
case STB_TEXTEDIT_K_DOWN | STB_TEXTEDIT_K_SHIFT:
case STB_TEXTEDIT_K_PGDOWN:
case STB_TEXTEDIT_K_PGDOWN | STB_TEXTEDIT_K_SHIFT: {
StbFindState find;
StbTexteditRow row;
int i, sel = (key & STB_TEXTEDIT_K_SHIFT) != 0;
int i, j, sel = (key & STB_TEXTEDIT_K_SHIFT) != 0;
int is_page = (key & ~STB_TEXTEDIT_K_SHIFT) == STB_TEXTEDIT_K_PGDOWN;
int row_count = is_page ? state->row_count_per_page : 1;

if (state->single_line) {
if (!is_page && state->single_line) {
// on windows, up&down in single-line behave like left&right
key = STB_TEXTEDIT_K_RIGHT | (key & STB_TEXTEDIT_K_SHIFT);
goto retry;
Expand All @@ -869,17 +875,25 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
if (sel)
stb_textedit_prep_selection_at_cursor(state);
else if (STB_TEXT_HAS_SELECTION(state))
stb_textedit_move_to_last(str,state);
stb_textedit_move_to_last(str, state);

// compute current position of cursor point
stb_textedit_clamp(str, state);
stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);

// now find character position down a row
if (find.length) {
float goal_x = state->has_preferred_x ? state->preferred_x : find.x;
float x;
for (j = 0; j < row_count; ++j) {
float x, goal_x = state->has_preferred_x ? state->preferred_x : find.x;
int start = find.first_char + find.length;

if (find.length == 0)
break;

// [DEAR IMGUI]
// going down while being on the last line shouldn't bring us to that line end
if (STB_TEXTEDIT_GETCHAR(str, find.first_char + find.length - 1) != STB_TEXTEDIT_NEWLINE)
break;

// now find character position down a row
state->cursor = start;
STB_TEXTEDIT_LAYOUTROW(&row, str, state->cursor);
x = row.x0;
Expand All @@ -901,17 +915,25 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,

if (sel)
state->select_end = state->cursor;

// go to next line
find.first_char = find.first_char + find.length;
find.length = row.num_chars;
}
break;
}

case STB_TEXTEDIT_K_UP:
case STB_TEXTEDIT_K_UP | STB_TEXTEDIT_K_SHIFT: {
case STB_TEXTEDIT_K_UP | STB_TEXTEDIT_K_SHIFT:
case STB_TEXTEDIT_K_PGUP:
case STB_TEXTEDIT_K_PGUP | STB_TEXTEDIT_K_SHIFT: {
StbFindState find;
StbTexteditRow row;
int i, sel = (key & STB_TEXTEDIT_K_SHIFT) != 0;
int i, j, prev_scan, sel = (key & STB_TEXTEDIT_K_SHIFT) != 0;
int is_page = (key & ~STB_TEXTEDIT_K_SHIFT) == STB_TEXTEDIT_K_PGUP;
int row_count = is_page ? state->row_count_per_page : 1;

if (state->single_line) {
if (!is_page && state->single_line) {
// on windows, up&down become left&right
key = STB_TEXTEDIT_K_LEFT | (key & STB_TEXTEDIT_K_SHIFT);
goto retry;
Expand All @@ -926,11 +948,14 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
stb_textedit_clamp(str, state);
stb_textedit_find_charpos(&find, str, state->cursor, state->single_line);

// can only go up if there's a previous row
if (find.prev_first != find.first_char) {
for (j = 0; j < row_count; ++j) {
float x, goal_x = state->has_preferred_x ? state->preferred_x : find.x;

// can only go up if there's a previous row
if (find.prev_first == find.first_char)
break;

// now find character position up a row
float goal_x = state->has_preferred_x ? state->preferred_x : find.x;
float x;
state->cursor = find.prev_first;
STB_TEXTEDIT_LAYOUTROW(&row, str, state->cursor);
x = row.x0;
Expand All @@ -952,6 +977,14 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,

if (sel)
state->select_end = state->cursor;

// go to previous line
// (we need to scan previous line the hard way. maybe we could expose this as a new API function?)
prev_scan = find.prev_first > 0 ? find.prev_first - 1 : 0;
while (prev_scan > 0 && STB_TEXTEDIT_GETCHAR(str, prev_scan - 1) != STB_TEXTEDIT_NEWLINE)
--prev_scan;
find.first_char = find.prev_first;
find.prev_first = prev_scan;
}
break;
}
Expand Down Expand Up @@ -1075,10 +1108,6 @@ static void stb_textedit_key(STB_TEXTEDIT_STRING *str, STB_TexteditState *state,
state->has_preferred_x = 0;
break;
}

// @TODO:
// STB_TEXTEDIT_K_PGUP - move cursor up a page
// STB_TEXTEDIT_K_PGDOWN - move cursor down a page
}
}

Expand Down Expand Up @@ -1134,7 +1163,7 @@ static void stb_textedit_discard_redo(StbUndoState *state)
state->undo_rec[i].char_storage += n;
}
// now move all the redo records towards the end of the buffer; the first one is at 'redo_point'
// {DEAR IMGUI]
// [DEAR IMGUI]
size_t move_size = (size_t)((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point - 1) * sizeof(state->undo_rec[0]));
const char* buf_begin = (char*)state->undo_rec; (void)buf_begin;
const char* buf_end = (char*)state->undo_rec + sizeof(state->undo_rec); (void)buf_end;
Expand Down Expand Up @@ -1350,6 +1379,7 @@ static void stb_textedit_clear_state(STB_TexteditState *state, int is_single_lin
state->initialized = 1;
state->single_line = (unsigned char) is_single_line;
state->insert_mode = 0;
state->row_count_per_page = 0;
}

// API initialize
Expand Down
6 changes: 6 additions & 0 deletions extension/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ HL_PRIM void HL_NAME(set_ini_filename)(vstring* filename)
ImGui::GetIO().IniFilename = ini_filename.c_str();
}

HL_PRIM void HL_NAME(set_config_flags)(ImGuiConfigFlags* flags)
{
ImGui::GetIO().ConfigFlags = convertPtr(flags, 0);
}

DEFINE_PRIM(_BOOL, want_capture_mouse, _NO_ARG);
DEFINE_PRIM(_BOOL, want_capture_keyboard, _NO_ARG);
DEFINE_PRIM(_VOID, set_ini_filename, _STRING);
DEFINE_PRIM(_VOID, set_config_flags, _REF(_I32));
6 changes: 3 additions & 3 deletions extension/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ HL_PRIM void HL_NAME(end_popup)()
ImGui::EndPopup();
}

HL_PRIM bool HL_NAME(open_popup_on_item_click)(vstring* str_id, ImGuiMouseButton* mouse_button)
HL_PRIM void HL_NAME(open_popup_on_item_click)(vstring* str_id, ImGuiMouseButton* mouse_button)
{
return ImGui::OpenPopupOnItemClick(convertString(str_id), convertPtr(mouse_button, 1));
ImGui::OpenPopupOnItemClick(convertString(str_id), convertPtr(mouse_button, 1));
}

HL_PRIM bool HL_NAME(is_popup_open)(vstring* str_id)
Expand All @@ -61,6 +61,6 @@ DEFINE_PRIM(_BOOL, begin_popup_context_window, _STRING _REF(_I32) _REF(_BOOL));
DEFINE_PRIM(_BOOL, begin_popup_context_void, _STRING _REF(_I32));
DEFINE_PRIM(_BOOL, begin_popup_modal, _STRING _REF(_BOOL) _REF(_I32));
DEFINE_PRIM(_VOID, end_popup, _NO_ARG);
DEFINE_PRIM(_BOOL, open_popup_on_item_click, _STRING _REF(_I32));
DEFINE_PRIM(_VOID, open_popup_on_item_click, _STRING _REF(_I32));
DEFINE_PRIM(_BOOL, is_popup_open, _STRING);
DEFINE_PRIM(_VOID, close_current_popup, _NO_ARG);
4 changes: 2 additions & 2 deletions extension/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ImGuiStyle getImGuiStyleFromHL(vdynamic* style)
getStructFloat(style, "GrabRounding", imgui_style.GrabRounding);
getStructFloat(style, "TabRounding", imgui_style.TabRounding);
getStructFloat(style, "TabBorderSize", imgui_style.TabBorderSize);
getStructFloat(style, "TabMinWidthForUnselectedCloseButton", imgui_style.TabMinWidthForUnselectedCloseButton);
getStructFloat(style, "TabMinWidthForCloseButton", imgui_style.TabMinWidthForCloseButton);
getStructInt(style, "ColorButtonPosition", imgui_style.ColorButtonPosition);
getStructImVec2(style, "ButtonTextAlign", imgui_style.ButtonTextAlign);
getStructImVec2(style, "SelectableTextAlign", imgui_style.SelectableTextAlign);
Expand Down Expand Up @@ -187,7 +187,7 @@ vdynamic* getHLFromImGuiStyle(const ImGuiStyle& imgui_style)
setStructFloat(style, "GrabRounding", imgui_style.GrabRounding);
setStructFloat(style, "TabRounding", imgui_style.TabRounding);
setStructFloat(style, "TabBorderSize", imgui_style.TabBorderSize);
setStructFloat(style, "TabMinWidthForUnselectedCloseButton", imgui_style.TabMinWidthForUnselectedCloseButton);
setStructFloat(style, "TabMinWidthForCloseButton", imgui_style.TabMinWidthForCloseButton);
setStructInt(style, "ColorButtonPosition", imgui_style.ColorButtonPosition);
setStructImVec2(style, "ButtonTextAlign", imgui_style.ButtonTextAlign);
setStructImVec2(style, "SelectableTextAlign", imgui_style.SelectableTextAlign);
Expand Down
20 changes: 18 additions & 2 deletions imgui/ImGui.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ abstract ExtDynamic<T>(Dynamic) from T to T {}
var NoInputs : Int = 786944;
}

@:enum abstract ImGuiDockNodeFlags(Int) from Int to Int {
var None : Int = 0;
var KeepAliveOnly : Int = 1;
var NoCentralNode : Int = 2;
var NoDockingInCentralNode : Int = 4;
var NoSplit : Int = 8;
var NoResize : Int = 16;
var PassthruCentralNode : Int = 32;
var AutoHideTabBar : Int = 64;
}

@:enum abstract ImGuiTreeNodeFlags(Int) from Int to Int {
var None : Int = 0;
var Selected : Int = 1;
Expand Down Expand Up @@ -270,6 +281,8 @@ abstract ExtDynamic<T>(Dynamic) from T to T {}
var NavNoCaptureKeyboard : Int = 8;
var NoMouse : Int = 16;
var NoMouseCursorChange : Int = 32;
var DockingEnable : Int = 64;
var ViewportsEnable : Int = 1024;
var IsSRGB : Int = 1048576;
var IsTouchScreen : Int = 2097152;
}
Expand Down Expand Up @@ -464,7 +477,7 @@ typedef ImGuiStyle = {
GrabRounding : Single,
TabRounding : Single,
TabBorderSize : Single,
TabMinWidthForUnselectedCloseButton : Single,
TabMinWidthForCloseButton : Single,
ColorButtonPosition : ImGuiDir,
ButtonTextAlign : ImVec2,
SelectableTextAlign : ImVec2,
Expand Down Expand Up @@ -549,6 +562,8 @@ class ImGui
public static function setWindowSize2(name : String, size : ExtDynamic<ImVec2>, cond : ImGuiCond = 0) {}
public static function setWindowCollapsed2(name : String, collapsed : Bool, cond : ImGuiCond = 0) {}
public static function setWindowFocus2(name : String) {}

public static function dockSpace(id : Int, size : ExtDynamic<ImVec2> = null, flags : ImGuiDockNodeFlags = 0) {}

// Content region
public static function getContentRegionMax() : ExtDynamic<ImVec2> {return null;}
Expand Down Expand Up @@ -743,7 +758,7 @@ class ImGui
public static function beginPopupContextVoid(str_id : String = null, mouse_button : ImGuiMouseButton= 1) : Bool {return false;}
public static function beginPopupModal(name : String, p_open : hl.Ref<Bool> = null, flags : ImGuiWindowFlags = 0) : Bool {return false;}
public static function endPopup() {}
public static function openPopupOnItemClick(str_id : String = null, mouse_button : ImGuiMouseButton = 1) : Bool {return false;}
public static function openPopupOnItemClick(str_id : String = null, mouse_button : ImGuiMouseButton = 1) : Void {}
public static function isPopupOpen(str_id : String) : Bool {return false;}
public static function closeCurrentPopup() {}

Expand Down Expand Up @@ -875,4 +890,5 @@ class ImGui
public static function setDisplaySize(display_width:Int, display_height:Int) {}
public static function wantCaptureMouse() : Bool {return false;}
public static function wantCaptureKeyboard() : Bool {return false;}
public static function setConfigFlags(flags:ImGuiConfigFlags = 0) : Void {}
}

0 comments on commit e9893e3

Please sign in to comment.