psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::Div Class Reference

#include <Div.hpp>

Inheritance diagram for psychic_ui::Div:
psychic_ui::Observer psychic_ui::Component< AvatarSkin > psychic_ui::Component< ButtonSkin > psychic_ui::Component< CheckBoxSkin > psychic_ui::Component< ColorSwatchesSkin > psychic_ui::Component< MenuButtonSkin > psychic_ui::Component< ScrollBarSkin > psychic_ui::Component< SegmentedControlSkin > psychic_ui::Component< SwitchSkin > psychic_ui::Component< RangeSkin > psychic_ui::DataContainer< std::shared_ptr< MenuItem > > psychic_ui::DataContainer< std::string > psychic_ui::AppShell psychic_ui::Badge psychic_ui::Box psychic_ui::Chip psychic_ui::Component< T, Base > psychic_ui::DataContainer< T > psychic_ui::EmptyState psychic_ui::Icon psychic_ui::Inspector psychic_ui::InspectorField psychic_ui::InspectorSection psychic_ui::Kbd psychic_ui::Overlay psychic_ui::PageHeader psychic_ui::Popup psychic_ui::RowGroup psychic_ui::Scroller psychic_ui::Select psychic_ui::SelectableRow psychic_ui::Shape psychic_ui::SidebarHeader psychic_ui::SidebarSection psychic_ui::Spacer psychic_ui::StatusDot psychic_ui::TabContainer< T > psychic_ui::Text psychic_ui::TextFieldBase psychic_ui::TitleBar psychic_ui::Toast psychic_ui::ToolBar psychic_ui::TreeNode psychic_ui::Window psychic_ui::WindowControls psychic_ui::internal::SkinBase

Classes

struct  Exit
struct  LayoutSlide
struct  SlideWalk

Public Member Functions

 Div (const Div &)=delete
Div & operator= (const Div &)=delete
 Div (Div &&)=delete
Div & operator= (Div &&)=delete
std::string toString () const
virtual Window * window ()
virtual const Window * window () const
Div * parent ()
const Div * parent () const
int depth () const
unsigned int childCount () const
const std::vector< std::shared_ptr< Div > > & children () const
template<class T, class... Args>
requires (std::derived_from<T, Div> && std::constructible_from<T, Args...>)
T & add (Args &&... args)
template<class T>
requires std::derived_from<T, Div>
T & add (unsigned int index, std::shared_ptr< T > child)
template<class T>
requires std::derived_from<T, Div>
T & add (std::shared_ptr< T > child)
void remove (unsigned int index)
void remove (const std::shared_ptr< Div > &child)
void remove (const Div &child)
void removeAll ()
const Div * at (unsigned int index) const
Div * at (unsigned int index)
int childIndex (const std::shared_ptr< Div > &child) const
int childIndex (const Div *child) const
template<class Self>
Self & transition (this Self &self, Property property, const Timing &timing)
template<class Self>
Self & transition (this Self &self, std::initializer_list< Property > properties, const Timing &timing)
template<class Self>
Self & row (this Self &self)
template<class Self>
Self & column (this Self &self)
template<class Self>
Self & size (this Self &self, Length width, Length height)
template<class Self>
Self & style (this Self &self, const Style &style)
const Style & style () const
const Style & computedStyle () const
Style targetStyle () const
bool transitioning () const
bool transitioning (Property property) const
void animate (float from, float to, const Timing &timing, std::function< void(float)> update)
template<class Self>
Self & startingClass (this Self &self, detail::StringArg className)
const std::string & startingClass () const
bool starting () const
void exit (const std::string &className, std::function< void()> done)
bool exiting () const
void cancelExit ()
bool subtreeTransitioning () const
float layoutOffsetX () const
float layoutOffsetY () const
bool layoutSliding () const
bool visible () const
bool enabled () const
template<class Self>
Self & enabled (this Self &self, detail::BoolArg enabled)
virtual bool active () const
bool focusEnabled () const
template<class Self>
Self & focusEnabled (this Self &self, detail::BoolArg focusEnabled)
bool hasFocus () const
virtual bool takesEscape () const
void setFocused (bool focused)
const std::string & tooltip () const
template<class Self>
Self & tooltip (this Self &self, const std::string &text)
const std::vector< std::shared_ptr< MenuItem > > & contextMenu () const
template<class Self>
Self & contextMenu (this Self &self, std::vector< std::shared_ptr< MenuItem > > items)
void localToGlobal (int &gx, int &gy, int x=0, int y=0) const
void globalToLocal (int &lx, int &ly, int x=0, int y=0) const
int x () const
int y () const
int getWidth () const
int getHeight () const
int boundsLeft () const
int boundsTop () const
int boundsRight () const
int boundsBottom () const
int contentWidth () const
int contentHeight () const
int scrollX () const
template<class Self>
Self & scrollX (this Self &self, int scrollX)
int scrollY () const
template<class Self>
Self & scrollY (this Self &self, int scrollY)
void scroll (double scrollX, double scrollY)
bool scrollBy (int deltaX, int deltaY)
void scrollIntoView (const SkRect &rect)
StyleManager * styleManager () const
void setStyleManager (std::shared_ptr< StyleManager > styleManager)
void updateStyle ()
void updateStyleRecursive ()
void updateDirtyStyles ()
bool styleDirty () const
const std::vector< std::string > & tags () const
const std::string & internalId () const
const std::string & id () const
template<class Self>
Self & id (this Self &self, std::string id)
const std::unordered_set< std::string > & classNames () const
template<class Self>
Self & classNames (this Self &self, const std::unordered_set< std::string > &classNames)
template<class Self>
Self & addClassName (this Self &self, std::string className)
template<class Self>
Self & removeClassName (this Self &self, std::string className)
virtual const PropertyMask & inheritedProperties () const
bool mouseChildren () const
template<class Self>
Self & mouseChildren (this Self &self, detail::BoolArg mouseChildren)
bool mouseEnabled () const
template<class Self>
Self & mouseEnabled (this Self &self, detail::BoolArg mouseEnabled)
bool mouseOver () const
void setMouseOver (bool over)
bool getMouseDown () const
void setMouseDown (bool down)
bool contains (float x, float y) const
bool boundsContains (float x, float y) const
virtual MouseEventStatus handleMouseMove (const MouseEvent &event, bool handled)
virtual bool handleMouseExit (const MouseEvent &event)
virtual MouseEventStatus handleMouseButtonChange (const MouseEvent &event)
virtual MouseEventStatus handleMousePress (const MouseEvent &event)
virtual MouseEventStatus handleMouseRelease (const MouseEvent &event)
virtual MouseEventStatus handleClick (const MouseEvent &event)
virtual MouseEventStatus handleDoubleClick (const MouseEvent &event)
virtual MouseEventStatus handleMouseScroll (const MouseEvent &event)
virtual MouseEventStatus handleContextMenuRequest (const MouseEvent &event)
MouseEvent mouseEventAtCenter ()
MouseEvent localMouseEvent (const MouseEvent &event) const
Public Member Functions inherited from psychic_ui::Observer
 Observer (const Observer &)=delete
Observer & operator= (const Observer &)=delete
 Observer (Observer &&)=delete
Observer & operator= (Observer &&)=delete

Public Attributes

Signal< int, int > scrolled {}
Signal< int, int > resized {}
bool dashed {false}
Signal< MouseEvent > mouseButtonChanged {}
Signal< MouseEvent > mousePressed {}
Signal< MouseEvent > mouseReleased {}
Signal< MouseEvent > mouseReleasedOutside {}
Signal< MouseEvent > mouseMoved {}
Signal< MouseEvent > mouseEntered {}
Signal< MouseEvent > mouseExited {}
Signal< MouseEvent > mouseScrolled {}
Signal< MouseEvent > clicked {}
Signal< MouseEvent > doubleClicked {}
Signal< MouseEvent > contextMenuRequested {}
Signal< Key, Mod > keyPressed {}
Signal< Key, Mod > keyRepeated {}
Signal< Key, Mod > keyReleased {}
Signal< icu::UnicodeString > typed {}
Signal focused {}
Signal blurred {}

Static Public Attributes

static bool debugLayout {false}

Protected Member Functions

void updateContextMenu (std::vector< std::shared_ptr< MenuItem > > items)
void setParent (Div *parent)
virtual void added ()
virtual void removed ()
virtual void childAdded (Div &child)
virtual void childRemoved (Div &child)
template<class T>
requires std::derived_from<T, Div>
T * trackChild (std::vector< std::shared_ptr< T > > &list, Div &child) const
virtual void addedToRender ()
virtual void removedFromRender ()
std::vector< std::shared_ptr< Div > > childrenTopmostFirst () const
void invalidateEndChildrenStyle ()
void insertChild (unsigned int index, std::shared_ptr< Div > child)
void updateEnabled (bool enabled)
void updateId (std::string id)
void updateClassNames (const std::unordered_set< std::string > &classNames)
void updateClassName (std::string className, bool present)
void scrollTo (int scrollX, int scrollY)
virtual void enabledChanged ()
template<class Self>
Self & tag (this Self &self, std::string tag)
void addTag (std::string tag)
void updateLayoutSlides (const SlideWalk &walk)
void updateSlidingClass ()
void releaseStartingClass ()
void finishExit ()
void updateTransitions (Style &computed)
bool advanceTransitions (std::chrono::nanoseconds now)
void finishTransitions ()
void cancelTransitions ()
void transitionsChanged (const PropertyMask &changed)
void invalidateStyle ()
void updateRuntimeStyles ()
virtual void createStyles ()
virtual void styleUpdated ()
void setMeasurable ()
void updateLayout (const PropertyMask &changed)
virtual void layoutUpdated ()
void invalidate ()
bool isValid () const
virtual Size measure (Constraint width, Constraint height)
virtual void render (SkCanvas *canvas)
void clip (SkCanvas *canvas)
virtual void draw (SkCanvas *canvas)
void drawShadow (SkCanvas *canvas)
void drawDotGrid (SkCanvas *canvas)
void drawOutline (SkCanvas *canvas)
Protected Member Functions inherited from psychic_ui::Observer
template<class... T, class F>
std::shared_ptr< Slot< T... > > subscribeTo (Signal< T... > &signal, F &&callback)

Static Protected Member Functions

template<class T>
requires std::derived_from<T, Div>
static T * untrackChild (std::vector< std::shared_ptr< T > > &list, const Div &child)

Protected Attributes

std::string _tooltip {}
std::vector< std::shared_ptr< MenuItem > > _contextMenu {}
ScopedSlot _contextMenuSlot {}
bool _enabled {true}
bool _visible {true}
int _x {0}
int _y {0}
int _width {0}
int _height {0}
int _boundsLeft {0}
int _boundsTop {0}
int _boundsRight {0}
int _boundsBottom {0}
bool _focusEnabled {false}
bool _focused {false}
int _depth {0}
Div * _parent {nullptr}
std::vector< std::shared_ptr< Div > > _children {}
std::vector< std::string > _tags {}
std::string _internalId {}
std::string _id {}
std::unordered_set< std::string > _classNames {}
std::shared_ptr< StyleManager > _styleManager {nullptr}
Style _defaultStyle
Style _inlineStyle
Style _computedStyle {}
bool _layoutInitialized {false}
bool _styleDirty {true}
bool _descendantStyleDirty {false}
Window * _styledIn {nullptr}
std::size_t _styledGeneration {0}
std::shared_ptr< detail::StyleTransitions > _transitions {}
std::vector< std::shared_ptr< Animation > > _animations {}
std::string _startingClass {}
bool _startingApplied {false}
std::unique_ptr< Exit > _exit {}
std::unique_ptr< LayoutSlide > _layoutSlide {}
YGNode * _yogaNode {nullptr}
SkRect _rect {}
SkRect _marginRect {}
float _marginLeft {0.0f}
float _marginRight {0.0f}
float _marginTop {0.0f}
float _marginBottom {0.0f}
SkRect _paddedRect {}
SkRRect _roundRect {}
SkRect _boundsRect {}
float _paintOutset {0.0f}
bool _ignoreInternalLayoutContraints {false}
bool layoutReady {false}
bool _drawBackground {false}
bool _drawBorder {false}
bool _drawComplexBorders {false}
bool _drawRoundRect {false}
bool _drawComplexRoundRect {false}
float _radiusTopLeft {0.0f}
float _radiusTopRight {0.0f}
float _radiusBottomLeft {0.0f}
float _radiusBottomRight {0.0f}
std::array< SkVector, 4 > _radii {}
float _borderLeft {0.0f}
float _borderRight {0.0f}
float _borderTop {0.0f}
float _borderBottom {0.0f}
int _scrollX {0}
int _scrollY {0}
bool _mouseEnabled {true}
bool _mouseChildren {true}
bool _mouseOver {false}
bool _mouseDown {false}
Protected Attributes inherited from psychic_ui::Observer
std::vector< ScopedSlot > slots {}

Static Protected Attributes

static int idCounter = 0

Friends

class StyleManager
class Window
class detail::StyleTransitions

Detailed Description

The Div class is the main object used to display content in Psychic UI. It has a similar role as a div in html: its purpose is to offer a rectangular container than can be used in a layout and styled using a stylesheet.

Constructor & Destructor Documentation

◆ Div()

psychic_ui::Div::Div ( const Div & )
delete

Just as a safety for now, delete the copy constructor because I don't see a reason why we would need it.

Member Function Documentation

◆ add() [1/3]

template<class T, class... Args>
requires (std::derived_from<T, Div> && std::constructible_from<T, Args...>)
T & psychic_ui::Div::add ( Args &&... args)
inline

Construct a child of type T and add it last. The parent owns the child:

auto &row = add<Div>().row().gap(12);
row.add<Button>("Save").onClick([this] { save(); });
Returns
The child, valid while this div holds it

◆ add() [2/3]

template<class T>
requires std::derived_from<T, Div>
T & psychic_ui::Div::add ( std::shared_ptr< T > child)
inline

Add an existing child last (moved there if it is one already)

Returns
The child

◆ add() [3/3]

template<class T>
requires std::derived_from<T, Div>
T & psychic_ui::Div::add ( unsigned int index,
std::shared_ptr< T > child )
inline

Add an existing child at index (in document order), at most childCount(): std::out_of_range past it, std::invalid_argument for no child. A child that has a parent leaves it first (this one too: the index is then among the other children), as the DOM moves a node.

Returns
The child

◆ added()

void psychic_ui::Div::added ( )
protectedvirtual

Reimplemented in psychic_ui::TreeNode.

◆ advanceTransitions()

bool psychic_ui::Div::advanceTransitions ( std::chrono::nanoseconds now)
protected

Put the transitions' values at now in the computed style

Returns
Whether one still runs

◆ animate()

void psychic_ui::Div::animate ( float from,
float to,
const Timing & timing,
std::function< void(float)> update )

Move a number from from to to with a timing, calling update with each value (in Window::updateAnimations, once per frame, the last time with to). Fire and forget: it ends with this div, or when it gets there. At once when the div isn't in a window or the window reduces motion.

div.animate(0.0f, 1.0f, Timing{150ms, Ease::Out}, [this](float t) { _reveal = t; });

◆ at() [1/2]

Div * psychic_ui::Div::at ( unsigned int index)

Get the child at index, in document order (0 is the first child, drawn at the back)

Parameters
indexIndex of the child to retrieve, < childCount() (std::out_of_range otherwise)
Returns
Pointer to the Div at index

◆ at() [2/2]

const Div * psychic_ui::Div::at ( unsigned int index) const

Get the child at index, in document order (0 is the first child, drawn at the back)

Parameters
indexIndex of the child to retrieve, < childCount() (std::out_of_range otherwise)
Returns
Const pointer to the Div at index

◆ cancelExit()

void psychic_ui::Div::cancelExit ( )

Stay after all: lose the exit's class (its transitions head back) and give the mouse back; done won't run

◆ cancelTransitions()

void psychic_ui::Div::cancelTransitions ( )
protected

Drop the transitions, leaving the computed style where they were (removed from the window)

◆ childAdded()

void psychic_ui::Div::childAdded ( Div & child)
protectedvirtual

A child joined this div, by any path (add, or moved here from another parent): it is in the children, its parent is this one and its added() ran, before its first style. For a div that keeps a typed list of some of its children (the overlay's popups, the toast stack's toasts), so that the children owe it nothing.

Reimplemented in psychic_ui::Overlay, and psychic_ui::ToastStack.

◆ childCount()

unsigned int psychic_ui::Div::childCount ( ) const

Get the Div's number of children

Returns
NUmber of children

◆ childIndex() [1/2]

int psychic_ui::Div::childIndex ( const Div * child) const

Get the index of a child by pointer, in document order

Parameters
childPointer to a child
Returns
Index of the child, -1 if it isn't a child

◆ childIndex() [2/2]

int psychic_ui::Div::childIndex ( const std::shared_ptr< Div > & child) const

Get the index of a child by shared pointer, in document order

Parameters
childShared pointer to a child
Returns
Index of the child, -1 if it isn't a child

◆ childRemoved()

void psychic_ui::Div::childRemoved ( Div & child)
protectedvirtual

A child left this div, by any path (remove, removeAll, added to another parent): it is out of the children and its removed() ran, before the focus it had moves (its parent() still answers this one until the call returns). The counterpart of childAdded.

Reimplemented in psychic_ui::Overlay, and psychic_ui::ToastStack.

◆ children()

const std::vector< std::shared_ptr< Div > > & psychic_ui::Div::children ( ) const

The children, in document order. Don't add or remove children while iterating over it.

◆ childrenTopmostFirst()

std::vector< std::shared_ptr< Div > > psychic_ui::Div::childrenTopmostFirst ( ) const
protected

Copy of the children, topmost (last) first, for dispatching mouse events. A copy so that handlers can add or remove children while we iterate.

◆ classNames()

template<class Self>
Self & psychic_ui::Div::classNames ( this Self & self,
const std::unordered_set< std::string > & classNames )
inline

Replace the class names, matched by .class selectors (case insensitive)

◆ column()

template<class Self>
Self & psychic_ui::Div::column ( this Self & self)
inline

Lay the children out in a column, shortcut for direction(Direction::Column)

◆ computedStyle()

const Style & psychic_ui::Div::computedStyle ( ) const

The computed style: what the stylesheets, the parent and the inline and default styles give this div, as of the last style pass, with its running transitions' values: what it paints with and pushes to Yoga. While a property transitions it holds the blend, updated every frame (and styleUpdated runs again); targetStyle() has where it goes.

◆ contextMenu()

const std::vector< std::shared_ptr< MenuItem > > & psychic_ui::Div::contextMenu ( ) const
inline

The menu the div opens where a context menu is asked for on it (contextMenuRequested: a right press, a touch long press, the Menu key or Shift+F10 while it or a descendant has the focus), unless a descendant opens its own; empty for none. From the keyboard, the menu starts at its first item.

◆ createStyles()

virtual void psychic_ui::Div::createStyles ( )
inlineprotectedvirtual

Create runtime styles This is called by updateRuntimeStyles and has to be overridden by div's that want to add rules to the stylesheet. It will be called during the app's lifetime when adding to render list or if a stylesheet is loaded.

◆ depth()

int psychic_ui::Div::depth ( ) const

Get the depth of this Div in the display hiarchy.

Returns
Depth of the Div

◆ draw()

void psychic_ui::Div::draw ( SkCanvas * canvas)
protectedvirtual

◆ drawShadow()

void psychic_ui::Div::drawShadow ( SkCanvas * canvas)
protected

The shadow* and outline* styles, around the border box: every div paints them, whatever its draw

◆ enabled()

template<class Self>
Self & psychic_ui::Div::enabled ( this Self & self,
detail::BoolArg enabled )
inline

Enable or disable the div (:disabled in stylesheets). Subclasses react in enabledChanged().

◆ enabledChanged()

virtual void psychic_ui::Div::enabledChanged ( )
inlineprotectedvirtual

Called when enabled(bool) changes the enabled state

Reimplemented in psychic_ui::NumberStepper, and psychic_ui::TextFieldBase.

◆ exit()

void psychic_ui::Div::exit ( const std::string & className,
std::function< void()> done )

Leave with transitions: give it className, whose rules say where its transitions go (a popup's exiting), take the mouse from it and its descendants, and call done (which removes it) once neither it nor a descendant transitions any more, after the style pass that follows (Window::updateStylesAndLayout). At once when it isn't in a window, was never painted (starting()) or the window reduces motion. A no-op while it exits. Leaving the window ends it without calling done.

◆ exiting()

bool psychic_ui::Div::exiting ( ) const
inline

Whether it is leaving (exit)

◆ finishExit()

void psychic_ui::Div::finishExit ( )
protected

The exit is over (nothing of it transitions): undo it and call done

◆ focusEnabled()

template<class Self>
Self & psychic_ui::Div::focusEnabled ( this Self & self,
detail::BoolArg focusEnabled )
inline

Whether the div can take the focus (:focus in stylesheets)

◆ handleMouseButtonChange()

MouseEventStatus psychic_ui::Div::handleMouseButtonChange ( const MouseEvent & event)
virtual

Reimplemented in psychic_ui::Window.

◆ handleMouseMove()

MouseEventStatus psychic_ui::Div::handleMouseMove ( const MouseEvent & event,
bool handled )
virtual

Reimplemented in psychic_ui::Window.

◆ handleMouseScroll()

MouseEventStatus psychic_ui::Div::handleMouseScroll ( const MouseEvent & event)
virtual

Reimplemented in psychic_ui::NumberStepper.

◆ id()

template<class Self>
Self & psychic_ui::Div::id ( this Self & self,
std::string id )
inline

Set the id, matched by #id selectors (case insensitive)

◆ inheritedProperties()

const PropertyMask & psychic_ui::Div::inheritedProperties ( ) const
virtual

The properties this div takes from its parent's computed style when no rule sets them

Reimplemented in psychic_ui::internal::SkinBase.

◆ insertChild()

void psychic_ui::Div::insertChild ( unsigned int index,
std::shared_ptr< Div > child )
protected

Insert a child in both the children and the Yoga node, then parent it (which styles it)

◆ invalidateEndChildrenStyle()

void psychic_ui::Div::invalidateEndChildrenStyle ( )
protected

Invalidate the style of the first and last children, whose :first-child/:last-child state changes when children are added or removed

◆ invalidateStyle()

void psychic_ui::Div::invalidateStyle ( )
protected

Invalidate the style

◆ layoutOffsetX()

float psychic_ui::Div::layoutOffsetX ( ) const

Where it is painted from where its layout puts it, as it slides there: a layout transition, its parent's layoutTransition (FLIP). After a layout that moved it in the window, scrolling aside, it is painted from where it was (from where it was painted, when it was sliding already) and the offset goes to 0 with that timing; Yoga runs once. Composed with its translateX/translateY, painting only (hit testing finds it at its layout place). Nothing slides on its first layout in that container (an added child appears in place, and so does one shown again), on a window resize, with new rules (a theme, a density, a skin set) or with reduced motion. Its size doesn't animate.

◆ layoutSliding()

bool psychic_ui::Div::layoutSliding ( ) const

Whether it slides to its layout place (layoutOffsetX/Y aren't 0). It has the sliding class meanwhile (styled before the paint that starts it; its rules should only paint, a row's opaque background), and is painted after its siblings that don't slide.

◆ layoutUpdated()

void psychic_ui::Div::layoutUpdated ( )
protectedvirtual

Callback for when layout was updated

Reimplemented in psychic_ui::Text, and psychic_ui::TextFieldBase.

◆ localMouseEvent()

MouseEvent psychic_ui::Div::localMouseEvent ( const MouseEvent & event) const

The event moved from the parent's content coordinates into this div's

◆ measure()

Size psychic_ui::Div::measure ( Constraint width,
Constraint height )
protectedvirtual

The size of a measurable div's content (see setMeasurable), within what the layout offers in each dimension. Must be pure: the layout caches it and calls it with various constraints.

Reimplemented in psychic_ui::Icon, and psychic_ui::Text.

◆ mouseChildren()

template<class Self>
Self & psychic_ui::Div::mouseChildren ( this Self & self,
detail::BoolArg mouseChildren )
inline

Whether the children get mouse events (this div still does)

◆ mouseEnabled()

template<class Self>
Self & psychic_ui::Div::mouseEnabled ( this Self & self,
detail::BoolArg mouseEnabled )
inline

Whether this div gets mouse events; they pass through it when not (see mouseChildren for its children)

◆ mouseEventAtCenter()

MouseEvent psychic_ui::Div::mouseEventAtCenter ( )

An event at this div's center, for what the keyboard does in place of the mouse (a click by Enter, a context menu by the Menu key): no button (set the one it stands for), clickCount 0, the window's input mode as source

◆ operator=()

Div & psychic_ui::Div::operator= ( const Div & )
delete

Just as a safety for now, delete the copy constructor because I don't see a reason why we would need it.

◆ parent() [1/2]

Div * psychic_ui::Div::parent ( )

If the div is included in a parent, returns a pointer to that parent

Returns
Pointer to parent Div, if any

◆ parent() [2/2]

const Div * psychic_ui::Div::parent ( ) const

If the div is included in a parent, returns a const pointer to that parent

Returns
Const pointer to parent Div, if any

◆ releaseStartingClass()

void psychic_ui::Div::releaseStartingClass ( )
protected

Lose the starting class (the window lets it go): its next style transitions from it

◆ remove() [1/2]

void psychic_ui::Div::remove ( const std::shared_ptr< Div > & child)

Remove a child, does nothing if it isn't one (nullptr included)

◆ remove() [2/2]

void psychic_ui::Div::remove ( unsigned int index)

Remove a child by index

Parameters
indexIndex of the child to remove, < childCount() (std::out_of_range otherwise)

◆ removeAll()

void psychic_ui::Div::removeAll ( )

Remove all children

◆ row()

template<class Self>
Self & psychic_ui::Div::row ( this Self & self)
inline

Lay the children out in a row, shortcut for direction(Direction::Row)

◆ scrollBy()

bool psychic_ui::Div::scrollBy ( int deltaX,
int deltaY )

Scroll by a number of window units, within the content (touch panning)

Returns
Whether the scroll position changed

◆ scrollIntoView()

void psychic_ui::Div::scrollIntoView ( const SkRect & rect)

Scroll the nearest scrolling ancestor (overflow: scroll) vertically, just enough for a rectangle of this div to show; to its start when only what is above the rectangle there would be left out (a border, a header, a padding)

Parameters
rectIn this div's coordinates (from its top-left corner, plus its scroll offset, as localToGlobal)

◆ setFocused()

void psychic_ui::Div::setFocused ( bool focused)

Used by the window, which manages the focus path

◆ setMeasurable()

void psychic_ui::Div::setMeasurable ( )
protected

Sets the component as measurable Registers the measure callback

◆ setParent()

void psychic_ui::Div::setParent ( Div * parent)
protected

Set the parent of that div Used internally when adding/removing a child to/from a parent

Parameters
Div*parent

◆ setStyleManager()

void psychic_ui::Div::setStyleManager ( std::shared_ptr< StyleManager > styleManager)

Set the local style manager override

◆ size()

template<class Self>
Self & psychic_ui::Div::size ( this Self & self,
Length width,
Length height )
inline

Shortcut for width(width).height(height)

◆ starting()

bool psychic_ui::Div::starting ( ) const

Whether it, or an ancestor, still has its starting class

◆ startingClass()

template<class Self>
Self & psychic_ui::Div::startingClass ( this Self & self,
detail::StringArg className )
inline

A class it has for its first style in a window only (its first style after it is added), lost before its first paint, so that its transitions start from what that class's rules give it, as CSS's @starting-style: a popup's entering. Its descendants' first styles see it too. Until the window lets it go (Window::updateStylesAndLayout, after the layout and the popups' placement) nothing of it or its descendants transitions: it was never painted. Nothing starts that way with reduced motion.

◆ style() [1/2]

const Style & psychic_ui::Div::style ( ) const

The inline style, as set through the setters above

◆ style() [2/2]

template<class Self>
Self & psychic_ui::Div::style ( this Self & self,
const Style & style )
inline

Overlay a whole style onto the inline style, for reusing a set of values:

const Style card = Style{}.padding(12).borderRadius(4).backgroundColor(rgb(0x202020));
add<Div>().style(card).grow(1);

◆ styleDirty()

bool psychic_ui::Div::styleDirty ( ) const

Whether this node or one of its descendants needs its style computed

◆ styleManager()

StyleManager * psychic_ui::Div::styleManager ( ) const

Get the current style manager In order of importance, the local override, the parent's (until window) or the singleton

Returns
StyleManager *

◆ styleUpdated()

◆ subtreeTransitioning()

bool psychic_ui::Div::subtreeTransitioning ( ) const

Whether it or a descendant transitions

◆ tag()

template<class Self>
Self & psychic_ui::Div::tag ( this Self & self,
std::string tag )
inlineprotected

Add a tag to the chain read by tags(): each class in the hierarchy adds its own, so selectors can match any of them. Obviously this should be static and/or use Reflection but in order to progress in other parts of the library it will stay local for the time being, until a better technique is implemented.

◆ takesEscape()

virtual bool psychic_ui::Div::takesEscape ( ) const
inlinevirtual

Whether it has a use for Escape now, while it is on the focus path: then Escape goes to the keys' path instead of closing the topmost popup first (a search field with text clears it, a number stepper being edited reverts). None by default.

Reimplemented in psychic_ui::NumberStepper, and psychic_ui::SearchField.

◆ targetStyle()

Style psychic_ui::Div::targetStyle ( ) const

The computed style with every running transition at its end: what computedStyle() will be once they are done. A copy.

◆ tooltip()

const std::string & psychic_ui::Div::tooltip ( ) const
inline

A short text the window shows in a tooltip above the div (below when there's no room) after the mouse rests on it, or after a touch long press that opens nothing else; "" for none

◆ toString()

std::string psychic_ui::Div::toString ( ) const

Get a string representing this Div for debug purposes

Returns
String used to identify a component in a log

◆ trackChild()

template<class T>
requires std::derived_from<T, Div>
T * psychic_ui::Div::trackChild ( std::vector< std::shared_ptr< T > > & list,
Div & child ) const
inlineprotected

From childAdded: put the child in list, the children that are a T in document order, if it is one

Returns
The child as a T, or nullptr

◆ transition()

template<class Self>
Self & psychic_ui::Div::transition ( this Self & self,
Property property,
const Timing & timing )
inline

Add to the inline transition: these properties blend to their new values with this timing (see Transition)

div.transition(Property::backgroundColor, Timing{100ms});

◆ transitioning()

bool psychic_ui::Div::transitioning ( ) const

Whether a property of the computed style is blending to a new value

◆ transitionsChanged()

void psychic_ui::Div::transitionsChanged ( const PropertyMask & changed)
protected

The transitions changed these computed values: push them to Yoga, run styleUpdated, restyle the children that inherit them

◆ untrackChild()

template<class T>
requires std::derived_from<T, Div>
T * psychic_ui::Div::untrackChild ( std::vector< std::shared_ptr< T > > & list,
const Div & child )
inlinestaticprotected

From childRemoved: take the child out of list

Returns
The child as a T, or nullptr if it wasn't in it

◆ updateDirtyStyles()

void psychic_ui::Div::updateDirtyStyles ( )

Compute style only where it was invalidated: nodes whose style is dirty and their descendants, reached through the _descendantStyleDirty flags, visible or not (hidden nodes still take part in layout). One pass: styles invalidated by a styleUpdated callback during the pass may be left dirty, check styleDirty() and run it again (Window::updateStylesAndLayout does).

◆ updateLayout()

void psychic_ui::Div::updateLayout ( const PropertyMask & changed)
protected

Push the computed style's layout properties to the Yoga node, only those in changed. Paint-only properties never reach Yoga, so changing them doesn't dirty the layout. The layoutUpdated() method will be called after Yoga has computed the new layout

◆ updateLayoutSlides()

void psychic_ui::Div::updateLayoutSlides ( const SlideWalk & walk)
protected

After a layout (Window::updateStylesAndLayout), down the tree: start, retarget or drop the layout slides

◆ updateRuntimeStyles()

void psychic_ui::Div::updateRuntimeStyles ( )
protected

Update the runtime style rules

◆ updateSlidingClass()

void psychic_ui::Div::updateSlidingClass ( )
protected

The sliding class while layoutSliding()

◆ updateStyle()

void psychic_ui::Div::updateStyle ( )

Compute style for this component and push it to its Yoga node

◆ updateStyleRecursive()

void psychic_ui::Div::updateStyleRecursive ( )

Compute style for this component and all its descendants, visible or not

◆ updateTransitions()

void psychic_ui::Div::updateTransitions ( Style & computed)
protected

Start, retarget or drop transitions for a new computed style, and put their current values in it

◆ visible()

bool psychic_ui::Div::visible ( ) const

Whether the div is painted and hit, from its computed visible style. Hidden divs are still laid out.

◆ window()

Window * psychic_ui::Div::window ( )
virtual

If the div is included in a window, returns a pointer to that window

Returns
Pointer to owning window, if any

Reimplemented in psychic_ui::Window.

Member Data Documentation

◆ _animations

std::vector<std::shared_ptr<Animation> > psychic_ui::Div::_animations {}
protected

animate's, until they end

◆ _boundsRect

SkRect psychic_ui::Div::_boundsRect {}
protected

Bounds rect

◆ _children

std::vector<std::shared_ptr<Div> > psychic_ui::Div::_children {}
protected

Children in document order (same as Yoga): first is at the back, last is on top

◆ _classNames

std::unordered_set<std::string> psychic_ui::Div::_classNames {}
protected

Pseudo CSS class names

◆ _computedStyle

Style psychic_ui::Div::_computedStyle {}
protected

Computed Style Computed style values, use this to obtain the final style to be applied

◆ _defaultStyle

Style psychic_ui::Div::_defaultStyle
protected

Default Style Use this instead of the inline style when a component needs a specific default for it to work correctly For example, text components should not grow/shrink as they are inline, but yoga doesn't let us do that.

◆ _descendantStyleDirty

bool psychic_ui::Div::_descendantStyleDirty {false}
protected

A descendant has a dirty style, so the style pass has to go through this node

◆ _id

std::string psychic_ui::Div::_id {}
protected

Id

◆ _ignoreInternalLayoutContraints

bool psychic_ui::Div::_ignoreInternalLayoutContraints {false}
protected

Ignore internal layout constraints (padding, border) Used by component to forward those to its skin

◆ _inlineStyle

Style psychic_ui::Div::_inlineStyle
protected

Inline Style Use the inline styles to set values that will override any stylesheet

◆ _layoutInitialized

bool psychic_ui::Div::_layoutInitialized {false}
protected

Whether the computed style was pushed to the Yoga node once: until then every layout property is

◆ _marginRect

SkRect psychic_ui::Div::_marginRect {}
protected

Component's margin rect

◆ _mouseChildren

bool psychic_ui::Div::_mouseChildren {true}
protected

Enables the mouse events for this div's children Events will still affect the current div See mouseEnabled for ignoring events on this div

◆ _mouseEnabled

bool psychic_ui::Div::_mouseEnabled {true}
protected

Enable the mouse events for this div. Events will passthrough if disabled See mouseChildren for ignoring the children

◆ _paddedRect

SkRect psychic_ui::Div::_paddedRect {}
protected

Component's padded rect

◆ _paintOutset

float psychic_ui::Div::_paintOutset {0.0f}
protected

How far the shadow and the outline paint outside the border box, for culling and the opacity layer

◆ _rect

SkRect psychic_ui::Div::_rect {}
protected

Component's rect

◆ _roundRect

SkRRect psychic_ui::Div::_roundRect {}
protected

Round rect

◆ _startingClass

std::string psychic_ui::Div::_startingClass {}
protected

startingClass, and whether it has it now (from its first style in a window until the window lets it go)

◆ _styledIn

Window* psychic_ui::Div::_styledIn {nullptr}
protected

The window, and the style manager's rules generation, the style was last computed in: transitions only start from a style computed in the same window with the same rules, so neither a div's first style in a window nor a theme switch transitions

◆ _styleDirty

bool psychic_ui::Div::_styleDirty {true}
protected

Dirty style flag

◆ _styleManager

std::shared_ptr<StyleManager> psychic_ui::Div::_styleManager {nullptr}
protected

Style Manager Override

◆ _tags

std::vector<std::string> psychic_ui::Div::_tags {}
protected

Chain of tags from the inheritance chain

◆ _transitions

std::shared_ptr<detail::StyleTransitions> psychic_ui::Div::_transitions {}
protected

The running style transitions, which the window ticks (made with the first one)

◆ _yogaNode

YGNode* psychic_ui::Div::_yogaNode {nullptr}
protected

Yoga Node

◆ contextMenuRequested

Signal<MouseEvent> psychic_ui::Div::contextMenuRequested {}

Asks for a context menu here: a right button press (a touch long press is one), or the Menu key or Shift+F10 on the focused div (its center, clickCount 0). Goes to the deepest div with a subscriber.

◆ idCounter

int psychic_ui::Div::idCounter = 0
staticprotected

Internal Id


The documentation for this class was generated from the following files: