DIWNE::DiwnePanel
A rectangular area representing a part of a DIWNE object. More...
#include "DIWNE/Core/Layout/DiwnePanel.h"
Public Functions
Name | |
---|---|
DiwnePanel(NodeEditor & editor, std::string label) | |
void | begin() |
void | end(DiwnePanel * parent =nullptr) |
void | expectWidthChangeThisFrame(float width)<br>Inform the next spring that a new fixed width item will appear this frame. |
ImVec2 | getAvailableSize() const |
float | getHeight() const<br>Returns real height of the diwne panel. |
const ImRect & | getLastScreenRectDiwne() const<br>Returns the last screen space rectangle of this panel as reported by ImGui in the last end() call. |
const ImVec2 & | getMax() const |
float | getMaxX() const |
float | getMaxY() const |
const ImVec2 & | getMin() const |
float | getMinimumHeight() const<br>Returns the minimum height of the panel. |
ImVec2 | getMinimumSize() const<br>Returns the minimum size of the panel. |
float | getMinimumWidth() const<br>Returns the minimum width of the panel. |
float | getMinMaxX() const |
float | getMinMaxY() const |
float | getMinX() const |
float | getMinY() const |
const ImRect & | getRect() const |
ImVec2 | getSize() const<br>Returns real size of the diwne panel. |
float | getWidth() const<br>Returns the real width of the diwne panel. |
void | layout()<br>Recalculates the available spring size for the next frame, should be called after end() and after its preferred dimensions have been set. |
void | setHeight(float height) |
void | setMax(const ImVec2 & max) |
void | setMaxX(float x) |
void | setMaxY(float y) |
void | setMin(const ImVec2 & min) |
void | setMinX(float x) |
void | setMinY(float y) |
void | setRect(const ImVec2 & min, const ImVec2 & max) |
void | setWidth(float width)<br>Sets the width of the panel, extending the rectangle to the right. |
bool | spring(float relSize, bool horizontal =true)<br>Adds a horizontal (or vertical) spring (dummy item) with width/height calculated based on remaining available width in the panel. |
void | translate(const ImVec2 & v) |
bool | vspring(float relSize)<br>Vertical spring. |
Protected Functions
Name | |
---|---|
void | beginFixedItem() |
void | endFixedItem() |
void | reset() |
Protected Attributes
Name | |
---|---|
int | hsprings |
ImVec2 | m_availableSpringSize <br>Total width/height that can be filled with springs, in DIWNE coordinates. |
NodeEditor & | m_editor <br>Reference to the overarching node editor. |
ImVec2 | m_fixedSize <br>Cumulative size of fixed items within the panel. The minimum size. |
std::string | m_label <br>ImGui label used for identification. |
ImVec2 | m_lastFixedPositionXY <br>Internal variable for tracking the fixed items size automatically. |
ImRect | m_lastScreenRect <br>Last screen space rectangle reported by ImGui. |
ImRect | m_rect <br>Actual rect including any extra spacings that can shrink. In DIWNE space. |
int | vsprings |
Detailed Description
class DIWNE::DiwnePanel;
class DIWNE::DiwnePanel;
A rectangular area representing a part of a DIWNE object.
See: DIWNE::Stack
Used for layouting, DiwnePanels support horizontal and vertical springs, which can be used to align fixed items within the panel. Note that this class is NOT a subclass of a DiwneObject. It is merely a utility class meant to be used within DIWNE objects.
DiwnePanels operate in DIWNE coordinates to be as view/zoom agnostic as possible. Unfortunately view position and zoom level still affects all coordinates due to ImGui pixel alignment.
Basic layout concept: DiwnePanel is a rectangle that tracks "fixed" size, which are parts of the rectangle that CANNOT shrink. Remaining size in the rectangle is considered "springy" and may be shrunk. Since the panel is tracking its fixed width (eg. it's minimal width), springs can be added within it that share some remaining available space. So to right align the panels content, a spring can be added to the beginning with a factor of 1.0f, making it use all the available space, right aligning the content. Similarly two springs with 0.5f factor each can be used to surround a fixed item and center it in the panel.
TODO: Better docs, examples etc.
DiwnePanels are meant to be a generic layout utility, but then need to work in "stable" coordinates. Hence they use DIWNE coordinates, which are converted from screen space using the provided editor reference. This incurs an extra runtime cost that wouldn't be necessary if used outside of the NodeEditor.
TODO: I might create a separate layout class for general ImGui if DiwnePanels prove useful
DiwnePanels themselves are merely a component of a larger layout system.
Public Functions Documentation
function DiwnePanel
DiwnePanel(
NodeEditor & editor,
std::string label
)
DiwnePanel(
NodeEditor & editor,
std::string label
)
function begin
void begin()
void begin()
function end
void end(
DiwnePanel * parent =nullptr
)
void end(
DiwnePanel * parent =nullptr
)
function expectWidthChangeThisFrame
void expectWidthChangeThisFrame(
float width
)
void expectWidthChangeThisFrame(
float width
)
Inform the next spring that a new fixed width item will appear this frame.
Can be used to prevent flickering on layout change.
function getAvailableSize
inline ImVec2 getAvailableSize() const
inline ImVec2 getAvailableSize() const
function getHeight
inline float getHeight() const
inline float getHeight() const
Returns real height of the diwne panel.
function getLastScreenRectDiwne
inline const ImRect & getLastScreenRectDiwne() const
inline const ImRect & getLastScreenRectDiwne() const
Returns the last screen space rectangle of this panel as reported by ImGui in the last end() call.
Warning: This rectangle is merely the last computed ImGui screen space rectangle. It does not have to correspond to getRect() and is only valid immediately after drawing, before layouting. Convert getRect() using screen2diwne to get a real screen space rect representation.
Can be used in special cases instead of the getRect() method to avoid unnecessary coordinate conversion.
function getMax
inline const ImVec2 & getMax() const
inline const ImVec2 & getMax() const
function getMaxX
inline float getMaxX() const
inline float getMaxX() const
function getMaxY
inline float getMaxY() const
inline float getMaxY() const
function getMin
inline const ImVec2 & getMin() const
inline const ImVec2 & getMin() const
function getMinimumHeight
float getMinimumHeight() const
float getMinimumHeight() const
Returns the minimum height of the panel.
Minimum height does not contain spring heights as those are willing to shrink if necessary.
function getMinimumSize
ImVec2 getMinimumSize() const
ImVec2 getMinimumSize() const
Returns the minimum size of the panel.
Minimum size does not contain spring sizes as those are willing to shrink if necessary.
function getMinimumWidth
float getMinimumWidth() const
float getMinimumWidth() const
Returns the minimum width of the panel.
Minimum width does not contain spring widths as those are willing to shrink if necessary.
function getMinMaxX
float getMinMaxX() const
float getMinMaxX() const
function getMinMaxY
float getMinMaxY() const
float getMinMaxY() const
function getMinX
inline float getMinX() const
inline float getMinX() const
function getMinY
inline float getMinY() const
inline float getMinY() const
function getRect
inline const ImRect & getRect() const
inline const ImRect & getRect() const
function getSize
inline ImVec2 getSize() const
inline ImVec2 getSize() const
Returns real size of the diwne panel.
function getWidth
inline float getWidth() const
inline float getWidth() const
Returns the real width of the diwne panel.
function layout
void layout()
void layout()
Recalculates the available spring size for the next frame, should be called after end() and after its preferred dimensions have been set.
function setHeight
void setHeight(
float height
)
void setHeight(
float height
)
function setMax
inline void setMax(
const ImVec2 & max
)
inline void setMax(
const ImVec2 & max
)
function setMaxX
inline void setMaxX(
float x
)
inline void setMaxX(
float x
)
function setMaxY
inline void setMaxY(
float y
)
inline void setMaxY(
float y
)
function setMin
inline void setMin(
const ImVec2 & min
)
inline void setMin(
const ImVec2 & min
)
function setMinX
inline void setMinX(
float x
)
inline void setMinX(
float x
)
function setMinY
inline void setMinY(
float y
)
inline void setMinY(
float y
)
function setRect
inline void setRect(
const ImVec2 & min,
const ImVec2 & max
)
inline void setRect(
const ImVec2 & min,
const ImVec2 & max
)
function setWidth
void setWidth(
float width
)
void setWidth(
float width
)
Sets the width of the panel, extending the rectangle to the right.
Or shrinking to the left.
function spring
bool spring(
float relSize,
bool horizontal =true
)
bool spring(
float relSize,
bool horizontal =true
)
Adds a horizontal (or vertical) spring (dummy item) with width/height calculated based on remaining available width in the panel.
Parameters:
- relSize Proportion of the available width/height this spring ends up using
- horizontal True for a horizontal spring, false for a vertical spring.
Return: Whether the spring item was truly added or not.
Warning: Springs operate in a single dimension, eg. in a single line, single "column". The space they span isn't meant to be occupied by another item. If you, for example, need several horizontal springs above each other, use multiple DiwnePanels and a layout manager like VStack.
function translate
inline void translate(
const ImVec2 & v
)
inline void translate(
const ImVec2 & v
)
function vspring
bool vspring(
float relSize
)
bool vspring(
float relSize
)
Vertical spring.
See: spring()
Protected Functions Documentation
function beginFixedItem
void beginFixedItem()
void beginFixedItem()
function endFixedItem
void endFixedItem()
void endFixedItem()
function reset
void reset()
void reset()
Protected Attributes Documentation
variable hsprings
int hsprings = 0;
int hsprings = 0;
variable m_availableSpringSize
ImVec2 m_availableSpringSize;
ImVec2 m_availableSpringSize;
Total width/height that can be filled with springs, in DIWNE coordinates.
variable m_editor
NodeEditor & m_editor;
NodeEditor & m_editor;
Reference to the overarching node editor.
variable m_fixedSize
ImVec2 m_fixedSize;
ImVec2 m_fixedSize;
Cumulative size of fixed items within the panel. The minimum size.
variable m_label
std::string m_label;
std::string m_label;
ImGui label used for identification.
variable m_lastFixedPositionXY
ImVec2 m_lastFixedPositionXY;
ImVec2 m_lastFixedPositionXY;
Internal variable for tracking the fixed items size automatically.
variable m_lastScreenRect
ImRect m_lastScreenRect {ImRect()};
ImRect m_lastScreenRect {ImRect()};
Last screen space rectangle reported by ImGui.
Used in special cases.
variable m_rect
ImRect m_rect {ImRect()};
ImRect m_rect {ImRect()};
Actual rect including any extra spacings that can shrink. In DIWNE space.
variable vsprings
int vsprings = 0;
int vsprings = 0;
Updated on 2025-05-31 at 12:55:31 +0000