From 5f83a5efa05064314bb5dc5202ee41827f41e381 Mon Sep 17 00:00:00 2001 From: Elias Daler Date: Wed, 12 Jan 2022 13:59:16 +0300 Subject: [PATCH 1/3] Add string formatting overloads for Text, LabelText, TreeNode, SetTooltip --- README.md | 4 ++-- Widgets.go | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd807e68..0c551866 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,12 @@ Functions that don't have optional parameters don't come in a verbose variant. The **Dear ImGui** functions `IO()` and `Style()` have been renamed to be `CurrentIO()` and `CurrentStyle()`. This was done because their returned types have the same name, causing a name clash. -With the `Current` prefix, they also better describe what they return. +With the `Current` prefix, they also better describe what they return. ## API philosophy This library does not intend to export all the functions of the wrapped **Dear ImGui**. The following filter applies as a rule of thumb: * Functions marked as "obsolete" are not available. (The corresponding C code isn't even compiled - disabled by define) -* "Shortcut" Functions, which combine language features and/or other **Dear ImGui** functions, are not available. Prime example are the Text*() functions for instance: Text formatting should be done with fmt.Sprintf(), and style formatting with the corresponding Push/Pop functions. +* "Shortcut" Functions, which combine language features and/or other **Dear ImGui** functions, are not available. There may be exceptions for this if the shortcut exists in Dear ImGui code base (e.g. `ImGui::Text` which does printf style string formatting) * Functions that are not needed by InkyBlackness are ignored. This doesn't mean that they can't be in the wrapper, they are simply not a priority. Feel free to propose an implementation or make a pull request, respecting the previous points :) ## Version philosophy diff --git a/Widgets.go b/Widgets.go index f3667d49..fc07f1fc 100644 --- a/Widgets.go +++ b/Widgets.go @@ -3,7 +3,10 @@ package imgui // #include "wrapper/Widgets.h" import "C" -import "math" +import ( + "fmt" + "math" +) // Text adds formatted text. See PushTextWrapPosV() or PushStyleColorV() for modifying the output. // Without any modified style stack, the text is unformatted. @@ -14,6 +17,11 @@ func Text(text string) { C.iggTextUnformatted(textArg) } +// Textf calls Text(fmt.Sprintf(format, v...) +func Textf(format string, v ...interface{}) { + Text(fmt.Sprintf(format, v...)) +} + // LabelText adds text+label aligned the same way as value+label widgets. func LabelText(label, text string) { labelArg, labelFin := wrapString(label) @@ -23,6 +31,11 @@ func LabelText(label, text string) { C.iggLabelText(labelArg, textArg) } +// LabelTextf calls LabelText(label, fmt.Sprintf(format, v...)) +func LabelTextf(label, format string, v ...interface{}) { + LabelText(label, fmt.Sprintf(format, v...)) +} + // ButtonV returns true if it is clicked. func ButtonV(id string, size Vec2) bool { idArg, idFin := wrapString(id) @@ -757,6 +770,11 @@ func TreeNode(label string) bool { return TreeNodeV(label, 0) } +// TreeNodeF calls TreeNode(fmt.Sprintf(format, v...)) +func TreeNodef(format string, v ...interface{}) bool { + return TreeNode(fmt.Sprintf(format, v...)) +} + // TreePop finishes a tree branch. This has to be called for a matching TreeNodeV call returning true. func TreePop() { C.iggTreePop() @@ -938,6 +956,11 @@ func SetTooltip(text string) { C.iggSetTooltip(textArg) } +// SetTooltipf calls SetTooltip(fmt.Sprintf(format, v...)) +func SetTooltipf(format string, v ...interface{}) { + SetTooltip(fmt.Sprintf(format, v...)) +} + // BeginTooltip begins/appends to a tooltip window. Used to create full-featured tooltip (with any kind of contents). // Requires a call to EndTooltip(). func BeginTooltip() { From c6f81e23f710531db89a65e038e00eaf5e5f72a9 Mon Sep 17 00:00:00 2001 From: Christian Haas Date: Sat, 22 Jan 2022 10:49:32 +0100 Subject: [PATCH 2/3] Fix comments, add periods for full sentences --- Widgets.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Widgets.go b/Widgets.go index fc07f1fc..6589a2b9 100644 --- a/Widgets.go +++ b/Widgets.go @@ -17,7 +17,7 @@ func Text(text string) { C.iggTextUnformatted(textArg) } -// Textf calls Text(fmt.Sprintf(format, v...) +// Textf calls Text(fmt.Sprintf(format, v...) . func Textf(format string, v ...interface{}) { Text(fmt.Sprintf(format, v...)) } @@ -31,7 +31,7 @@ func LabelText(label, text string) { C.iggLabelText(labelArg, textArg) } -// LabelTextf calls LabelText(label, fmt.Sprintf(format, v...)) +// LabelTextf calls LabelText(label, fmt.Sprintf(format, v...)) . func LabelTextf(label, format string, v ...interface{}) { LabelText(label, fmt.Sprintf(format, v...)) } @@ -770,7 +770,7 @@ func TreeNode(label string) bool { return TreeNodeV(label, 0) } -// TreeNodeF calls TreeNode(fmt.Sprintf(format, v...)) +// TreeNodeF calls TreeNode(fmt.Sprintf(format, v...)) . func TreeNodef(format string, v ...interface{}) bool { return TreeNode(fmt.Sprintf(format, v...)) } @@ -956,7 +956,7 @@ func SetTooltip(text string) { C.iggSetTooltip(textArg) } -// SetTooltipf calls SetTooltip(fmt.Sprintf(format, v...)) +// SetTooltipf calls SetTooltip(fmt.Sprintf(format, v...)) . func SetTooltipf(format string, v ...interface{}) { SetTooltip(fmt.Sprintf(format, v...)) } From 4e541d6eede1c11f1c3698c28433dac05a242b5c Mon Sep 17 00:00:00 2001 From: Christian Haas Date: Sat, 22 Jan 2022 10:52:05 +0100 Subject: [PATCH 3/3] Fix comment, refer to proper function name --- Widgets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Widgets.go b/Widgets.go index 6589a2b9..b6e07bef 100644 --- a/Widgets.go +++ b/Widgets.go @@ -770,7 +770,7 @@ func TreeNode(label string) bool { return TreeNodeV(label, 0) } -// TreeNodeF calls TreeNode(fmt.Sprintf(format, v...)) . +// TreeNodef calls TreeNode(fmt.Sprintf(format, v...)) . func TreeNodef(format string, v ...interface{}) bool { return TreeNode(fmt.Sprintf(format, v...)) }