Skip to content

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)
voidbegin()
voidend(DiwnePanel * parent =nullptr)
voidexpectWidthChangeThisFrame(float width)<br>Inform the next spring that a new fixed width item will appear this frame.
ImVec2getAvailableSize() const
floatgetHeight() 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
floatgetMaxX() const
floatgetMaxY() const
const ImVec2 &getMin() const
floatgetMinimumHeight() const<br>Returns the minimum height of the panel.
ImVec2getMinimumSize() const<br>Returns the minimum size of the panel.
floatgetMinimumWidth() const<br>Returns the minimum width of the panel.
floatgetMinMaxX() const
floatgetMinMaxY() const
floatgetMinX() const
floatgetMinY() const
const ImRect &getRect() const
ImVec2getSize() const<br>Returns real size of the diwne panel.
floatgetWidth() const<br>Returns the real width of the diwne panel.
voidlayout()<br>Recalculates the available spring size for the next frame, should be called after end() and after its preferred dimensions have been set.
voidsetHeight(float height)
voidsetMax(const ImVec2 & max)
voidsetMaxX(float x)
voidsetMaxY(float y)
voidsetMin(const ImVec2 & min)
voidsetMinX(float x)
voidsetMinY(float y)
voidsetRect(const ImVec2 & min, const ImVec2 & max)
voidsetWidth(float width)<br>Sets the width of the panel, extending the rectangle to the right.
boolspring(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.
voidtranslate(const ImVec2 & v)
boolvspring(float relSize)<br>Vertical spring.

Protected Functions

Name
voidbeginFixedItem()
voidendFixedItem()
voidreset()

Protected Attributes

Name
inthsprings
ImVec2m_availableSpringSize <br>Total width/height that can be filled with springs, in DIWNE coordinates.
NodeEditor &m_editor <br>Reference to the overarching node editor.
ImVec2m_fixedSize <br>Cumulative size of fixed items within the panel. The minimum size.
std::stringm_label <br>ImGui label used for identification.
ImVec2m_lastFixedPositionXY <br>Internal variable for tracking the fixed items size automatically.
ImRectm_lastScreenRect <br>Last screen space rectangle reported by ImGui.
ImRectm_rect <br>Actual rect including any extra spacings that can shrink. In DIWNE space.
intvsprings

Detailed Description

cpp
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

cpp
DiwnePanel(
    NodeEditor & editor,
    std::string label
)
DiwnePanel(
    NodeEditor & editor,
    std::string label
)

function begin

cpp
void begin()
void begin()

function end

cpp
void end(
    DiwnePanel * parent =nullptr
)
void end(
    DiwnePanel * parent =nullptr
)

function expectWidthChangeThisFrame

cpp
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

cpp
inline ImVec2 getAvailableSize() const
inline ImVec2 getAvailableSize() const

function getHeight

cpp
inline float getHeight() const
inline float getHeight() const

Returns real height of the diwne panel.

function getLastScreenRectDiwne

cpp
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

cpp
inline const ImVec2 & getMax() const
inline const ImVec2 & getMax() const

function getMaxX

cpp
inline float getMaxX() const
inline float getMaxX() const

function getMaxY

cpp
inline float getMaxY() const
inline float getMaxY() const

function getMin

cpp
inline const ImVec2 & getMin() const
inline const ImVec2 & getMin() const

function getMinimumHeight

cpp
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

cpp
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

cpp
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

cpp
float getMinMaxX() const
float getMinMaxX() const

function getMinMaxY

cpp
float getMinMaxY() const
float getMinMaxY() const

function getMinX

cpp
inline float getMinX() const
inline float getMinX() const

function getMinY

cpp
inline float getMinY() const
inline float getMinY() const

function getRect

cpp
inline const ImRect & getRect() const
inline const ImRect & getRect() const

function getSize

cpp
inline ImVec2 getSize() const
inline ImVec2 getSize() const

Returns real size of the diwne panel.

function getWidth

cpp
inline float getWidth() const
inline float getWidth() const

Returns the real width of the diwne panel.

function layout

cpp
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

cpp
void setHeight(
    float height
)
void setHeight(
    float height
)

function setMax

cpp
inline void setMax(
    const ImVec2 & max
)
inline void setMax(
    const ImVec2 & max
)

function setMaxX

cpp
inline void setMaxX(
    float x
)
inline void setMaxX(
    float x
)

function setMaxY

cpp
inline void setMaxY(
    float y
)
inline void setMaxY(
    float y
)

function setMin

cpp
inline void setMin(
    const ImVec2 & min
)
inline void setMin(
    const ImVec2 & min
)

function setMinX

cpp
inline void setMinX(
    float x
)
inline void setMinX(
    float x
)

function setMinY

cpp
inline void setMinY(
    float y
)
inline void setMinY(
    float y
)

function setRect

cpp
inline void setRect(
    const ImVec2 & min,
    const ImVec2 & max
)
inline void setRect(
    const ImVec2 & min,
    const ImVec2 & max
)

function setWidth

cpp
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

cpp
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

cpp
inline void translate(
    const ImVec2 & v
)
inline void translate(
    const ImVec2 & v
)

function vspring

cpp
bool vspring(
    float relSize
)
bool vspring(
    float relSize
)

Vertical spring.

See: spring()

Protected Functions Documentation

function beginFixedItem

cpp
void beginFixedItem()
void beginFixedItem()

function endFixedItem

cpp
void endFixedItem()
void endFixedItem()

function reset

cpp
void reset()
void reset()

Protected Attributes Documentation

variable hsprings

cpp
int hsprings = 0;
int hsprings = 0;

variable m_availableSpringSize

cpp
ImVec2 m_availableSpringSize;
ImVec2 m_availableSpringSize;

Total width/height that can be filled with springs, in DIWNE coordinates.

variable m_editor

cpp
NodeEditor & m_editor;
NodeEditor & m_editor;

Reference to the overarching node editor.

variable m_fixedSize

cpp
ImVec2 m_fixedSize;
ImVec2 m_fixedSize;

Cumulative size of fixed items within the panel. The minimum size.

variable m_label

cpp
std::string m_label;
std::string m_label;

ImGui label used for identification.

variable m_lastFixedPositionXY

cpp
ImVec2 m_lastFixedPositionXY;
ImVec2 m_lastFixedPositionXY;

Internal variable for tracking the fixed items size automatically.

variable m_lastScreenRect

cpp
ImRect m_lastScreenRect {ImRect()};
ImRect m_lastScreenRect {ImRect()};

Last screen space rectangle reported by ImGui.

See: getLastScreenRectDiwne()

Used in special cases.

variable m_rect

cpp
ImRect m_rect {ImRect()};
ImRect m_rect {ImRect()};

Actual rect including any extra spacings that can shrink. In DIWNE space.

variable vsprings

cpp
int vsprings = 0;
int vsprings = 0;

Updated on 2025-05-31 at 12:55:31 +0000