Lysa UI  0.0
Lysa UI —UI components for the Lysa Engine
ColorPicker Class Reference

Detailed Description

A widget selecting a color with one slider per component & a preview of the result.

+ Inheritance diagram for ColorPicker:

Public Typedefs

using Transform = std::function< float4 (const float4 &)>
 

Public Types

enum  Component { RED, GREEN, BLUE, ALPHA }
 
enum  Mode { RGB, HSV, LINEAR }
 
- Public Types inherited from Widget
enum  Type {
  WIDGET, PANEL, BOX, LINE,
  FRAME, BUTTON, TOGGLEBUTTON, RADIOBUTTON,
  CHECKBOX, CHECKMARK, CROSSMARK, ARROW,
  TEXT, TEXTEDIT, RICHTEXTAREA, SCROLLBAR,
  SLIDER, COLORSLIDER, COLORWHEEL, KNOB,
  TREEVIEW, IMAGE, POPUP, LIST,
  LISTBOX, SELECTION, PROGRESSBAR, SCROLLCONTAINER,
  MENU, MENUPANEL, MENUBOX, TABBAR,
  TABCONTAINER, DIALOG, FOLDABLECONTAINER, COLORPICKER,
  COLORPICKERBUTTON, SPINBOX, SPINBUTTONS, ICONIMAGE,
  ICONSVG, DROPDOWNLIST, TOOLTIP, GRIDCELL,
  GRID, TABLE
}
 

Public Member Functions

 ColorPicker (const float4 &color={0.0f, 0.0f, 0.0f, 1.0f})
 
const auto & getColor () const
 
void setColor (const float4 &color)
 
auto getMode () const
 
void setMode (Mode mode)
 
void setModeLabels (const std::array< std::string, MODES > &labels)
 
auto getTabBar () const
 
void setTabHeight (float height)
 
auto getTabHeight () const
 
auto getFooter () const
 
void setFooterHeight (float height)
 
auto getFooterHeight () const
 
void setPreviewTransform (const Transform &transform)
 
void setPreviewHeight (float height)
 
auto getPreviewHeight () const
 
void setWheelHeight (float height)
 
auto getWheelHeight () const
 
void setBrightnessWidth (float width)
 
auto getBrightnessWidth () const
 
void setRowHeight (float height)
 
auto getRowHeight () const
 
void setLabelWidth (float width)
 
auto getLabelWidth () const
 
void setValueWidth (float width)
 
auto getValueWidth () const
 
float getAutoHeight () const
 
auto getPreview () const
 
auto getWheel () const
 
auto getBrightnessSlider () const
 
auto getSlider (const Component component) const
 
auto getLabel (const Component component) const
 
auto getValue (const Component component) const
 
void setResources (const std::string &resPreview)
 
- Public Member Functions inherited from Widget
 Widget (Type type=WIDGET)
 
 ~Widget () override
 
Type getType () const
 
bool isVisible () const
 
void setVisible (bool show=true)
 
bool isEnabled () const
 
void setEnabled (bool isEnabled=true)
 
virtual void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
float getRequestedWidth () const
 
float getRequestedHeight () const
 
virtual void setSize (float width, float height)
 
void setWidth (const float width)
 
void setHeight (const float height)
 
const Rect & getRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
float getAspectRatio () const
 
Alignment getAlignment () const
 
void setAlignment (Alignment alignment)
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
virtual void setFontScale (float fontScale)
 
bool isFocused () const
 
Widget * getParent () const
 
void setOverlap (const bool overlap)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const Alignment alignment, Args &&...args)
 
template<typename T >
std::shared_ptr< T > add (std::shared_ptr< T > child, const Alignment alignment=Alignment::NONE, const std::string &resource="", const bool overlap=false)
 
template<typename T >
std::shared_ptr< T > addPopup (std::shared_ptr< T > child, const std::string &resource="")
 
template<typename T >
std::shared_ptr< T > addAfter (std::shared_ptr< T > child, const std::shared_ptr< Widget > &after, const Alignment alignment, const std::string &resource="", const bool overlap=false)
 
virtual void remove (const std::shared_ptr< Widget > &child)
 
virtual void removeAll ()
 
void setPadding (float padding)
 
float getPadding () const
 
float getVBorder () const
 
float getHBorder () const
 
void setVBorder (float size)
 
void setHBorder (float size)
 
bool isDrawBackground () const
 
void setDrawBackground (bool drawBackground)
 
bool isPushed () const
 
bool isPointed () const
 
bool isFreezed () const
 
bool isRedrawOnMouseEvent () const
 
bool isOverlapping () const
 
Rect getChildrenRect () const
 
void setFreezed (const bool f)
 
void setPushed (const bool p)
 
void refresh ()
 
void setResource (std::shared_ptr< UIResource > res)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
template<typename T >
getUserData () const
 
template<typename T >
std::shared_ptr< T > getPointerUserData () const
 
const std::any & getUserData () const
 
void setUserData (const std::any &data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
float getChildrenOffsetX () const
 
float getChildrenOffsetY () const
 
void setChildrenOffset (float x, float y)
 
std::shared_ptr< Widget > setFocus (bool focus=true)
 
virtual void onAttach ()
 
virtual void onDetach ()
 
virtual void onShow ()
 
virtual void onHide ()
 
virtual void onResize ()
 
virtual void onMove ()
 
virtual bool onKeyDown (Key key)
 
virtual bool onTextInput (const std::string &text)
 
virtual bool onKeyUp (Key key)
 
virtual bool onMouseDown (MouseButton button, float x, float y)
 
virtual bool onMouseUp (MouseButton button, float x, float y)
 
virtual bool onMouseMove (uint32 buttonsState, float x, float y)
 
virtual void onMouseLeave ()
 
virtual void onDisable ()
 
virtual void onEnable ()
 
virtual void onGotFocus ()
 
virtual void onLostFocus ()
 
bool getConsumeMouseEvent () const
 
void setConsumeMouseEvent (const bool consumeMouseEvent)
 
const std::list< std::shared_ptr< Widget > > & getChildren () const
 
bool hasChildren () const
 
void subscribe (const event_type &type, unique_id id, EventHandlerCallback callback)
 
void subscribe (const event_type &type, EventHandlerCallback callback)
 
void unsubscribe (unique_id id)
 
bool isAttached () const
 
WindowgetWindow () const
 
StylegetStyle () const
 
Vector2DRenderer & getRenderer () const
 
RenderingWindow & getRenderingWindow () const
 
WindowManagergetWindowManager () const
 

Static Public Member Functions

static float componentOf (const float4 &color, uint32 index)
 
static float toLinear (float value)
 
static float fromLinear (float value)
 

Static Public Attributes

static constexpr uint32 COMPONENTS {4}
 Number of components of a color. More...
 
static constexpr uint32 MODES {3}
 Number of spaces the components can be edited in. More...
 
static constexpr float MAX_HUE {359.0f}
 Largest value of a hue, in degrees. More...
 
static constexpr uint32 HUE_STOPS {6}
 Number of stops of the ramp of the hue, one per primary & secondary color. More...
 
static constexpr float MAX_VALUE {255.0f}
 Largest value of a component : the sliders select integral values in [0, MAX_VALUE]. More...
 
static constexpr float DEFAULT_PREVIEW_HEIGHT {32.0f}
 Default height of the preview of the color. More...
 
static constexpr float DEFAULT_WHEEL_HEIGHT {150.0f}
 Default height of the wheel selecting the hue & the saturation. More...
 
static constexpr float DEFAULT_BRIGHTNESS_WIDTH {16.0f}
 Default width of the slider selecting the brightness, in square units. More...
 
static constexpr float DEFAULT_ROW_HEIGHT {28.0f}
 Default height of the row displaying the slider & the spin box of one component. More...
 
static constexpr float DEFAULT_LABEL_WIDTH {16.0f}
 Default width of the name of a component, in square units. More...
 
static constexpr float DEFAULT_VALUE_WIDTH {60.0f}
 Default width of the value of a component, in square units, buttons included. More...
 
static constexpr float DEFAULT_TAB_HEIGHT {24.0f}
 Default height of the bar of tabs selecting the mode. More...
 
static const std::array< std::array< std::string, COMPONENTS >, MODES > LABELS
 Names of the components, displayed at the left of the sliders, by mode. More...
 
static const std::array< std::string, MODES > MODE_LABELS {"RGB", "HSV", "Linear"}
 Default labels of the tabs, in the order of Mode. More...
 

Additional Inherited Members

- Protected Attributes inherited from Widget
const Type type
 
Rect rect
 
float requestedWidth {0}
 
float requestedHeight {0}
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
bool consumeMouseEvent {false}
 
bool overlap {false}
 
bool focused {false}
 
bool allowFocus {false}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool scrollChildren {false}
 
bool skipInvisibleChildren {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
std::shared_ptr< UIResourceresource
 
std::list< std::shared_ptr< Widget > > children
 
bool mouseMoveOnFocus {false}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Member Typedef Documentation

using Transform = std::function<float4(const float4&)>

Converts the selected color into the color the preview is drawn with, used when the colors of the UI are not in the same space as the selected color.

Member Enumeration Documentation

enum Component

Components of the color

Enum ValuesDocumentation
RED 
GREEN 
BLUE 
ALPHA 
enum Mode

Space the components of the color are edited in

Enum ValuesDocumentation
RGB 
HSV 

Red, green & blue as they are stored.

LINEAR 

Hue in degrees, saturation & brightness.

Constructor & Destructor Documentation

ColorPicker ( const float4 &  color = {0.0f, 0.0f, 0.0f, 1.0f})

Creates a color selector.

Member Function Documentation

static float componentOf ( const float4 &  color,
uint32  index 
)
static

Returns the value of one component of a color, in [0.0, 1.0].

static float fromLinear ( float  value)
static

Converts a component from the linear space to the sRGB one

float getAutoHeight ( ) const

Returns the height needed to display the preview & all the sliders.

auto getBrightnessSlider ( ) const
inline

Returns the slider selecting the brightness, at the right of the wheel

auto getBrightnessWidth ( ) const
inline

Returns the width of the slider selecting the brightness, in square units

const auto& getColor ( ) const
inline

Returns the selected color

auto getFooter ( ) const
inline

Returns the widget displayed at the bottom of the picker, left empty for the application to fill it

auto getFooterHeight ( ) const
inline

Returns the height of the widget displayed at the bottom of the picker

auto getLabel ( const Component  component) const
inline

Returns the text widget displaying the name of a component

auto getLabelWidth ( ) const
inline

Returns the width of the column displaying the names of the components.

auto getMode ( ) const
inline

Returns the space the components are edited in

auto getPreview ( ) const
inline

Returns the widget displaying the selected color.

auto getPreviewHeight ( ) const
inline

Returns the height of the preview of the color.

auto getRowHeight ( ) const
inline

Returns the height of the row displaying the slider of one component.

auto getSlider ( const Component  component) const
inline

Returns the slider of a component

auto getTabBar ( ) const
inline

Returns the bar of tabs selecting the mode

auto getTabHeight ( ) const
inline

Returns the height of the bar of tabs selecting the mode

auto getValue ( const Component  component) const
inline

Returns the spin box displaying the value of a component

auto getValueWidth ( ) const
inline

Returns the width of the column displaying the values of the components.

auto getWheel ( ) const
inline

Returns the wheel selecting the hue & the saturation

auto getWheelHeight ( ) const
inline

Returns the height of the wheel selecting the hue & the saturation

void setBrightnessWidth ( float  width)

Sets the width of the slider selecting the brightness, in square units

void setColor ( const float4 &  color)

Changes the selected color

void setFooterHeight ( float  height)

Sets the height of the widget displayed at the bottom of the picker

void setLabelWidth ( float  width)

Sets the width of the column displaying the names of the components.

void setMode ( Mode  mode)

Changes the space the components are edited in

void setModeLabels ( const std::array< std::string, MODES > &  labels)

Changes the labels of the tabs selecting the mode, in the order of Mode

void setPreviewHeight ( float  height)

Sets the height of the preview of the color.

void setPreviewTransform ( const Transform transform)

Sets the conversion applied to the selected color before drawing the preview.

void setResources ( const std::string &  resPreview)

Sets the UI resources of the widgets created by the selector.

Parameters
resPreviewResource for the box displaying the selected color.
void setRowHeight ( float  height)

Sets the height of the row displaying the slider of one component.

void setTabHeight ( float  height)

Sets the height of the bar of tabs selecting the mode

void setValueWidth ( float  width)

Sets the width of the column displaying the values of the components.

void setWheelHeight ( float  height)

Sets the height of the wheel selecting the hue & the saturation

static float toLinear ( float  value)
static

Converts a component from the sRGB space to the linear one

Member Data Documentation

constexpr uint32 COMPONENTS {4}
staticconstexpr

Number of components of a color.

constexpr float DEFAULT_BRIGHTNESS_WIDTH {16.0f}
staticconstexpr

Default width of the slider selecting the brightness, in square units.

constexpr float DEFAULT_LABEL_WIDTH {16.0f}
staticconstexpr

Default width of the name of a component, in square units.

constexpr float DEFAULT_PREVIEW_HEIGHT {32.0f}
staticconstexpr

Default height of the preview of the color.

constexpr float DEFAULT_ROW_HEIGHT {28.0f}
staticconstexpr

Default height of the row displaying the slider & the spin box of one component.

constexpr float DEFAULT_TAB_HEIGHT {24.0f}
staticconstexpr

Default height of the bar of tabs selecting the mode.

constexpr float DEFAULT_VALUE_WIDTH {60.0f}
staticconstexpr

Default width of the value of a component, in square units, buttons included.

constexpr float DEFAULT_WHEEL_HEIGHT {150.0f}
staticconstexpr

Default height of the wheel selecting the hue & the saturation.

constexpr uint32 HUE_STOPS {6}
staticconstexpr

Number of stops of the ramp of the hue, one per primary & secondary color.

const std::array<std::array<std::string, COMPONENTS>, MODES> LABELS
inlinestatic
Initial value:
{{
{"R", "G", "B", "A"},
{"H", "S", "V", "A"},
{"R", "G", "B", "A"},
}}

Names of the components, displayed at the left of the sliders, by mode.

constexpr float MAX_HUE {359.0f}
staticconstexpr

Largest value of a hue, in degrees.

constexpr float MAX_VALUE {255.0f}
staticconstexpr

Largest value of a component : the sliders select integral values in [0, MAX_VALUE].

const std::array<std::string, MODES> MODE_LABELS {"RGB", "HSV", "Linear"}
inlinestatic

Default labels of the tabs, in the order of Mode.

constexpr uint32 MODES {3}
staticconstexpr

Number of spaces the components can be edited in.