psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::Window Class Reference
Inheritance diagram for psychic_ui::Window:
psychic_ui::Div psychic_ui::Observer

Public Types

using GestureTime = std::chrono::nanoseconds

Public Member Functions

 Window (std::string title)
 Window (const Window &)=delete
Window & operator= (const Window &)=delete
 Window (Window &&)=delete
Window & operator= (Window &&)=delete
Window * window () override
const Window * window () const override
std::string getTitle () const
void setTitle (const std::string &title)
bool getResizable () const
void setResizable (bool resizable)
bool getDecorated () const
void setDecorated (bool decorated)
void toggleMinimized ()
bool minimized () const
void setMinimized (bool minimized)
void toggleMaximized ()
bool maximized () const
void setMaximized (bool maximized)
void toggleFullscreen ()
bool getFullscreen () const
void setFullscreen (bool fullscreen)
bool windowVisible () const
void setWindowVisible (bool value)
void startDrag ()
void stopDrag ()
bool supportsDrag () const
void addDragArea (const std::shared_ptr< Div > &div)
bool isDragArea (int x, int y)
int windowX () const
int windowY () const
void setWindowPosition (int x, int y)
int windowWidth () const
int windowHeight () const
void setWindowSize (int width, int height)
void open (SystemWindow *systemWindow)
SystemWindow * systemWindow () const
void close ()
void drawAll ()
void updateStylesAndLayout ()
void paint (SkCanvas *canvas, float pixelRatio)
bool needsFrame () const
std::optional< std::chrono::nanoseconds > nextFrameTime () const
std::optional< std::chrono::nanoseconds > untilNextFrame (std::chrono::nanoseconds now) const
void requestFrame ()
void post (std::function< void()> task)
void runPosted ()
void updateAnimations (std::chrono::nanoseconds now)
std::optional< std::chrono::nanoseconds > animationClock () const
void startAnimation (const std::shared_ptr< Animation > &animation)
bool animating () const
bool reducedMotion () const
template<class Self>
Self & reducedMotion (this Self &self, detail::BoolArg reduced)
float animationSpeed () const
template<class Self>
Self & animationSpeed (this Self &self, detail::FloatArg speed)
Div & appContainer () const
Overlay & overlay () const
Menu & openMenu (const MenuItems &items, int x, int y)
Menu & openMenu (const MenuItems &items, Div &anchor, Side side=Side::Bottom, PopupAlign align=PopupAlign::Start)
Menu & openMenu (const std::shared_ptr< Menu > &menu)
Menu & openContextMenu (const MenuItems &items, float x, float y, bool fromKeyboard=false)
void closeMenu ()
Toast & toast (const ToastOptions &options)
ToastStack & toasts ()
Tooltip * tooltip () const
void updatePopups (std::chrono::nanoseconds now)
void setCursor (Cursor cursor)
InputMode inputMode () const
template<class Self>
Self & inputMode (this Self &self, InputMode mode)
virtual void handleInputModeChange (InputMode mode)
void handleTouchPress (float x, float y, GestureTime time)
void handleTouchMove (float x, float y, GestureTime time)
void handleTouchRelease (float x, float y, GestureTime time)
void handleTouchCancel (GestureTime time)
void updateGestures (GestureTime now)
bool flinging () const
template<typename T>
void loadStyleSheet (bool reset=false)
template<class S, class Self>
Self & skinSet (this Self &self)
template<class Self>
Self & skinSet (this Self &self, std::unique_ptr< SkinSet > skinSet)
const Theme & theme () const
template<class Self>
Self & theme (this Self &self, const Theme &theme)
template<class Self>
Self & followSystemTheme (this Self &self)
template<class Self>
Self & followSystemTheme (this Self &self, const Theme &light, const Theme &dark)
bool followsSystemTheme () const
ColorScheme colorScheme () const
const Theme & systemTheme () const
virtual void handleColorSchemeChange (ColorScheme scheme)
Div * focusedDiv () const
void requestFocus (Div *component, bool visible=false)
bool focusVisible () const
bool focusNext (bool backwards=false)
virtual void windowMoved (int x, int y)
virtual void windowResized (int width, int height)
virtual void windowActivated ()
virtual void windowDeactivated ()
virtual void windowMinimized ()
virtual void windowRestored ()
virtual bool windowShouldClose ()
virtual bool dropEvent (const std::vector< std::string > &)
MouseEventStatus handleMouseMove (const MouseEvent &event, bool handled) override
MouseEventStatus handleMouseScroll (const MouseEvent &event) override
MouseEventStatus handleMouseButtonChange (const MouseEvent &event) override
bool ctrlClickIsRightClick () const
template<class Self>
Self & ctrlClickIsRightClick (this Self &self, detail::BoolArg rightClick)
bool contextMenuOnRelease () const
template<class Self>
Self & contextMenuOnRelease (this Self &self, detail::BoolArg onRelease)
Div * hitSlopTarget (float x, float y, float &targetX, float &targetY)
Div * tooltipTargetAt (float x, float y)
std::string clipboardText () const
void setClipboardText (const std::string &text)
void startTextInput ()
void stopTextInput ()
void setTextInputArea (int x, int y, int width, int height, int cursor)
bool handleKeyPress (Key key, Mod mod)
bool handleKeyRepeat (Key key, Mod mod)
bool handleKeyRelease (Key key, Mod mod)
bool handleType (const icu::UnicodeString &character)
Public Member Functions inherited from psychic_ui::Div
 Div (const Div &)=delete
Div & operator= (const Div &)=delete
 Div (Div &&)=delete
Div & operator= (Div &&)=delete
std::string toString () 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 bool handleMouseExit (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 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

Static Public Member Functions

static void focusables (Div *div, std::vector< Div * > &list)

Public Attributes

Signal menuOpened {}
Signal menuClosed {}
Signal< InputMode > inputModeChanged {}
Signal< ColorScheme > colorSchemeChanged {}
Public Attributes inherited from psychic_ui::Div
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 constexpr int maxStylePasses = 4
static constexpr std::chrono::nanoseconds tooltipDelay = std::chrono::milliseconds(300)
static constexpr std::chrono::nanoseconds tooltipWarmTime = std::chrono::milliseconds(400)
static constexpr float touchSlop = 8.0f
static constexpr GestureTime longPressDelay = std::chrono::milliseconds(500)
static constexpr float flingMinVelocity = 50.0f
static constexpr float flingDecay = 0.998f
static constexpr float flingStopVelocity = 10.0f
static constexpr GestureTime flingRestDelay = std::chrono::milliseconds(100)
static constexpr std::chrono::milliseconds multiClickDelay {500}
static constexpr float multiClickDistance = 4.0f
Static Public Attributes inherited from psychic_ui::Div
static bool debugLayout {false}

Protected Types

enum class  TouchPhase : std::uint8_t {
  None , Pending , Pressing , Panning ,
  Ignored
}

Protected Member Functions

void updateReducedMotion (bool reduced)
void updateTheme (const Theme &theme)
void applyTheme (const Theme &theme)
void updateSkinSet (std::unique_ptr< SkinSet > skinSet)
void updateFollowSystemTheme (const Theme *light, const Theme *dark)
void applySystemTheme ()
void showTooltip (Div &target)
void hideTooltip (bool warm)
bool releaseStartingClasses ()
void settleExits ()
void slideLayout ()
MouseEvent touchEvent (float x, float y, MouseButton button=MouseButton::NONE, bool down=false) const
bool requestContextMenuFromKeyboard ()
void touchPressButton (MouseButton button)
void touchEnd ()
bool panBy (float dx, float dy)
Div * scrollTargetAt (float x, float y, bool horizontal)
void initSkia ()
void getSkiaSurface ()
void releaseSkia ()
Protected Member Functions inherited from psychic_ui::Div
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)

Protected Attributes

Div * app {nullptr}
Overlay * _overlay {nullptr}
std::shared_ptr< ToastStack > _toasts {}
std::shared_ptr< Tooltip > _tooltip {}
std::weak_ptr< Tooltip > _hidTooltip {}
std::weak_ptr< Div > _tooltipTarget {}
std::optional< std::chrono::nanoseconds > _tooltipSince {}
bool _tooltipSuppressed {false}
bool _tooltipWarm {false}
std::optional< std::chrono::nanoseconds > _warmSince {}
bool _touchTooltip {false}
bool _ctrlClickIsRightClick {false}
bool _ctrlClickHeld {false}
bool _contextMenuOnRelease {false}
bool _pressSwallowed {false}
MouseButton _swallowedButton {MouseButton::LEFT}
std::vector< std::weak_ptr< Animation > > _scheduledAnimations {}
std::chrono::nanoseconds _animationTime {}
std::optional< std::chrono::nanoseconds > _animationRealTime {}
float _animationSpeed {1.0f}
bool _animationClockFresh {false}
bool _reducedMotion {false}
std::atomic< bool > _frameRequested {true}
std::mutex _postedMutex {}
std::vector< std::function< void()> > _posted {}
std::atomic< bool > _hasPosted {false}
std::vector< std::weak_ptr< Div > > _startingDivs {}
std::vector< std::weak_ptr< Div > > _exitingDivs {}
std::uint64_t _slidePass {0}
std::size_t _slideGeneration {0}
int _slideWidth {0}
int _slideHeight {0}
SystemWindow * _systemWindow {nullptr}
sk_sp< GrDirectContext > _sk_context {nullptr}
sk_sp< SkSurface > _sk_surface {nullptr}
SkCanvas * _sk_canvas {nullptr}
std::string _title
bool _windowVisible {true}
bool _fullscreen {false}
bool _resizable {true}
bool _decorated {true}
Cursor _cursor {Cursor::Arrow}
InputMode _inputMode {InputMode::Pointer}
bool _focusVisible {false}
ColorScheme _colorScheme {ColorScheme::Unknown}
bool _followSystemTheme {true}
std::optional< Theme > _lightTheme {}
std::optional< Theme > _darkTheme {}
std::weak_ptr< Div > _slopTarget {}
unsigned _buttons {0}
std::chrono::time_point< std::chrono::steady_clock > _lastPress {}
MouseButton _lastPressButton {MouseButton::NONE}
float _lastPressX {0}
float _lastPressY {0}
unsigned _clickCount {0}
GestureTime _lastTap {}
TouchPhase _touchPhase {TouchPhase::None}
MouseButton _touchButton {MouseButton::LEFT}
float _touchStartX {0}
float _touchStartY {0}
float _touchX {0}
float _touchY {0}
GestureTime _touchStart {}
GestureTime _touchTime {}
std::weak_ptr< Div > _panTarget {}
float _panVelocityX {0}
float _panVelocityY {0}
float _panRemainderX {0}
float _panRemainderY {0}
bool _flinging {false}
GestureTime _flingTime {}
bool _surfaceStale {true}
std::vector< Div * > _focusPath {}
std::vector< std::weak_ptr< Div > > _dragAreas {}
double fps {0.0f}
int _windowWidth {0}
int _windowHeight {0}
Protected Attributes inherited from psychic_ui::Div
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 {}

Friends

class Div

Additional Inherited Members

Static Protected Member Functions inherited from psychic_ui::Div
template<class T>
requires std::derived_from<T, Div>
static T * untrackChild (std::vector< std::shared_ptr< T > > &list, const Div &child)
Static Protected Attributes inherited from psychic_ui::Div
static int idCounter = 0

Member Typedef Documentation

◆ GestureTime

using psychic_ui::Window::GestureTime = std::chrono::nanoseconds

When a touch event happened: a monotonic clock's reading (the backend's event timestamps, the system window's gestureTime() for frames). Only differences matter.

Member Function Documentation

◆ addDragArea()

void psychic_ui::Window::addDragArea ( const std::shared_ptr< Div > & div)

Marks a div as a part of the window that moves it when dragged, like a title bar. Pressing on its interactive children (anything with mouse button or click handlers) still reaches them. Held weakly: a div that goes away stops being one.

◆ animating()

bool psychic_ui::Window::animating ( ) const

Whether something moves: a tween, a style transition, kinetic scrolling

◆ animationClock()

std::optional< std::chrono::nanoseconds > psychic_ui::Window::animationClock ( ) const

The time of the frame being made: what updateAnimations was last given, until drawAll ends. nullopt between frames.

◆ animationSpeed()

float psychic_ui::Window::animationSpeed ( ) const
inline

How fast animations play (1, the default): 0.1 plays them ten times slower, to look at them. The animation clock advances by the time between updateAnimations calls times this; the timers (tooltip delays, toast timeouts, a long press) and kinetic scrolling keep the real time.

◆ appContainer()

Div & psychic_ui::Window::appContainer ( ) const
inline

Where the application's content goes, filling the window

◆ clipboardText()

std::string psychic_ui::Window::clipboardText ( ) const

The system clipboard's text, in UTF-8

◆ closeMenu()

void psychic_ui::Window::closeMenu ( )

Close the open menu, with its submenus

◆ colorScheme()

ColorScheme psychic_ui::Window::colorScheme ( ) const
inline

The system's light or dark mode, as its system window last reported it (Unknown before, or when the platform doesn't say)

◆ ctrlClickIsRightClick()

bool psychic_ui::Window::ctrlClickIsRightClick ( ) const
inline

Whether the right button asks for a context menu on its release, as on Windows (the default there), rather than on its press, as on macOS and Linux (the default elsewhere). A touch long press always asks on the press (it is held), the keyboard when its key goes down. Whether a left press with Control (and no other modifier) is a right press, for the whole press and its release (the right button, a context menu, no click), as Cocoa applications do on macOS (the default there; AppKit delivers it as a left press with Control, and SDL leaves it so by default). Not for touches.

◆ flinging()

bool psychic_ui::Window::flinging ( ) const
inline

Whether kinetic scrolling is moving a div

◆ focusables()

void psychic_ui::Window::focusables ( Div * div,
std::vector< Div * > & list )
static

The divs under div (it included) that Tab stops at, in document order: focusEnabled, enabled, visible and displayed, their ancestors up to div too

◆ focusedDiv()

Div * psychic_ui::Window::focusedDiv ( ) const
inline

The deepest div of the focus path, or nullptr

◆ focusNext()

bool psychic_ui::Window::focusNext ( bool backwards = false)

Move the focus to the next div that takes it (focusEnabled, enabled, visible), in document order, or the previous one with backwards; wraps around. Tab and Shift+Tab do it. While a popup that traps the focus is open (a menu, a dialog), only among its divs.

Returns
Whether a div took the focus

◆ focusVisible()

bool psychic_ui::Window::focusVisible ( ) const
inline

Whether the focus moved with the keyboard, so that the focused div shows a focus ring (:focus-visible)

◆ followsSystemTheme()

bool psychic_ui::Window::followsSystemTheme ( ) const
inline

Whether the theme follows the system (until theme(t) picks one)

◆ followSystemTheme()

template<class Self>
Self & psychic_ui::Window::followSystemTheme ( this Self & self)
inline

Follow the system's light or dark mode (what a new window does): the skin set's light theme while the system is light, its default theme (dark) while it is dark or doesn't say; switched live as the system changes (handleColorSchemeChange). With a pair, those two themes instead.

◆ handleColorSchemeChange()

void psychic_ui::Window::handleColorSchemeChange ( ColorScheme scheme)
virtual

Called by the system window when the system goes light or dark (and when it attaches): a window following the system switches themes, then colorSchemeChanged is emitted. The same scheme again does nothing.

◆ handleInputModeChange()

void psychic_ui::Window::handleInputModeChange ( InputMode mode)
virtual

Called by the backends with the device each input event came from: a change restyles the window (:touch) and emits inputModeChanged, the same mode again does nothing

◆ handleMouseButtonChange()

MouseEventStatus psychic_ui::Window::handleMouseButtonChange ( const MouseEvent & event)
overridevirtual

A press first closes the popups it is outside of (Overlay::pressOutside); one that closed a modal popup goes no further, and neither does its release. A press on nothing that takes presses goes to the nearest div whose hitSlop reaches it, as if it landed on its edge, and so does its release while still within that slop

Reimplemented from psychic_ui::Div.

◆ handleMouseMove()

MouseEventStatus psychic_ui::Window::handleMouseMove ( const MouseEvent & event,
bool handled )
overridevirtual

Also follows the div under the mouse with a tooltip, to show it after tooltipDelay

Reimplemented from psychic_ui::Div.

◆ handleMouseScroll()

MouseEventStatus psychic_ui::Window::handleMouseScroll ( const MouseEvent & event)
overridevirtual

Reimplemented from psychic_ui::Div.

◆ handleTouchCancel()

void psychic_ui::Window::handleTouchCancel ( GestureTime time)

The system took the touch away: a press in progress is released without a click, no fling

◆ handleTouchPress()

void psychic_ui::Window::handleTouchPress ( float x,
float y,
GestureTime time )

The primary finger of a direct touch screen, from the backends (window coordinates), which turns the input mode to touch. The window makes mouse events of it: a tap clicks where the finger landed; past touchSlop it pans the scrollable div under the finger when it can scroll along the drag's main axis (with kinetic scrolling after), otherwise it presses where the finger landed and drags; held longPressDelay without moving is a right button press, released when the finger lifts. A finger landing while kinetic scrolling runs only stops it.

◆ hitSlopTarget()

Div * psychic_ui::Window::hitSlopTarget ( float x,
float y,
float & targetX,
float & targetY )

The div a press here goes to through its hitSlop, and the point on it the press moves to; nullptr when the press lands on something that takes presses, or no slop reaches it

◆ inputMode() [1/2]

InputMode psychic_ui::Window::inputMode ( ) const
inline

What the user points with, as last seen: Pointer until a backend reports a finger on a touch screen (Touch, until the next real mouse motion) or a pen (Pen). In touch mode the :touch pseudo-class matches every div of the window.

◆ inputMode() [2/2]

template<class Self>
Self & psychic_ui::Window::inputMode ( this Self & self,
InputMode mode )
inline

Set the input mode, as the backends do: see handleInputModeChange

◆ isDragArea()

bool psychic_ui::Window::isDragArea ( int x,
int y )

Whether a press at this point (window coordinates) should move the window. The system window asks it before the press is dispatched, so that the window manager or compositor moves the window.

◆ loadStyleSheet()

template<typename T>
void psychic_ui::Window::loadStyleSheet ( bool reset = false)
inline

Helper to forward the stylesheet loading to the style manager and refresh our children's runtime styles

Template Parameters
T:StyleSheet

◆ needsFrame()

bool psychic_ui::Window::needsFrame ( ) const

Whether the window has something new to draw: a frame was asked for (requestFrame, the first one, a resize), a task was posted (post), styles or the layout are dirty, or something moves (animating). With nextFrameTime, what a runner needs to sleep while nothing changes; input events are the runner's own business (it draws after them).

◆ nextFrameTime()

std::optional< std::chrono::nanoseconds > psychic_ui::Window::nextFrameTime ( ) const

When the window has something to do next without input, on the system window's gestureTime() clock: a tooltip's delay, a toast's timeout, a long press. nullopt when nothing waits.

◆ open()

void psychic_ui::Window::open ( SystemWindow * systemWindow)

Attaches the window to the system window that shows it, or detaches it with nullptr. Skia is set up on the first frame drawn after, in the system window's GL context.

◆ openContextMenu()

Menu & psychic_ui::Window::openContextMenu ( const MenuItems & items,
float x,
float y,
bool fromKeyboard = false )

Open a context menu at a point (window coordinates), like openMenu there, with the context class. Div::contextMenu(items) calls it when a context menu is asked for on the div; fromKeyboard (the Menu key, Shift+F10) gives the menu the focus with its first item highlighted.

◆ openMenu() [1/3]

Menu & psychic_ui::Window::openMenu ( const MenuItems & items,
Div & anchor,
Side side = Side::Bottom,
PopupAlign align = PopupAlign::Start )

Open a menu beside a div, on a side of it (below by default), lined up with its start

◆ openMenu() [2/3]

Menu & psychic_ui::Window::openMenu ( const MenuItems & items,
int x,
int y )

Open a menu (closing the open one), at a point in window coordinates: below it and to its right, flipped and shifted to stay inside the window

◆ openMenu() [3/3]

Menu & psychic_ui::Window::openMenu ( const std::shared_ptr< Menu > & menu)

Open a menu made by hand (closing the open one)

◆ overlay()

Overlay & psychic_ui::Window::overlay ( ) const
inline

The layer above the content where popups go (menus, select lists, tooltips, dialogs, toasts): see Popup

◆ paint()

void psychic_ui::Window::paint ( SkCanvas * canvas,
float pixelRatio )

Paint the window into a canvas sized in pixels, as drawAll paints its GL surface: cleared, then the tree scaled by the pixel ratio. For drawing elsewhere than the system window (an offscreen raster surface); the styles and layout are the caller's to update first.

◆ panBy()

bool psychic_ui::Window::panBy ( float dx,
float dy )
protected

Scroll the pan target, keeping the fractions for the next move

Returns
Whether it couldn't move at all (at the end of its content)

◆ post()

void psychic_ui::Window::post ( std::function< void()> task)

Hand a task to the UI thread, from any thread: it runs at the start of the next frame (runPosted, first in drawAll), after the tasks posted before it, and asks for that frame (requestFrame). The UI stays single-threaded: another thread changes the window and its divs only through a task. A hidden window (windowVisible() false) runs its tasks once it draws again, so stop or coalesce posts to one. A task must not capture a shared_ptr to the window (the queue would keep it alive: a cycle); capture a weak_ptr, or a raw pointer whose lifetime the caller guarantees. Tasks still queued when the window is destroyed are destroyed without running; the caller must stop posting before that.

◆ reducedMotion() [1/2]

bool psychic_ui::Window::reducedMotion ( ) const
inline

Whether motion is reduced: every duration is 0, values jump to their end (style transitions, Animated, Div::animate). Kinetic scrolling, which follows the finger, stays. Off by default: SDL doesn't say what the system prefers.

◆ reducedMotion() [2/2]

template<class Self>
Self & psychic_ui::Window::reducedMotion ( this Self & self,
detail::BoolArg reduced )
inline

Reduce motion or not; reducing it ends what moves now

◆ releaseStartingClasses()

bool psychic_ui::Window::releaseStartingClasses ( )
protected

Let the divs with their starting class go (they restyle from it)

Returns
Whether there was one

◆ requestContextMenuFromKeyboard()

bool psychic_ui::Window::requestContextMenuFromKeyboard ( )
protected

The Menu key or Shift+F10: a context menu request on the focused div, at its center

◆ requestFocus()

void psychic_ui::Window::requestFocus ( Div * component,
bool visible = false )

Focus a div (and the path to it). visible is whether the focus should show (:focus-visible): true when it moved with the keyboard, false for a press.

◆ requestFrame()

void psychic_ui::Window::requestFrame ( )

Ask for a frame, for a change the window can't see: something a draw reads changing without input, a style or layout change. Wakes the system window's loop (SystemWindow::wake) the first time after a frame. One of the two calls that may come from another thread, with post.

◆ runPosted()

void psychic_ui::Window::runPosted ( )

Run the posted tasks, in posting order; UI thread only. drawAll calls it first; tests call it themselves. A task posted while they run waits for the next call. When a task throws, the rest of its batch goes back to the front of the queue and the exception propagates.

◆ scrollTargetAt()

Div * psychic_ui::Window::scrollTargetAt ( float x,
float y,
bool horizontal )
protected

The deepest div under a point that can scroll along that axis, the way a press would find it

◆ setTextInputArea()

void psychic_ui::Window::setTextInputArea ( int x,
int y,
int width,
int height,
int cursor )

Where text is being typed, for the system window (SystemWindow::setTextInputArea): text fields tell it in touch mode, so that the on-screen keyboard leaves their caret visible

◆ settleExits()

void psychic_ui::Window::settleExits ( )
protected

Finish the exits that are over: styled since they started, nothing of them transitioning

◆ skinSet()

template<class S, class Self>
Self & psychic_ui::Window::skinSet ( this Self & self)
inline

Use a skin set for the style manager: every component hatches a new skin. The theme: a theme picked with theme(t) stays picked, itself if it is one of the set's (SkinSet::themes()), else the set's theme of the same scheme (its light or dark theme); a window following the system keeps following it, with the pair given to followSystemTheme if both are the set's, else the set's own (SkinSet::theme(scheme)).

◆ slideLayout()

void psychic_ui::Window::slideLayout ( )
protected

After a layout: the layout transitions slide what moved, or snap with new rules or a new window size

◆ startAnimation()

void psychic_ui::Window::startAnimation ( const std::shared_ptr< Animation > & animation)

Tick an animation in updateAnimations until it ends; held weakly, so it ends with its owner too

◆ startDrag()

void psychic_ui::Window::startDrag ( )

Moves the window with the mouse until stopDrag(), for a custom title bar. Prefer addDragArea, which also works where applications can't place their windows (Wayland).

◆ supportsDrag()

bool psychic_ui::Window::supportsDrag ( ) const

Whether the window can be moved from inside it (custom title bars). False on Wayland when the system window has no way to hand the move to the compositor: use system decorations there.

◆ systemTheme()

const Theme & psychic_ui::Window::systemTheme ( ) const

The theme following the system picks now

◆ theme() [1/2]

const Theme & psychic_ui::Window::theme ( ) const
inline

The style manager's theme

◆ theme() [2/2]

template<class Self>
Self & psychic_ui::Window::theme ( this Self & self,
const Theme & theme )
inline

Switch the style manager's theme: its stylesheets load again with the new values. The window stops following the system's light or dark mode.

◆ toast()

Toast & psychic_ui::Window::toast ( const ToastOptions & options)

Show a toast in the bottom right corner, over the ones already there (see ToastOptions)

◆ toasts()

ToastStack & psychic_ui::Window::toasts ( )

The toasts' stack, made on the first toast

◆ tooltip()

Tooltip * psychic_ui::Window::tooltip ( ) const
inline

The tooltip showing now, or nullptr

◆ tooltipTargetAt()

Div * psychic_ui::Window::tooltipTargetAt ( float x,
float y )

The deepest div with a tooltip under a point (window coordinates), as a press would find it

◆ touchEvent()

MouseEvent psychic_ui::Window::touchEvent ( float x,
float y,
MouseButton button = MouseButton::NONE,
bool down = false ) const
protected

The window's touch gestures as mouse events, from a finger at x, y

◆ untilNextFrame()

std::optional< std::chrono::nanoseconds > psychic_ui::Window::untilNextFrame ( std::chrono::nanoseconds now) const

How long a runner may wait for input before drawing again, at now (gestureTime()): zero when the window needs a frame, nullopt when nothing but input can change it

◆ updateAnimations()

void psychic_ui::Window::updateAnimations ( std::chrono::nanoseconds now)

Advance what moves with time: tweens (Animated, Div::animate) and style transitions. drawAll calls it every frame with the system window's gestureTime(), after updateGestures and updatePopups and before the styles and the layout; tests call it with their own times. A tween started after it, until the frame ends, starts at its time (animationClock); one started between frames starts with the next one.

◆ updateGestures()

void psychic_ui::Window::updateGestures ( GestureTime now)

Advance what goes on without events: a long press fires, kinetic scrolling moves and slows down. drawAll calls it every frame with the system window's gestureTime(); tests call it with theirs.

◆ updatePopups()

void psychic_ui::Window::updatePopups ( std::chrono::nanoseconds now)

Advance the popups with time: a tooltip's delay, the toasts' timers. drawAll calls it every frame with the system window's gestureTime(); tests call it with theirs.

◆ updateStylesAndLayout()

void psychic_ui::Window::updateStylesAndLayout ( )

The frame's work before painting, in order: compute the dirty styles (visible or not), then lay out the tree if needed. Called by drawAll, needs no canvas.

◆ window() [1/2]

const Window * psychic_ui::Window::window ( ) const
overridevirtual

Reimplemented from psychic_ui::Div.

◆ window() [2/2]

Window * psychic_ui::Window::window ( )
overridevirtual

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

Returns
Pointer to owning window, if any

Reimplemented from psychic_ui::Div.

◆ windowVisible()

bool psychic_ui::Window::windowVisible ( ) const

Whether the system window is shown. Not the visible style: the window's own visibility, which close() turns off and the application follows.

Member Data Documentation

◆ _cursor

Cursor psychic_ui::Window::_cursor {Cursor::Arrow}
protected

Cursor to use when this component has the mouse focus

◆ _slopTarget

std::weak_ptr<Div> psychic_ui::Window::_slopTarget {}
protected

The div the last press went to through its hit slop, for its release

◆ _surfaceStale

bool psychic_ui::Window::_surfaceStale {true}
protected

The Skia surface no longer matches the framebuffer (it was resized): the next frame makes a new one

◆ _windowWidth

int psychic_ui::Window::_windowWidth {0}
protected

Window size, read through windowWidth()/windowHeight() (the system window's once opened): the size the root is laid out at

◆ flingMinVelocity

float psychic_ui::Window::flingMinVelocity = 50.0f
staticconstexpr

Kinetic scrolling: the speed (window units per second) a pan must have when the finger lifts to keep scrolling, the share of its speed it keeps every millisecond, and the speed where it stops

◆ flingRestDelay

GestureTime psychic_ui::Window::flingRestDelay = std::chrono::milliseconds(100)
staticconstexpr

A pan that rests this long before the finger lifts doesn't fling

◆ inputModeChanged

Signal<InputMode> psychic_ui::Window::inputModeChanged {}

Emitted with the new mode when the input mode changes

◆ longPressDelay

GestureTime psychic_ui::Window::longPressDelay = std::chrono::milliseconds(500)
staticconstexpr

How long a finger stays down, within the slop, to raise a context press (a right button press)

◆ maxStylePasses

int psychic_ui::Window::maxStylePasses = 4
staticconstexpr

How many style passes a frame may run when styleUpdated callbacks keep invalidating styles

◆ multiClickDelay

std::chrono::milliseconds psychic_ui::Window::multiClickDelay {500}
staticconstexpr

Presses of the same button in a row count as one more click when this close in time and space

◆ tooltipDelay

std::chrono::nanoseconds psychic_ui::Window::tooltipDelay = std::chrono::milliseconds(300)
staticconstexpr

How long the mouse rests on a div with a tooltip before it shows, and how soon after one hides the next one shows at once (Pivotal's)

◆ touchSlop

float psychic_ui::Window::touchSlop = 8.0f
staticconstexpr

How far a finger moves (window units) before a press becomes a drag or a pan


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