Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height > Class Template Reference

A template class that allows you to move and resize a widget. More...

#include <widget.h>

Inheritance diagram for MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >:
MaxOS::drivers::peripherals::MouseEventHandler MaxOS::common::EventHandler< MouseEvents >

Public Member Functions

 WidgetMoverResizer (Widget *widget)
 
void on_mouse_move_event (int8_t x, int8_t y) override
 
- Public Member Functions inherited from MaxOS::drivers::peripherals::MouseEventHandler
common::Event< MouseEvents > * on_event (common::Event< MouseEvents > *) override
 Handles the triggered event and calls the appropriate function.
 
virtual void on_mouse_down_event (uint8_t button)
 Called when the mouse is pressed.
 
virtual void on_mouse_up_event (uint8_t button)
 Called when the mouse is released.
 
- Public Member Functions inherited from MaxOS::common::EventHandler< MouseEvents >
virtual Event< MouseEvents > * on_event (Event< MouseEvents > *event)
 This function is called when an event is raised.
 

Detailed Description

template<int Left, int Top, int Width, int Height>
class MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >

A template class that allows you to move and resize a widget.

Template Parameters
LeftLeft
TopTop
WidthWidth
HeightHeight

Definition at line 127 of file widget.h.

Constructor & Destructor Documentation

◆ WidgetMoverResizer()

template<int Left, int Top, int Width, int Height>
MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >::WidgetMoverResizer ( Widget target)

WidgetMoverResizer is a template class that allows you to move and resize a widget

Template Parameters
LeftThe left edge of the widget
TopThe top edge of the widget
WidthThe m_width of the widget
HeightThe m_height of the widget
Parameters
targetThe widget to move and resize

Definition at line 161 of file widget.h.

162 : drivers::peripherals::MouseEventHandler() {
163 this->targeted_widget = target;
164 }

Member Function Documentation

◆ on_mouse_move_event()

template<int Left, int Top, int Width, int Height>
void MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >::on_mouse_move_event ( int8_t  x,
int8_t  y 
)
overridevirtual

OnMouseMoved is called when the mouse is moved. Resizes and moves the widget when this happens.

Parameters
xThe x m_position of the mouse
yThe y m_position of the mouse

Reimplemented from MaxOS::drivers::peripherals::MouseEventHandler.

Definition at line 174 of file widget.h.

174 {
175
176 Widget* targ = this->targeted_widget;
177
178 // If there is actually a size of the widget to change
179 if(Left != 0 || Top != 0)
180 // Move the widget to the left or right, and up or down
181 targ->move(targ->m_position.left + Left * x, targ->m_position.top + Top * y);
182
183 // If there is actually a size of the widget to change
184 if(Width != 0 || Height != 0)
185 // Resize the widget to the left or right, and up or down
186 targ->resize(targ->m_position.width + Width * x, targ->m_position.height + Height * y);
187 }
void move(int32_t left, int32_t top)
Set the position of the widget, and invalidate the old and new positions so they are redrawn.
Definition widget.cpp:138

References MaxOS::common::Rectangle< Type >::height, MaxOS::common::Rectangle< Type >::left, MaxOS::gui::Widget::m_position, MaxOS::gui::Widget::move(), MaxOS::gui::Widget::resize(), MaxOS::common::Rectangle< Type >::top, and MaxOS::common::Rectangle< Type >::width.


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