SavvyUI C++ UI Library
Loading...
Searching...
No Matches
Button Class Reference

A clickable UI component representing a button with customizable text and type. More...

#include <Button.h>

Inheritance diagram for Button:
Component

Public Member Functions

 Button ()
 Constructs a Button object.
virtual ~Button ()
 Destructs the Button object and cleans up resources.
void setText (const wstring &text)
 Sets the text displayed on the button.
void setHasShadow (BOOL hasShadow)
void setImage (const IconSource &iconSource, const Direction &imagePosition=Direction::LEFT)
 Sets the image file displayed on the button and the image position.
void setButtonType (const ButtonType &buttonType, COLORREF bkColor=Theme::ButtonBackgroundStartColor, COLORREF fgColor=Theme::ButtonForegroundColor)
 Sets the button type/style.
void setLinkStyle ()
void onPaint (Graphics *g)
 Handles the painting of the button.
void onMousePressed (WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed)
 Handles mouse press events on the button.
void onMouseReleased (WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
 Handles mouse release events on the button.
void onMouseMoved (WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
 Handles mouse move events over the button.
void addActionListener (ActionListener *l)
 Adds an action listener to the button to handle action events.
Public Member Functions inherited from Component
 Component ()
 Constructs a new Component instance.
virtual ~Component ()
 Virtual destructor.
long getId ()
 Gets the unique ID assigned to this component.
void setParent (Component *parent)
ComponentgetParent ()
wstring getComponentType ()
 Gets the component type string.
BOOL isWindowCreated ()
 Returns whether the native window has been created.
WinHandle getWindowHandle ()
 Returns the native WinHandle for this component.
int createComponent (WinHandle hParent, Bounds rect, long nCmd=-1, BOOL isVisible=TRUE)
 Creates the component's native window as a child of hParent.
void setFont (long fontSize, BOOL isBold=FALSE, BOOL isItalic=FALSE, BOOL isUnderlined=FALSE, const wstring &fontName=L"Arial")
 Sets the font for the component.
void showBorder (BOOL bShow=TRUE)
void setEnabled (BOOL bEnable=TRUE)
 Enables or disables the component.
void setVisible (BOOL bShow=TRUE)
 Shows or hides the component.
void GetClientRect (Bounds &rect)
void GetWindowRect (Bounds &rect)
void moveWindow (long x, long y, long width, long height, BOOL bRedraw=TRUE)
 Moves and resizes the component window.
void reconfigureScrollBar ()
 Forces the component to recalculate the scrollbar info.
void setMouseWheelDelta (int delta)
 Sets the accumulated mouse wheel delta.
int getMouseWheelDelta ()
 Gets the current mouse wheel delta.
virtual int getMinimumHeight ()
 Returns the minimum height the component can have.
virtual int getPreferredHeight ()
 Returns the preferred height of the component.
void repaint (WinHandle hWnd=NULL)
 Requests the component to repaint itself.
void clearQueuedPaintRequest ()
 clears the queued paint request. This function should only be called internally from the library.
virtual void onWindowResized ()
 Called when the component's window is resized.
virtual void onWindowMoved ()
 Called when the component's window is moved.
virtual void onAction (WinHandle hTarget, long actionId, const ProcParams &procParams)
 Called when an action occurs on the component.
virtual void onSelectionChanged (WinHandle hTarget, int itemIndex, const wstring &itemText, BOOL itemChecked, const ProcParams &procParams)
 Called when the selection changes.
virtual void onDataChanged (WinHandle hTarget, const wstring &newValue, const ProcParams &procParams)
 Called when data changes in the component.
virtual BOOL onHorzScroll (WinHandle hTarget, const ProcParams &procParams)
 Called on horizontal scroll events.
virtual BOOL onDrawMeasureItem (LPMEASUREITEMSTRUCT dis, const ProcParams &procParams)
 Called when measuring an item for owner-draw controls.
virtual BOOL onDrawItem (LPDRAWITEMSTRUCT dis, const ProcParams &procParams)
 Called when drawing an item for owner-draw controls.
virtual void onMouseRightClicked (WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
 Called when the right mouse button is clicked within the component.
virtual BOOL onMouseWheel (WinHandle hWnd, int x, int y, int delta)
 Called when the mouse wheel is used over the component.
virtual void onArrowLeft (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onArrowRight (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onArrowUp (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onArrowDown (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onPageUp (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onPageDown (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyHome (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyEnd (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyInsert (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyDelete (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyBackSpace (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyTyped (wchar_t ch, BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyTab (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyEnter (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF1 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF2 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF3 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF4 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF5 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF6 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF7 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF8 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF9 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF10 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF11 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF12 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onFocusGained ()
 Called when the component gains keyboard focus.
virtual void onFocusLost ()
 Called when the component loses keyboard focus.
virtual void onTimer (unsigned int timerId)
 Called on timer events.
virtual BOOL getScrollingInfo (__int64 &scrollMin, __int64 &scrollMax, __int64 &pageSize)
 Provides scrolling information if supported.
virtual void setScrollbarTopOffset (__int64 firstVisibleRow)
 Sets the scrollbar's top offset.
void updateScrollbarTopOffset (__int64 firstVisibleRow)
 Updates the scrollbar's top offset based on the current first visible row.

Protected Member Functions

BOOL getCreateWindowOptions (wstring &title, UINT &widownStyles, wstring &wndClassName, BOOL &isCustomWndProc)
 Prepares window creation options such as title, styles, and class name.
void windowCreated ()
 Called after the window has been created to perform any initialization.
Protected Member Functions inherited from Component
long getActionId ()
 Returns the component's action command ID.
void doNotSubclass ()
 Marks this component's native window to avoid subclassing.
void startTimer (unsigned int timerId, unsigned int milliseconds)
 Starts a timer with the given ID and interval.
void stopTimer (unsigned int timerId)
 Stops the timer identified by timerId.
void protectedAddDataChangedListener (DataChangeListener *l)
 Adds a data change listener.
void protectedAddSelectionChangedListener (SelectionChangeListener *l)
 Adds a selection change listener.
void protectedAddActionListener (ActionListener *l)
 Adds an action listener.
void protectedAddItemDoubleClickedListener (RowDoubleClickListener *l)
 Adds a row double-click listener.
void protectedFireDataChangedEvent (const wstring &oldValue, const wstring &newValue)
 Fires a data changed event to registered listeners.
void protectedFireSelectionChangedEvent (long selectionIndex=-1, const wstring &selectionValue=L"", BOOL checked=FALSE)
 Fires a selection changed event to registered listeners.
void protectedFireActionEvent (long actionId=-1, const wstring &actionName=L"")
 Fires an action event to registered listeners.
void protectedFireItemDoubleClickedEvent (__int64 rowIndex)
 Fires a row double-click event to registered listeners.

Additional Inherited Members

Protected Attributes inherited from Component
WinHandle _hWnd
 Handle to the native window associated with this component.
wstring _componentType
 String representing the component type (e.g., "Button", "ComboBox").
BOOL _showBorder

Detailed Description

A clickable UI component representing a button with customizable text and type.

The Button class extends Component and supports mouse interactions, allowing for text display and different button styles (e.g., primary, default, danger, success).

Constructor & Destructor Documentation

◆ Button()

Button::Button ( )

Constructs a Button object.

◆ ~Button()

virtual Button::~Button ( )
virtual

Destructs the Button object and cleans up resources.

Member Function Documentation

◆ addActionListener()

void Button::addActionListener ( ActionListener * l)

Adds an action listener to the button to handle action events.

Parameters
lPointer to the ActionListener object to add.

◆ getCreateWindowOptions()

BOOL Button::getCreateWindowOptions ( wstring & title,
UINT & widownStyles,
wstring & wndClassName,
BOOL & isCustomWndProc )
protectedvirtual

Prepares window creation options such as title, styles, and class name.

Parameters
titleThe window title to set.
widownStylesWindow style flags.
wndClassNameThe window class name.
isCustomWndProcIndicates if a custom window procedure is used.
Returns
TRUE if the options were set successfully, FALSE otherwise.

Implements Component.

◆ onMouseMoved()

void Button::onMouseMoved ( WinHandle hWnd,
int x,
int y,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Handles mouse move events over the button.

Parameters
hWndHandle to the window receiving the event.
xThe x-coordinate of the mouse pointer.
yThe y-coordinate of the mouse pointer.
shiftPressedTRUE if the Shift key is pressed.
ctrlPressedTRUE if the Ctrl key is pressed.

Reimplemented from Component.

◆ onMousePressed()

void Button::onMousePressed ( WinHandle hWnd,
int x,
int y,
int clickCount,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Handles mouse press events on the button.

Parameters
hWndHandle to the window receiving the event.
xThe x-coordinate of the mouse pointer.
yThe y-coordinate of the mouse pointer.
clickCountNumber of clicks detected.
shiftPressedTRUE if the Shift key is pressed.
ctrlPressedTRUE if the Ctrl key is pressed.

Reimplemented from Component.

◆ onMouseReleased()

void Button::onMouseReleased ( WinHandle hWnd,
int x,
int y,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Handles mouse release events on the button.

Parameters
hWndHandle to the window receiving the event.
xThe x-coordinate of the mouse pointer.
yThe y-coordinate of the mouse pointer.
shiftPressedTRUE if the Shift key is pressed.
ctrlPressedTRUE if the Ctrl key is pressed.

Reimplemented from Component.

◆ onPaint()

void Button::onPaint ( Graphics * g)
virtual

Handles the painting of the button.

Parameters
hDCHandle to the device context to paint on.

Reimplemented from Component.

◆ setButtonType()

void Button::setButtonType ( const ButtonType & buttonType,
COLORREF bkColor = Theme::ButtonBackgroundStartColor,
COLORREF fgColor = Theme::ButtonForegroundColor )

Sets the button type/style.

Parameters
buttonTypeThe type of button (e.g., ButtonType::PRIMARY).

◆ setHasShadow()

void Button::setHasShadow ( BOOL hasShadow)

◆ setImage()

void Button::setImage ( const IconSource & iconSource,
const Direction & imagePosition = Direction::LEFT )

Sets the image file displayed on the button and the image position.

Parameters
imageFileThe file containing the image displayed on the button.
imagePositionThe position of the image displayed on the button (e.g. left|top|right|bottom).

◆ setLinkStyle()

void Button::setLinkStyle ( )

◆ setText()

void Button::setText ( const wstring & text)

Sets the text displayed on the button.

Parameters
textThe new text for the button.

◆ windowCreated()

void Button::windowCreated ( )
protectedvirtual

Called after the window has been created to perform any initialization.

Implements Component.


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