mirror of
https://github.com/ocornut/imgui.git
synced 2025-04-07 22:43:09 +00:00
Generate wrappers for remaining Begin/Push/Tree methods
This commit is contained in:
parent
f42f3e6310
commit
56374b8e08
2 changed files with 291 additions and 24 deletions
|
@ -19,15 +19,23 @@ class WrapperClass
|
|||
def initialize(m)
|
||||
@name = m[:name]
|
||||
|
||||
@state_var = nil
|
||||
case m[:name]
|
||||
when 'Begin'
|
||||
@class_name = 'Window'
|
||||
@state_var = 'IsContentVisible'
|
||||
else
|
||||
@class_name = m[:name]
|
||||
@state_var = 'IsOpen' if m[:type] == 'bool'
|
||||
end
|
||||
@class_name = case @name
|
||||
when 'Begin'
|
||||
'Window'
|
||||
when /^Begin(.*)$/
|
||||
$1
|
||||
when /^Push(.*)$/
|
||||
$1
|
||||
else
|
||||
m[:name]
|
||||
end
|
||||
|
||||
@state_var = case @name
|
||||
when 'Begin', 'BeginChild'
|
||||
'IsContentVisible'
|
||||
else
|
||||
'IsOpen' if m[:type] == 'bool'
|
||||
end
|
||||
|
||||
puts <<EOT
|
||||
#{INDENT}struct #{@class_name}
|
||||
|
@ -43,9 +51,14 @@ EOT
|
|||
print "#{INDENT * 2}~#{@class_name}() { "
|
||||
print case @name
|
||||
when 'Begin' then 'ImGui::End();'
|
||||
when /^Tree/ then "if (#{@state_var}) ImGui::TreePop();"
|
||||
when /^PushID$/ then 'ImGui::PopID();'
|
||||
else fail "Don't know what pop body to use"
|
||||
when 'BeginChild' then 'ImGui::EndChild();'
|
||||
when 'BeginChildFrame' then 'ImGui::EndChildFrame();'
|
||||
when /^BeginPopup/ then "if (#{@state_var}) ImGui::EndPopup();"
|
||||
when /^Begin(.*)/ then "if (#{@state_var}) ImGui::End#{$1}();"
|
||||
when /^TreeNode/ then "if (#{@state_var}) ImGui::TreePop();"
|
||||
when 'TreePush' then 'ImGui::TreePop();'
|
||||
when /^Push(.*)/ then "ImGui::Pop#{$1}();"
|
||||
else fail "Don't know what pop body to use for #{@name}"
|
||||
end
|
||||
puts " }"
|
||||
|
||||
|
@ -67,9 +80,10 @@ current_class = nil
|
|||
|
||||
header_file = File.open("../../imgui.h")
|
||||
header_file.each_line do |line|
|
||||
break if line.match(/^}\s*\/\/\s*namespace ImGui$/i)
|
||||
|
||||
line.match(/^\s*IMGUI_API\s+(?<type>[\w\s]+\w)\s+(?<name>\w*)\((?<args>[^)]+)\)(?<attrs>[^;]*);(?<rest>.*)$/) do |m|
|
||||
next unless m[:name].match(/^(Begin|Push|Open|Tree|Column)/)
|
||||
next unless m[:name].match(/^TreeNode|PushID|Begin$/)
|
||||
next unless m[:name].match(/^(Begin|Push|Tree)/)
|
||||
|
||||
argnames = m[:args].split(/,\s*/).map do |arg|
|
||||
arg = arg.split(/\s*=\s*/, 2).first
|
||||
|
|
|
@ -19,18 +19,128 @@ namespace ImScoped
|
|||
Window &operator=(Window &) = delete;
|
||||
};
|
||||
|
||||
struct PushID
|
||||
struct Child
|
||||
{
|
||||
PushID(const char* str_id) { ImGui::PushID(str_id); }
|
||||
PushID(const char* str_id_begin, const char* str_id_end) { ImGui::PushID(str_id_begin, str_id_end); }
|
||||
PushID(const void* ptr_id) { ImGui::PushID(ptr_id); }
|
||||
PushID(int int_id) { ImGui::PushID(int_id); }
|
||||
~PushID() { ImGui::PopID(); }
|
||||
bool IsContentVisible;
|
||||
|
||||
PushID(PushID &&) = delete;
|
||||
PushID &operator=(PushID &&) = delete;
|
||||
PushID(const PushID &) = delete;
|
||||
PushID &operator=(PushID &) = delete;
|
||||
Child(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags flags = 0) { IsContentVisible = ImGui::BeginChild(str_id, size, 0); }
|
||||
Child(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags flags = 0) { IsContentVisible = ImGui::BeginChild(id, size, 0); }
|
||||
~Child() { ImGui::EndChild(); }
|
||||
|
||||
operator bool() { return IsContentVisible; }
|
||||
|
||||
Child(Child &&) = delete;
|
||||
Child &operator=(Child &&) = delete;
|
||||
Child(const Child &) = delete;
|
||||
Child &operator=(Child &) = delete;
|
||||
};
|
||||
|
||||
struct Font
|
||||
{
|
||||
Font(ImFont* font) { ImGui::PushFont(font); }
|
||||
~Font() { ImGui::PopFont(); }
|
||||
|
||||
Font(Font &&) = delete;
|
||||
Font &operator=(Font &&) = delete;
|
||||
Font(const Font &) = delete;
|
||||
Font &operator=(Font &) = delete;
|
||||
};
|
||||
|
||||
struct StyleColor
|
||||
{
|
||||
StyleColor(ImGuiCol idx, ImU32 col) { ImGui::PushStyleColor(idx, col); }
|
||||
StyleColor(ImGuiCol idx, const ImVec4& col) { ImGui::PushStyleColor(idx, col); }
|
||||
~StyleColor() { ImGui::PopStyleColor(); }
|
||||
|
||||
StyleColor(StyleColor &&) = delete;
|
||||
StyleColor &operator=(StyleColor &&) = delete;
|
||||
StyleColor(const StyleColor &) = delete;
|
||||
StyleColor &operator=(StyleColor &) = delete;
|
||||
};
|
||||
|
||||
struct StyleVar
|
||||
{
|
||||
StyleVar(ImGuiStyleVar idx, float val) { ImGui::PushStyleVar(idx, val); }
|
||||
StyleVar(ImGuiStyleVar idx, const ImVec2& val) { ImGui::PushStyleVar(idx, val); }
|
||||
~StyleVar() { ImGui::PopStyleVar(); }
|
||||
|
||||
StyleVar(StyleVar &&) = delete;
|
||||
StyleVar &operator=(StyleVar &&) = delete;
|
||||
StyleVar(const StyleVar &) = delete;
|
||||
StyleVar &operator=(StyleVar &) = delete;
|
||||
};
|
||||
|
||||
struct ItemWidth
|
||||
{
|
||||
ItemWidth(float item_width) { ImGui::PushItemWidth(item_width); }
|
||||
~ItemWidth() { ImGui::PopItemWidth(); }
|
||||
|
||||
ItemWidth(ItemWidth &&) = delete;
|
||||
ItemWidth &operator=(ItemWidth &&) = delete;
|
||||
ItemWidth(const ItemWidth &) = delete;
|
||||
ItemWidth &operator=(ItemWidth &) = delete;
|
||||
};
|
||||
|
||||
struct TextWrapPos
|
||||
{
|
||||
TextWrapPos(float wrap_pos_x = 0.0f) { ImGui::PushTextWrapPos(wrap_pos_x); }
|
||||
~TextWrapPos() { ImGui::PopTextWrapPos(); }
|
||||
|
||||
TextWrapPos(TextWrapPos &&) = delete;
|
||||
TextWrapPos &operator=(TextWrapPos &&) = delete;
|
||||
TextWrapPos(const TextWrapPos &) = delete;
|
||||
TextWrapPos &operator=(TextWrapPos &) = delete;
|
||||
};
|
||||
|
||||
struct AllowKeyboardFocus
|
||||
{
|
||||
AllowKeyboardFocus(bool allow_keyboard_focus) { ImGui::PushAllowKeyboardFocus(allow_keyboard_focus); }
|
||||
~AllowKeyboardFocus() { ImGui::PopAllowKeyboardFocus(); }
|
||||
|
||||
AllowKeyboardFocus(AllowKeyboardFocus &&) = delete;
|
||||
AllowKeyboardFocus &operator=(AllowKeyboardFocus &&) = delete;
|
||||
AllowKeyboardFocus(const AllowKeyboardFocus &) = delete;
|
||||
AllowKeyboardFocus &operator=(AllowKeyboardFocus &) = delete;
|
||||
};
|
||||
|
||||
struct ButtonRepeat
|
||||
{
|
||||
ButtonRepeat(bool repeat) { ImGui::PushButtonRepeat(repeat); }
|
||||
~ButtonRepeat() { ImGui::PopButtonRepeat(); }
|
||||
|
||||
ButtonRepeat(ButtonRepeat &&) = delete;
|
||||
ButtonRepeat &operator=(ButtonRepeat &&) = delete;
|
||||
ButtonRepeat(const ButtonRepeat &) = delete;
|
||||
ButtonRepeat &operator=(ButtonRepeat &) = delete;
|
||||
};
|
||||
|
||||
struct ID
|
||||
{
|
||||
ID(const char* str_id) { ImGui::PushID(str_id); }
|
||||
ID(const char* str_id_begin, const char* str_id_end) { ImGui::PushID(str_id_begin, str_id_end); }
|
||||
ID(const void* ptr_id) { ImGui::PushID(ptr_id); }
|
||||
ID(int int_id) { ImGui::PushID(int_id); }
|
||||
~ID() { ImGui::PopID(); }
|
||||
|
||||
ID(ID &&) = delete;
|
||||
ID &operator=(ID &&) = delete;
|
||||
ID(const ID &) = delete;
|
||||
ID &operator=(ID &) = delete;
|
||||
};
|
||||
|
||||
struct Combo
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
Combo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0) { IsOpen = ImGui::BeginCombo(label, preview_value, flags); }
|
||||
~Combo() { if (IsOpen) ImGui::EndCombo(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
Combo(Combo &&) = delete;
|
||||
Combo &operator=(Combo &&) = delete;
|
||||
Combo(const Combo &) = delete;
|
||||
Combo &operator=(Combo &) = delete;
|
||||
};
|
||||
|
||||
struct TreeNode
|
||||
|
@ -99,4 +209,147 @@ namespace ImScoped
|
|||
TreeNodeExV &operator=(TreeNodeExV &) = delete;
|
||||
};
|
||||
|
||||
struct TreePush
|
||||
{
|
||||
TreePush(const char* str_id) { ImGui::TreePush(str_id); }
|
||||
TreePush(const void* ptr_id = NULL) { ImGui::TreePush(ptr_id); }
|
||||
~TreePush() { ImGui::TreePop(); }
|
||||
|
||||
TreePush(TreePush &&) = delete;
|
||||
TreePush &operator=(TreePush &&) = delete;
|
||||
TreePush(const TreePush &) = delete;
|
||||
TreePush &operator=(TreePush &) = delete;
|
||||
};
|
||||
|
||||
struct Menu
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
Menu(const char* label, bool enabled = true) { IsOpen = ImGui::BeginMenu(label, enabled); }
|
||||
~Menu() { if (IsOpen) ImGui::EndMenu(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
Menu(Menu &&) = delete;
|
||||
Menu &operator=(Menu &&) = delete;
|
||||
Menu(const Menu &) = delete;
|
||||
Menu &operator=(Menu &) = delete;
|
||||
};
|
||||
|
||||
struct Popup
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
Popup(const char* str_id, ImGuiWindowFlags flags = 0) { IsOpen = ImGui::BeginPopup(str_id, flags); }
|
||||
~Popup() { if (IsOpen) ImGui::EndPopup(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
Popup(Popup &&) = delete;
|
||||
Popup &operator=(Popup &&) = delete;
|
||||
Popup(const Popup &) = delete;
|
||||
Popup &operator=(Popup &) = delete;
|
||||
};
|
||||
|
||||
struct PopupContextItem
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
PopupContextItem(const char* str_id = NULL, int mouse_button = 1) { IsOpen = ImGui::BeginPopupContextItem(str_id, mouse_button); }
|
||||
~PopupContextItem() { if (IsOpen) ImGui::EndPopup(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
PopupContextItem(PopupContextItem &&) = delete;
|
||||
PopupContextItem &operator=(PopupContextItem &&) = delete;
|
||||
PopupContextItem(const PopupContextItem &) = delete;
|
||||
PopupContextItem &operator=(PopupContextItem &) = delete;
|
||||
};
|
||||
|
||||
struct PopupContextWindow
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
PopupContextWindow(const char* str_id = NULL, int mouse_button = 1, bool also_over_items = true) { IsOpen = ImGui::BeginPopupContextWindow(str_id, mouse_button, also_over_items); }
|
||||
~PopupContextWindow() { if (IsOpen) ImGui::EndPopup(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
PopupContextWindow(PopupContextWindow &&) = delete;
|
||||
PopupContextWindow &operator=(PopupContextWindow &&) = delete;
|
||||
PopupContextWindow(const PopupContextWindow &) = delete;
|
||||
PopupContextWindow &operator=(PopupContextWindow &) = delete;
|
||||
};
|
||||
|
||||
struct PopupContextVoid
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
PopupContextVoid(const char* str_id = NULL, int mouse_button = 1) { IsOpen = ImGui::BeginPopupContextVoid(str_id, mouse_button); }
|
||||
~PopupContextVoid() { if (IsOpen) ImGui::EndPopup(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
PopupContextVoid(PopupContextVoid &&) = delete;
|
||||
PopupContextVoid &operator=(PopupContextVoid &&) = delete;
|
||||
PopupContextVoid(const PopupContextVoid &) = delete;
|
||||
PopupContextVoid &operator=(PopupContextVoid &) = delete;
|
||||
};
|
||||
|
||||
struct PopupModal
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
PopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0) { IsOpen = ImGui::BeginPopupModal(name, p_open, flags); }
|
||||
~PopupModal() { if (IsOpen) ImGui::EndPopup(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
PopupModal(PopupModal &&) = delete;
|
||||
PopupModal &operator=(PopupModal &&) = delete;
|
||||
PopupModal(const PopupModal &) = delete;
|
||||
PopupModal &operator=(PopupModal &) = delete;
|
||||
};
|
||||
|
||||
struct DragDropSource
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
DragDropSource(ImGuiDragDropFlags flags = 0) { IsOpen = ImGui::BeginDragDropSource(flags); }
|
||||
~DragDropSource() { if (IsOpen) ImGui::EndDragDropSource(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
DragDropSource(DragDropSource &&) = delete;
|
||||
DragDropSource &operator=(DragDropSource &&) = delete;
|
||||
DragDropSource(const DragDropSource &) = delete;
|
||||
DragDropSource &operator=(DragDropSource &) = delete;
|
||||
};
|
||||
|
||||
struct ClipRect
|
||||
{
|
||||
ClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect) { ImGui::PushClipRect(clip_rect_min, clip_rect_max, intersect_with_current_clip_rect); }
|
||||
~ClipRect() { ImGui::PopClipRect(); }
|
||||
|
||||
ClipRect(ClipRect &&) = delete;
|
||||
ClipRect &operator=(ClipRect &&) = delete;
|
||||
ClipRect(const ClipRect &) = delete;
|
||||
ClipRect &operator=(ClipRect &) = delete;
|
||||
};
|
||||
|
||||
struct ChildFrame
|
||||
{
|
||||
bool IsOpen;
|
||||
|
||||
ChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags flags = 0) { IsOpen = ImGui::BeginChildFrame(id, size, flags); }
|
||||
~ChildFrame() { ImGui::EndChildFrame(); }
|
||||
|
||||
operator bool() { return IsOpen; }
|
||||
|
||||
ChildFrame(ChildFrame &&) = delete;
|
||||
ChildFrame &operator=(ChildFrame &&) = delete;
|
||||
ChildFrame(const ChildFrame &) = delete;
|
||||
ChildFrame &operator=(ChildFrame &) = delete;
|
||||
};
|
||||
|
||||
} // namespace ImScoped
|
||||
|
|
Loading…
Add table
Reference in a new issue