cwidget  0.5.17
Public Member Functions | List of all members
cwidget::style Class Reference

A "style" is a setting to be applied to a display element (widget, text, etc). More...

#include <style.h>

Public Member Functions

 style ()
 Initialize an "empty" style. More...
 
void set_fg (short _fg)
 Set the foreground color. More...
 
void set_bg (short _bg)
 Set the background color. More...
 
void attrs_on (attr_t attrs)
 Set the given attribute(s). More...
 
void attrs_off (attr_t attrs)
 Clear the given attribute(s). More...
 
void attrs_flip (attr_t attrs)
 Flip the given attribute(s). More...
 
void apply_style (const style &other)
 Update this style by applying the settings in the other style.
 
style operator+ (const style &other) const
 
styleoperator+= (const style &other)
 Shorthand for apply_style. More...
 
bool operator== (const style &other) const
 
bool operator!= (const style &other) const
 
short get_fg () const
 
short get_bg () const
 
attr_t get_attrs () const
 
chtype apply_to (chtype ch) const
 
wchtype apply_to (wchtype ch) const
 

Detailed Description

A "style" is a setting to be applied to a display element (widget, text, etc).

This means color (foreground and background) and attributes. A style may contain settings for any or all of these; settings which are unspecified are taken from the context in which the display element occurs. For instance, the "button highlighted" style might simply toggle the REVERSE flag.

The interface of styles is high-level: each style is viewed as a function that applies to the current text attributes; you can also extract the style's "current" state in order to merge it with a cchar (this is the style applied to the "null" or default style). However, as there are only a relatively limited number of things each style can change, the representation doesn't rely on virtual functions or even on keeping an array of operations to be applied; instead, it just keeps a summary of the operations it represents.

Constructor & Destructor Documentation

◆ style()

cwidget::style::style ( )
inline

Initialize an "empty" style.

Member Function Documentation

◆ apply_to() [1/2]

chtype cwidget::style::apply_to ( chtype  ch) const
inline
Returns
the given character with its attributes updated with ours.

References cwidget::config::mix_color().

Referenced by cwidget::chstring::apply_style(), and cwidget::wchstring::apply_style().

◆ apply_to() [2/2]

wchtype cwidget::style::apply_to ( wchtype  ch) const
inline
Returns
the given character with its attributes updated with ours.

References cwidget::wchtype::attrs, cwidget::wchtype::ch, and cwidget::config::mix_color().

◆ attrs_flip()

void cwidget::style::attrs_flip ( attr_t  attrs)
inline

Flip the given attribute(s).

Referenced by apply_style(), cwidget::fragf(), and cwidget::style_attrs_flip().

◆ attrs_off()

void cwidget::style::attrs_off ( attr_t  attrs)
inline

Clear the given attribute(s).

Referenced by apply_style(), and cwidget::style_attrs_off().

◆ attrs_on()

void cwidget::style::attrs_on ( attr_t  attrs)
inline

Set the given attribute(s).

Referenced by apply_style(), and cwidget::style_attrs_on().

◆ get_attrs()

attr_t cwidget::style::get_attrs ( ) const
inline

◆ get_bg()

short cwidget::style::get_bg ( ) const
inline
Returns
the background color.

◆ get_fg()

short cwidget::style::get_fg ( ) const
inline
Returns
the foreground color.

◆ operator+()

style cwidget::style::operator+ ( const style other) const
inline
Returns
a new style formed by composing this style with other. Note that this is a noncommutative operator!

◆ operator+=()

style& cwidget::style::operator+= ( const style other)
inline

Shorthand for apply_style.

References apply_style().

◆ set_bg()

void cwidget::style::set_bg ( short  _bg)
inline

Set the background color.

There is no change if the new background color is "empty".

Referenced by apply_style(), and cwidget::style_bg().

◆ set_fg()

void cwidget::style::set_fg ( short  _fg)
inline

Set the foreground color.

There is no change if the new foreground color is "empty".

Referenced by apply_style(), and cwidget::style_fg().


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