Skip to content

Commit

Permalink
Update Dear ImGui to 1.82.
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenDang committed Mar 17, 2021
1 parent 56d4a97 commit 6403291
Show file tree
Hide file tree
Showing 36 changed files with 2,452 additions and 610 deletions.
31 changes: 17 additions & 14 deletions Canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,30 @@ func (c *Canvas) AddLine(p1, p2 image.Point, color color.RGBA, thickness float32
c.drawlist.AddLine(ToVec2(p1), ToVec2(p2), ToVec4Color(color), thickness)
}

type CornerFlags int
type DrawFlags int

const (
CornerFlags_None CornerFlags = 0
CornerFlags_TopLeft CornerFlags = 1 << 0 // 0x1
CornerFlags_TopRight CornerFlags = 1 << 1 // 0x2
CornerFlags_BotLeft CornerFlags = 1 << 2 // 0x4
CornerFlags_BotRight CornerFlags = 1 << 3 // 0x8
CornerFlags_Top CornerFlags = CornerFlags_TopLeft | CornerFlags_TopRight // 0x3
CornerFlags_Bot CornerFlags = CornerFlags_BotLeft | CornerFlags_BotRight // 0xC
CornerFlags_Left CornerFlags = CornerFlags_TopLeft | CornerFlags_BotLeft // 0x5
CornerFlags_Right CornerFlags = CornerFlags_TopRight | CornerFlags_BotRight // 0xA
CornerFlags_All CornerFlags = 0xF // In your function calls you may use ~0 (= all bits sets) instead of ImDrawCornerFlags_All, as a convenience

DrawFlags_None DrawFlags = 0
DrawFlags_Closed DrawFlags = 1 << 0 // PathStroke(), AddPolyline(): specify that shape should be closed (portant: this is always == 1 for legacy reason)
DrawFlags_RoundCornersTopLeft DrawFlags = 1 << 4 // AddRect(), AddRectFilled(), PathRect(): enable rounding top-left corner only (when rounding > 0.0f, we default to all corners). Was 0x01.
DrawFlags_RoundCornersTopRight DrawFlags = 1 << 5 // AddRect(), AddRectFilled(), PathRect(): enable rounding top-right corner only (when rounding > 0.0f, we default to all corners). Was 0x02.
DrawFlags_RoundCornersBottomLeft DrawFlags = 1 << 6 // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-left corner only (when rounding > 0.0f, we default to all corners). Was 0x04.
DrawFlags_RoundCornersBottomRight DrawFlags = 1 << 7 // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-right corner only (when rounding > 0.0f, we default to all corners). Wax 0x08.
DrawFlags_RoundCornersNone DrawFlags = 1 << 8 // AddRect(), AddRectFilled(), PathRect(): disable rounding on all corners (when rounding > 0.0f). This is NOT zero, NOT an implicit flag!
DrawFlags_RoundCornersTop DrawFlags = DrawFlags_RoundCornersTopLeft | DrawFlags_RoundCornersTopRight
DrawFlags_RoundCornersBottom DrawFlags = DrawFlags_RoundCornersBottomLeft | DrawFlags_RoundCornersBottomRight
DrawFlags_RoundCornersLeft DrawFlags = DrawFlags_RoundCornersBottomLeft | DrawFlags_RoundCornersTopLeft
DrawFlags_RoundCornersRight DrawFlags = DrawFlags_RoundCornersBottomRight | DrawFlags_RoundCornersTopRight
DrawFlags_RoundCornersAll DrawFlags = DrawFlags_RoundCornersTopLeft | DrawFlags_RoundCornersTopRight | DrawFlags_RoundCornersBottomLeft | DrawFlags_RoundCornersBottomRight
DrawFlags_RoundCornersDefault_ DrawFlags = DrawFlags_RoundCornersAll // Default to ALL corners if none of the _RoundCornersXX flags are specified.
DrawFlags_RoundCornersMask_ DrawFlags = DrawFlags_RoundCornersAll | DrawFlags_RoundCornersNone
)

func (c *Canvas) AddRect(pMin, pMax image.Point, color color.RGBA, rounding float32, rounding_corners CornerFlags, thickness float32) {
func (c *Canvas) AddRect(pMin, pMax image.Point, color color.RGBA, rounding float32, rounding_corners DrawFlags, thickness float32) {
c.drawlist.AddRect(ToVec2(pMin), ToVec2(pMax), ToVec4Color(color), rounding, int(rounding_corners), thickness)
}

func (c *Canvas) AddRectFilled(pMin, pMax image.Point, color color.RGBA, rounding float32, rounding_corners CornerFlags) {
func (c *Canvas) AddRectFilled(pMin, pMax image.Point, color color.RGBA, rounding float32, rounding_corners DrawFlags) {
c.drawlist.AddRectFilled(ToVec2(pMin), ToVec2(pMax), ToVec4Color(color), rounding, int(rounding_corners))
}

Expand Down
64 changes: 21 additions & 43 deletions Flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,27 @@ package giu
type InputTextFlags int

const (
// InputTextFlagsNone sets everything default.
InputTextFlagsNone InputTextFlags = 0
// InputTextFlagsCharsDecimal allows 0123456789.+-
InputTextFlagsCharsDecimal InputTextFlags = 1 << 0
// InputTextFlagsCharsHexadecimal allow 0123456789ABCDEFabcdef
InputTextFlagsCharsHexadecimal InputTextFlags = 1 << 1
// InputTextFlagsCharsUppercase turns a..z into A..Z.
InputTextFlagsCharsUppercase InputTextFlags = 1 << 2
// InputTextFlagsCharsNoBlank filters out spaces, tabs.
InputTextFlagsCharsNoBlank InputTextFlags = 1 << 3
// InputTextFlagsAutoSelectAll selects entire text when first taking mouse focus.
InputTextFlagsAutoSelectAll InputTextFlags = 1 << 4
// InputTextFlagsEnterReturnsTrue returns 'true' when Enter is pressed (as opposed to when the value was modified).
InputTextFlagsEnterReturnsTrue InputTextFlags = 1 << 5
// InputTextFlagsCallbackCompletion for callback on pressing TAB (for completion handling).
InputTextFlagsCallbackCompletion InputTextFlags = 1 << 6
// InputTextFlagsCallbackHistory for callback on pressing Up/Down arrows (for history handling).
InputTextFlagsCallbackHistory InputTextFlags = 1 << 7
// InputTextFlagsCallbackAlways for callback on each iteration. User code may query cursor position, modify text buffer.
InputTextFlagsCallbackAlways InputTextFlags = 1 << 8
// InputTextFlagsCallbackCharFilter for callback on character inputs to replace or discard them.
// Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
InputTextFlagsCallbackCharFilter InputTextFlags = 1 << 9
// InputTextFlagsAllowTabInput when pressing TAB to input a '\t' character into the text field.
InputTextFlagsAllowTabInput InputTextFlags = 1 << 10
// InputTextFlagsCtrlEnterForNewLine in multi-line mode, unfocus with Enter, add new line with Ctrl+Enter
// (default is opposite: unfocus with Ctrl+Enter, add line with Enter).
InputTextFlagsCtrlEnterForNewLine InputTextFlags = 1 << 11
// InputTextFlagsNoHorizontalScroll disables following the cursor horizontally.
InputTextFlagsNoHorizontalScroll InputTextFlags = 1 << 12
// InputTextFlagsAlwaysInsertMode sets insert mode.
InputTextFlagsAlwaysInsertMode InputTextFlags = 1 << 13
// InputTextFlagsReadOnly sets read-only mode.
InputTextFlagsReadOnly InputTextFlags = 1 << 14
// InputTextFlagsPassword sets password mode, display all characters as '*'.
InputTextFlagsPassword InputTextFlags = 1 << 15
// InputTextFlagsNoUndoRedo disables undo/redo. Note that input text owns the text data while active,
// if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID().
InputTextFlagsNoUndoRedo InputTextFlags = 1 << 16
// InputTextFlagsCharsScientific allows 0123456789.+-*/eE (Scientific notation input).
InputTextFlagsCharsScientific InputTextFlags = 1 << 17
// inputTextFlagsCallbackResize for callback on buffer capacity change requests.
// inputTextFlagsCallbackResize InputTextFlags = 1 << 18
InputTextFlags_None InputTextFlags = 0
InputTextFlags_CharsDecimal InputTextFlags = 1 << 0 // Allow 0123456789.+-*/
InputTextFlags_CharsHexadecimal InputTextFlags = 1 << 1 // Allow 0123456789ABCDEFabcdef
InputTextFlags_CharsUppercase InputTextFlags = 1 << 2 // Turn a..z into A..Z
InputTextFlags_CharsNoBlank InputTextFlags = 1 << 3 // Filter out spaces, tabs
InputTextFlags_AutoSelectAll InputTextFlags = 1 << 4 // Select entire text when first taking mouse focus
InputTextFlags_EnterReturnsTrue InputTextFlags = 1 << 5 // Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function.
InputTextFlags_CallbackCompletion InputTextFlags = 1 << 6 // Callback on pressing TAB (for completion handling)
InputTextFlags_CallbackHistory InputTextFlags = 1 << 7 // Callback on pressing Up/Down arrows (for history handling)
InputTextFlags_CallbackAlways InputTextFlags = 1 << 8 // Callback on each iteration. User code may query cursor position, modify text buffer.
InputTextFlags_CallbackCharFilter InputTextFlags = 1 << 9 // Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
InputTextFlags_AllowTabInput InputTextFlags = 1 << 10 // Pressing TAB input a '\t' character into the text field
InputTextFlags_CtrlEnterForNewLine InputTextFlags = 1 << 11 // In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite: unfocus with Ctrl+Enter, add line with Enter).
InputTextFlags_NoHorizontalScroll InputTextFlags = 1 << 12 // Disable following the cursor horizontally
InputTextFlags_AlwaysOverwrite InputTextFlags = 1 << 13 // Overwrite mode
InputTextFlags_ReadOnly InputTextFlags = 1 << 14 // Read-only mode
InputTextFlags_Password InputTextFlags = 1 << 15 // Password mode, display all characters as '*'
InputTextFlags_NoUndoRedo InputTextFlags = 1 << 16 // Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID().
InputTextFlags_CharsScientific InputTextFlags = 1 << 17 // Allow 0123456789.+-*/eE (Scientific notation input)
InputTextFlags_CallbackResize InputTextFlags = 1 << 18 // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this)
InputTextFlags_CallbackEdit InputTextFlags = 1 << 19 // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)
)

type WindowFlags int
Expand Down
2 changes: 1 addition & 1 deletion examples/canvas/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func loop() {
pos := g.GetCursorScreenPos()
color := color.RGBA{200, 75, 75, 255}
canvas.AddLine(pos, pos.Add(image.Pt(100, 100)), color, 1)
canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), color, 5, g.CornerFlags_All, 1)
canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), color, 5, g.DrawFlags_RoundCornersAll, 1)
canvas.AddRectFilled(pos.Add(image.Pt(220, 0)), pos.Add(image.Pt(320, 100)), color, 0, 0)

pos0 := pos.Add(image.Pt(0, 110))
Expand Down
2 changes: 1 addition & 1 deletion examples/dragdrop/dragdrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func loop() {
}
}),
),
g.InputTextMultiline("##DropTarget", &dropTarget).Size(-1, -1).Flags(g.InputTextFlagsReadOnly),
g.InputTextMultiline("##DropTarget", &dropTarget).Size(-1, -1).Flags(g.InputTextFlags_ReadOnly),
g.Custom(func() {
if imgui.BeginDragDropTarget() {
payload := imgui.AcceptDragDropPayload("DND_DEMO")
Expand Down
2 changes: 1 addition & 1 deletion examples/ondrop/ondrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
func loop() {
g.SingleWindow("On Drop Demo").Layout(
g.Label("Drop file to this window"),
g.InputTextMultiline("#DroppedFiles", &dropInFiles).Size(-1, -1).Flags(g.InputTextFlagsReadOnly),
g.InputTextMultiline("#DroppedFiles", &dropInFiles).Size(-1, -1).Flags(g.InputTextFlags_ReadOnly),
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/transparent/transparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func loop() {
pos := g.GetCursorScreenPos()
color := color.RGBA{200, 75, 75, 255}
canvas.AddLine(pos, pos.Add(image.Pt(100, 100)), color, 1)
canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), color, 5, g.CornerFlags_All, 1)
canvas.AddRect(pos.Add(image.Pt(110, 0)), pos.Add(image.Pt(200, 100)), color, 5, g.DrawFlags_RoundCornersAll, 1)
canvas.AddRectFilled(pos.Add(image.Pt(220, 0)), pos.Add(image.Pt(320, 100)), color, 0, 0)

pos0 := pos.Add(image.Pt(0, 110))
Expand Down
27 changes: 0 additions & 27 deletions imgui/LICENSE

This file was deleted.

21 changes: 21 additions & 0 deletions imgui/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014-2021 Omar Cornut

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 5 additions & 3 deletions imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )

Expand All @@ -34,8 +36,8 @@
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty.

//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. (imm32.lib/.a)
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
Expand Down
Loading

0 comments on commit 6403291

Please sign in to comment.