Pioneer
Loading...
Searching...
No Matches
EditorDraw.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#pragma once
5
6#include "imgui/imgui.h"
7#include "imgui/imgui_internal.h"
8
9#include "FloatComparison.h"
10
11#include <string_view>
12
13struct Color4ub;
14
15namespace Editor {
16 class UndoSystem;
17}
18
19namespace Editor::Draw {
20
21 enum RectSide : uint8_t {
26 };
27
28 // Subtract a section from a side of the original rect and return it as a new rect
29 ImRect RectCut(ImRect &orig, float amount, RectSide side);
30
31 // Set the next window size to the given rect and begin it
32 bool BeginWindow(ImRect rect, const char *name, bool *p_open = NULL, ImGuiWindowFlags flags = 0);
33
34 // Draw a fullscreen host window for a dockspace
35 bool BeginHostWindow(const char *name, bool *p_open = NULL, ImGuiWindowFlags flags = 0);
36
37 // Draw an edit box for an ImVec2 with the given settings
38 bool EditFloat2(const char *label, ImVec2 *vec, float step = 0.f, float step_fast = 0.f, const char *format = "%.3f");
39
40 // Begin a horizontal layout for N inputs/items, reserving a given amount of size for each one's label
41 bool LayoutHorizontal(const char *label, int nItems, float itemLabelSize);
42
43 // End a horizontal layout block
44 void EndLayout();
45
46 // Setup horizontal layout for a button bar
47 void BeginHorizontalBar();
48
49 // End a horizontal layout block
50 void EndHorizontalBar();
51
52 // Show a window to debug the state of the passed undo system
53 void ShowUndoDebugWindow(UndoSystem *undo, bool *p_open = nullptr);
54
55 // Manage pushing/popping an UndoEntry after an input widget that provides IsItemActivated() and IsItemDeactivated()
56 // Note: this helper relies on the widget *not* changing the underlying value the frame IsItemActivated() is true
57 bool UndoHelper(std::string_view label, UndoSystem *undo);
58
59 // Open a Combo and manage pushing/popping an UndoEntry. Returns true if the Combo window is open.
60 // Use ImGui::IsWindowAppearing() to determine if you should push an UndoStep.
61 bool ComboUndoHelper(std::string_view entryName, const char *label, const char *preview, UndoSystem *undo);
62
63 // The above, but defaulting the label to the entryName
64 bool ComboUndoHelper(std::string_view label, const char *preview, UndoSystem *undo);
65
66 // Show an edit dialog box to chose a value from an enumeration
67 void EditEnum(std::string_view label, const char *name, const char *ns, int *val, size_t val_max, UndoSystem *undo);
68
69 // Simple button that summons a popup menu underneath it
70 bool MenuButton(const char *label);
71
72 // Simple on/off toggle button with a text label
73 bool ToggleButton(const char *label, bool *value, ImVec4 activeColor);
74
75 // Color edit button
76 bool ColorEdit3(const char *label, Color4ub *color);
77
82 DROP_AFTER = 3
83 };
84
85 // Begin tri-mode drag-drop handling on a
86 DragDropTarget HierarchyDragDrop(const char *type, ImGuiID targetID, void *data, void *outData, size_t dataSize);
87
88 // Show a help tooltip
89 void HelpMarker(const char* desc, bool same_line = true);
90
91}
92
93inline bool operator==(const ImVec2 &a, const ImVec2 &b)
94{
95 return is_equal_general(a.x, b.x) && is_equal_general(a.y, b.y);
96}
bool operator==(const ImVec2 &a, const ImVec2 &b)
Definition: EditorDraw.h:93
IEEEFloatTraits< T >::bool_type is_equal_general(T a, T b, T rel_tol, T abs_tol)
Definition: FloatComparison.h:142
unsigned int ImGuiID
Definition: Modal.h:9
double val
Definition: PrecalcPath.cpp:40
Definition: UndoSystem.h:112
Definition: EditorDraw.h:19
void BeginHorizontalBar()
Definition: EditorDraw.cpp:103
void ShowUndoDebugWindow(UndoSystem *undo, bool *p_open=nullptr)
Definition: EditorDraw.cpp:115
DragDropTarget
Definition: EditorDraw.h:78
@ DROP_CHILD
Definition: EditorDraw.h:81
@ DROP_AFTER
Definition: EditorDraw.h:82
@ DROP_NONE
Definition: EditorDraw.h:79
@ DROP_BEFORE
Definition: EditorDraw.h:80
bool MenuButton(const char *label)
Definition: EditorDraw.cpp:231
ImRect RectCut(ImRect &orig, float amount, RectSide side)
Definition: EditorDraw.cpp:19
bool BeginHostWindow(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: EditorDraw.cpp:46
bool BeginWindow(ImRect rect, const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: EditorDraw.cpp:36
void HelpMarker(const char *desc, bool same_line=true)
Definition: EditorDraw.cpp:354
void EditEnum(std::string_view label, const char *name, const char *ns, int *val, size_t val_max, UndoSystem *undo)
Definition: EditorDraw.cpp:210
bool LayoutHorizontal(const char *label, int nItems, float itemLabelSize)
Definition: EditorDraw.cpp:78
void EndLayout()
Definition: EditorDraw.cpp:93
bool ToggleButton(const char *label, bool *value, ImVec4 activeColor)
Definition: EditorDraw.cpp:248
bool EditFloat2(const char *label, ImVec2 *vec, float step=0.f, float step_fast=0.f, const char *format="%.3f")
Definition: EditorDraw.cpp:65
bool UndoHelper(std::string_view label, UndoSystem *undo)
Definition: EditorDraw.cpp:167
DragDropTarget HierarchyDragDrop(const char *type, ImGuiID targetID, void *data, void *outData, size_t dataSize)
Definition: EditorDraw.cpp:272
RectSide
Definition: EditorDraw.h:21
@ RectSide_Right
Definition: EditorDraw.h:24
@ RectSide_Top
Definition: EditorDraw.h:23
@ RectSide_Left
Definition: EditorDraw.h:22
@ RectSide_Bottom
Definition: EditorDraw.h:25
bool ComboUndoHelper(std::string_view entryName, const char *label, const char *preview, UndoSystem *undo)
Definition: EditorDraw.cpp:183
void EndHorizontalBar()
Definition: EditorDraw.cpp:109
bool ColorEdit3(const char *label, Color4ub *color)
Definition: EditorDraw.cpp:264
Definition: ActionBinder.h:14
Definition: Color.h:66