mousetrap v0.2.0
Loading...
Searching...
No Matches
mousetrap::Widget Class Reference

Widget, super class of all renderable entities. More...

#include <widget.hpp>

Inheritance diagram for mousetrap::Widget:
mousetrap::SignalEmitter mousetrap::ActionBar mousetrap::AspectFrame mousetrap::Box mousetrap::Button mousetrap::CenterBox mousetrap::CheckButton mousetrap::ClampFrame mousetrap::ColumnView mousetrap::DropDown mousetrap::Entry mousetrap::Expander mousetrap::Fixed mousetrap::FlowBox mousetrap::Frame mousetrap::Grid mousetrap::GridView mousetrap::HeaderBar mousetrap::ImageDisplay mousetrap::Label mousetrap::LevelBar mousetrap::ListView mousetrap::MenuBar mousetrap::Notebook mousetrap::Overlay mousetrap::Paned mousetrap::Popover mousetrap::PopoverButton mousetrap::PopoverMenu mousetrap::PopupMessageOverlay mousetrap::ProgressBar mousetrap::RenderArea mousetrap::Revealer mousetrap::Scale mousetrap::Scrollbar mousetrap::Separator mousetrap::SpinButton mousetrap::Spinner mousetrap::Stack mousetrap::StackSidebar mousetrap::StackSwitcher mousetrap::Switch mousetrap::TextView mousetrap::ToggleButton mousetrap::TransformBin mousetrap::Viewport mousetrap::Window

Public Member Functions

 Widget (detail::WidgetInternal *)
 construct from internal
 
virtual ~Widget ()
 default dtor
 
 Widget (const Widget &)=delete
 
Widgetoperator= (const Widget &) const =delete
 
 Widget (Widget &&other)=delete
 
Widgetoperator= (Widget &&)=delete
 
 operator NativeObject () const override
 implement signal emitter
 
NativeObject get_internal () const override
 expose internally managed object, \for_internal_use_only
 
virtual operator NativeWidget () const
 expose as GtkWidget, this is the only function that needs to be implemented in oder for an object to act as a widget
 
void activate ()
 activate the widget, if it is activatable. This will also trigger any associated animations or signals
 
Vector2f get_size_request ()
 get minimum allocated size
 
void set_size_request (Vector2f)
 set minimum allocated size
 
bool operator== (const Widget &other) const
 check if both widgets point to the same internal object
 
bool operator!= (const Widget &other) const
 check if both widgets point to the same internal object
 
void set_margin_top (float margin)
 set top margin, minimum distance to any other widget boundary
 
float get_margin_top () const
 get top margin, minimum distance to any other widget boundary
 
void set_margin_bottom (float margin)
 set bottom margin, minimum distance to any other widget boundary
 
float get_margin_bottom () const
 set botom margin, minimum distance to any other widget boundary
 
void set_margin_start (float margin)
 set left margin, minimum distance to any other widget boundary
 
float get_margin_start () const
 get left margin, minimum distance to any other widget boundary
 
void set_margin_end (float margin)
 set right margin, minimum distance to any other widget boundary
 
float get_margin_end () const
 get right margin, minimum distance to any other widget boundary
 
void set_margin_horizontal (float margin)
 set left and right margin, minimum distance to any other widget boundary
 
void set_margin_vertical (float margin)
 set top and bottom margin, minimum distance to any other widget boundary
 
void set_margin (float margin)
 set margin in all directions, minimum distance to any other widget boundary
 
void set_expand_horizontally (bool should_expand)
 set whether widget should attempt to allocate the maximum allowed space horizontally
 
bool get_expand_horizontally () const
 get whether widget should attempt to allocate the maximum allowed space horizontally
 
void set_expand_vertically (bool should_expand)
 set whether widget should attempt to allocate the maximum allowed space verticall
 
bool get_expand_vertically () const
 get whether widget should attempt to allocate the maximum allowed space vertically
 
void set_expand (bool both)
 set whether the widget should attempt to allocate the maximum allowed space in both dimensions
 
void set_horizontal_alignment (Alignment)
 set where the widget should align itself along the x-axis
 
Alignment get_horizontal_alignment () const
 get where the widget should align itself along the x-axis
 
void set_vertical_alignment (Alignment)
 set where the widget should align itself along the y-axis
 
Alignment get_vertical_alignment () const
 get where the widget should align itself along the y-axis
 
void set_alignment (Alignment both)
 set where the widget should align itself along both axes
 
void set_opacity (float opacity)
 set widget opacity, in [0, 1], if opacity is set to 0, equivalent to mousetrap::Widget::hide()
 
float get_opacity ()
 get widget opacity
 
void set_is_visible (bool b)
 set whether the widget should be hidden
 
bool get_is_visible ()
 get whether the widget is hidden
 
void set_tooltip_text (const std::string &text)
 set text displayed as a tooltip when the user hovers over the widget
 
void set_tooltip_widget (const Widget &widget)
 set arbitrary widget displayed as a tooltip when user hovers over the widget
 
void remove_tooltip_widget ()
 remove tooltip
 
void set_cursor (CursorType type)
 set the shape of cursor displayed when the cursor is above the widget
 
void set_cursor_from_image (const Image &image, Vector2i offset)
 set cursor from custom image
 
void hide ()
 hide the widget, this may set its allocated size to 0
 
void show ()
 show the widget, this allocates its size
 
void add_controller (const EventController &)
 add an event controller to the widget, a widget may have an arbitrary number of controllers
 
void remove_controller (const EventController &)
 remove an event controller from the widget, if event controller is not registered to widget, does nothing
 
void set_is_focusable (bool)
 set whether the widgets can contain input focus
 
bool get_is_focusable () const
 get whether widget can contain focus input focus
 
void grab_focus ()
 attempt to grab the input focus
 
bool get_has_focus ()
 get whether the wigdet currently holds input focus
 
void set_focus_on_click (bool)
 set whether the input should attempt to grab the focus when the user clicks on it
 
bool get_focus_on_click () const
 get whether the input should attempt to grab the focus when the user clicks on it
 
bool get_is_realized ()
 get whether the widget was realized
 
Vector2f get_minimum_size () const
 get minimum size, this will always be equal to or larger than the size request
 
Vector2f get_natural_size () const
 get natural size, this is the intended size of the widget if no expansion or clipping occurrs
 
Vector2f get_position () const
 get position
 
Vector2f get_allocated_size () const
 get allocated size
 
void unparent ()
 remove the widget from the container it is in, if any
 
void set_can_respond_to_input (bool)
 set whether the widget is allowed to gather input events. If set to false, the widget may appear "grayed out"
 
bool get_can_respond_to_input () const
 get whether the widget is allowed to gather input events
 
template<typename Function_t , typename Data_t >
void set_tick_callback (Function_t function, Data_t data)
 add a callback that is invoked every frame
 
template<typename Function_t >
void set_tick_callback (Function_t function)
 add a callback that is invoked every frame
 
void remove_tick_callback ()
 remove callback that si invoked every frame
 
Clipboard get_clipboard () const
 get the widgets associated clipboard
 
void set_hide_on_overflow (bool b)
 set whether a child widget inside this widget should be cutoff when it leaves this widgets boundary
 
bool get_hide_on_overflow () const
 get whether a child widget inside this widget should be cutoff when it leaves this widgets boundary
 
void set_listens_for_shortcut_actions (Action &)
 Convenience function that automatically adds the action to a shortcut controller of this widget.
 
void apply_style_class (const StyleClass &)
 apply style class to widget and its children
 
void add_css_class (const std::string &css)
 add css class
 
void remove_css_class (const std::string &css)
 remove css class
 
std::vector< std::string > get_css_classes () const
 get all applied css classes
 
- Public Member Functions inherited from mousetrap::SignalEmitter
void set_signal_blocked (const std::string &signal_id, bool b)
 block a signal by id \for_internal_use_only
 
bool get_signal_blocked (const std::string &signal_id) const
 get whether a signal is currently blocked
 
std::vector< std::string > get_all_signal_names ()
 get list of possible signal ids \for_internal_use_only
 
template<typename Function_t >
void connect_signal (const std::string &signal_id, Function_t *function, void *data=nullptr)
 connect static function to signal, does not work with lambdas \for_internal_use_only
 
void disconnect_signal (const std::string &signal_id)
 disconnect signal, it may not be invoked until reconnected, if signal is not registered, does nothing. For internal use only
 
virtual operator NativeObject () const =0
 expose as NativeObject, this is the GLib instance that signals are emitted on \for_internal_use_only
 
virtual NativeObject get_internal () const
 expose internally managed object, \for_internal_use_only
 

Protected Member Functions

 Widget (NativeWidget widget)
 ctor protected. Only inheriting classes should call this
 
- Protected Member Functions inherited from mousetrap::SignalEmitter
 SignalEmitter ()
 ctor
 
 ~SignalEmitter ()
 destructor
 

Friends

template<typename T >
struct WidgetImplementation
 

Detailed Description

Widget, super class of all renderable entities.

Constructor & Destructor Documentation

◆ Widget()

mousetrap::Widget::Widget ( NativeWidget  widget)
protected

ctor protected. Only inheriting classes should call this

Parameters
widgetGtkWidget instance

Member Function Documentation

◆ add_controller()

void mousetrap::Widget::add_controller ( const EventController controller)

add an event controller to the widget, a widget may have an arbitrary number of controllers

Parameters
controller

◆ add_css_class()

void mousetrap::Widget::add_css_class ( const std::string &  css)

add css class

Parameters
code

Referenced by apply_style_class().

◆ apply_style_class()

void mousetrap::Widget::apply_style_class ( const StyleClass c)

apply style class to widget and its children

Parameters
styleclass

References add_css_class(), mousetrap::StyleManager::add_style_class(), and mousetrap::StyleClass::get_name().

◆ get_allocated_size()

Vector2f mousetrap::Widget::get_allocated_size ( ) const

get allocated size

Returns
widget and height, in pixels

Referenced by mousetrap::RenderArea::from_gl_coordinates(), and mousetrap::RenderArea::to_gl_coordinates().

◆ get_can_respond_to_input()

bool mousetrap::Widget::get_can_respond_to_input ( ) const

get whether the widget is allowed to gather input events

Returns
true if interactable, false otherwise

◆ get_clipboard()

Clipboard mousetrap::Widget::get_clipboard ( ) const

get the widgets associated clipboard

Returns
clipboard

◆ get_css_classes()

std::vector< std::string > mousetrap::Widget::get_css_classes ( ) const

get all applied css classes

Returns
classes

◆ get_expand_horizontally()

bool mousetrap::Widget::get_expand_horizontally ( ) const

get whether widget should attempt to allocate the maximum allowed space horizontally

Returns
true if widget should expand horizontally, false otherwise

◆ get_expand_vertically()

bool mousetrap::Widget::get_expand_vertically ( ) const

get whether widget should attempt to allocate the maximum allowed space vertically

Returns
true if widget should expand vertically, false otherwise

◆ get_focus_on_click()

bool mousetrap::Widget::get_focus_on_click ( ) const

get whether the input should attempt to grab the focus when the user clicks on it

Returns
true if it should grab focus, false otherwise

◆ get_has_focus()

bool mousetrap::Widget::get_has_focus ( )

get whether the wigdet currently holds input focus

Returns
true if holding focus, false otherwise

◆ get_hide_on_overflow()

bool mousetrap::Widget::get_hide_on_overflow ( ) const

get whether a child widget inside this widget should be cutoff when it leaves this widgets boundary

Returns
true if child shut be cutoff, true if it should be fully visible

◆ get_horizontal_alignment()

Alignment mousetrap::Widget::get_horizontal_alignment ( ) const

get where the widget should align itself along the x-axis

Returns
alignment

◆ get_internal()

NativeObject mousetrap::Widget::get_internal ( ) const
overridevirtual

expose internally managed object, \for_internal_use_only

Reimplemented from mousetrap::SignalEmitter.

Reimplemented in mousetrap::Window.

◆ get_is_focusable()

bool mousetrap::Widget::get_is_focusable ( ) const

get whether widget can contain focus input focus

Returns
true if it can contain focus, false otherwise

◆ get_is_realized()

bool mousetrap::Widget::get_is_realized ( )

get whether the widget was realized

Returns
true if realized, false otherwise

◆ get_is_visible()

bool mousetrap::Widget::get_is_visible ( )

get whether the widget is hidden

Returns
false if hidden, true otherwise

◆ get_margin_bottom()

float mousetrap::Widget::get_margin_bottom ( ) const

set botom margin, minimum distance to any other widget boundary

Returns
margin

◆ get_margin_end()

float mousetrap::Widget::get_margin_end ( ) const

get right margin, minimum distance to any other widget boundary

Returns
margin

◆ get_margin_start()

float mousetrap::Widget::get_margin_start ( ) const

get left margin, minimum distance to any other widget boundary

Returns
margin

◆ get_margin_top()

float mousetrap::Widget::get_margin_top ( ) const

get top margin, minimum distance to any other widget boundary

Returns
margin

◆ get_minimum_size()

Vector2f mousetrap::Widget::get_minimum_size ( ) const

get minimum size, this will always be equal to or larger than the size request

Returns
widget and height, in pixels

◆ get_natural_size()

Vector2f mousetrap::Widget::get_natural_size ( ) const

get natural size, this is the intended size of the widget if no expansion or clipping occurrs

Returns
widget and height, in pixels

◆ get_opacity()

float mousetrap::Widget::get_opacity ( )

get widget opacity

Returns
opacity, in [0, 1]

◆ get_position()

Vector2f mousetrap::Widget::get_position ( ) const

get position

Returns
position, in pixels

◆ get_size_request()

Vector2f mousetrap::Widget::get_size_request ( )

get minimum allocated size

Returns
width, height

◆ get_vertical_alignment()

Alignment mousetrap::Widget::get_vertical_alignment ( ) const

get where the widget should align itself along the y-axis

Returns
alignment

◆ operator NativeObject()

mousetrap::Widget::operator NativeObject ( ) const
explicitoverridevirtual

implement signal emitter

Implements mousetrap::SignalEmitter.

Reimplemented in mousetrap::Window.

◆ operator!=()

bool mousetrap::Widget::operator!= ( const Widget other) const

check if both widgets point to the same internal object

Parameters
other
Returns
false if internally managed object is the same, true otherwise

◆ operator==()

bool mousetrap::Widget::operator== ( const Widget other) const

check if both widgets point to the same internal object

Parameters
other
Returns
true if internally managed object is the same, false otherwise

◆ remove_controller()

void mousetrap::Widget::remove_controller ( const EventController controller)

remove an event controller from the widget, if event controller is not registered to widget, does nothing

Parameters
controllercontroller to remove

◆ set_alignment()

void mousetrap::Widget::set_alignment ( Alignment  both)

set where the widget should align itself along both axes

Parameters
bothalignment

◆ set_can_respond_to_input()

void mousetrap::Widget::set_can_respond_to_input ( bool  b)

set whether the widget is allowed to gather input events. If set to false, the widget may appear "grayed out"

Parameters
btrue if interactable, false otherwise

◆ set_cursor()

void mousetrap::Widget::set_cursor ( CursorType  type)

set the shape of cursor displayed when the cursor is above the widget

Parameters
typecursor type

◆ set_cursor_from_image()

void mousetrap::Widget::set_cursor_from_image ( const Image image,
Vector2i  offset 
)

set cursor from custom image

Parameters
image
offsetwhere the pixel should be anchored, in pixels

◆ set_expand()

void mousetrap::Widget::set_expand ( bool  both)

set whether the widget should attempt to allocate the maximum allowed space in both dimensions

Parameters
bothtrue widget should expand, false otherwise

◆ set_expand_horizontally()

void mousetrap::Widget::set_expand_horizontally ( bool  should_expand)

set whether widget should attempt to allocate the maximum allowed space horizontally

Parameters
should_expandtrue if widget should expand horizontally, false otherwise

Referenced by mousetrap::Separator::Separator().

◆ set_expand_vertically()

void mousetrap::Widget::set_expand_vertically ( bool  should_expand)

set whether widget should attempt to allocate the maximum allowed space verticall

Parameters
should_expandtrue if widget should expand vertically, false otherwise

Referenced by mousetrap::Separator::Separator().

◆ set_focus_on_click()

void mousetrap::Widget::set_focus_on_click ( bool  b)

set whether the input should attempt to grab the focus when the user clicks on it

Parameters
btrue if it should grab focus, false otherwise

◆ set_hide_on_overflow()

void mousetrap::Widget::set_hide_on_overflow ( bool  b)

set whether a child widget inside this widget should be cutoff when it leaves this widgets boundary

Parameters
btrue if child shut be cutoff, true if it should be fully visible

◆ set_horizontal_alignment()

void mousetrap::Widget::set_horizontal_alignment ( Alignment  alignment)

set where the widget should align itself along the x-axis

Parameters
alignment

◆ set_is_focusable()

void mousetrap::Widget::set_is_focusable ( bool  b)

set whether the widgets can contain input focus

Parameters
btrue if it can contain focus, false otherwise

◆ set_is_visible()

void mousetrap::Widget::set_is_visible ( bool  b)

set whether the widget should be hidden

Parameters
bfalse if hidden, true otherwise

◆ set_listens_for_shortcut_actions()

void mousetrap::Widget::set_listens_for_shortcut_actions ( Action action)

Convenience function that automatically adds the action to a shortcut controller of this widget.

Parameters
actionAction

References mousetrap::Action::get_id(), mousetrap::Action::get_shortcuts(), and mousetrap::log::warning().

◆ set_margin()

void mousetrap::Widget::set_margin ( float  margin)

set margin in all directions, minimum distance to any other widget boundary

Parameters
margin

References set_margin_bottom(), set_margin_end(), set_margin_start(), and set_margin_top().

◆ set_margin_bottom()

void mousetrap::Widget::set_margin_bottom ( float  margin)

set bottom margin, minimum distance to any other widget boundary

Parameters
margin

Referenced by set_margin(), and set_margin_vertical().

◆ set_margin_end()

void mousetrap::Widget::set_margin_end ( float  margin)

set right margin, minimum distance to any other widget boundary

Parameters
margin

Referenced by set_margin(), and set_margin_horizontal().

◆ set_margin_horizontal()

void mousetrap::Widget::set_margin_horizontal ( float  margin)

set left and right margin, minimum distance to any other widget boundary

Parameters
margin

References set_margin_end(), and set_margin_start().

◆ set_margin_start()

void mousetrap::Widget::set_margin_start ( float  margin)

set left margin, minimum distance to any other widget boundary

Parameters
margin

Referenced by set_margin(), and set_margin_horizontal().

◆ set_margin_top()

void mousetrap::Widget::set_margin_top ( float  margin)

set top margin, minimum distance to any other widget boundary

Parameters
margin

Referenced by set_margin(), and set_margin_vertical().

◆ set_margin_vertical()

void mousetrap::Widget::set_margin_vertical ( float  margin)

set top and bottom margin, minimum distance to any other widget boundary

Parameters
margin

References set_margin_bottom(), and set_margin_top().

◆ set_opacity()

void mousetrap::Widget::set_opacity ( float  opacity)

set widget opacity, in [0, 1], if opacity is set to 0, equivalent to mousetrap::Widget::hide()

Parameters
opacity

◆ set_size_request()

void mousetrap::Widget::set_size_request ( Vector2f  size)

set minimum allocated size

Parameters
sizewidth, height

◆ set_tick_callback() [1/2]

template<typename Function_t >
void mousetrap::Widget::set_tick_callback ( Function_t  function)

add a callback that is invoked every frame

Template Parameters
Function_tstatic function or lambda with signature (FrameClock) -> TickCallbackResult
Parameters
function

References remove_tick_callback().

◆ set_tick_callback() [2/2]

template<typename Function_t , typename Data_t >
void mousetrap::Widget::set_tick_callback ( Function_t  function,
Data_t  data 
)

add a callback that is invoked every frame

Template Parameters
Function_tstatic function or lambda with signature (FrameClock, Data_t) -> TickCallbackResult
Data_tarbitrary data type
Parameters
function
data

References remove_tick_callback().

◆ set_tooltip_text()

void mousetrap::Widget::set_tooltip_text ( const std::string &  text)

set text displayed as a tooltip when the user hovers over the widget

Parameters
text

◆ set_tooltip_widget()

void mousetrap::Widget::set_tooltip_widget ( const Widget widget)

set arbitrary widget displayed as a tooltip when user hovers over the widget

Parameters
widget

References mousetrap::SignalEmitter::connect_signal().

◆ set_vertical_alignment()

void mousetrap::Widget::set_vertical_alignment ( Alignment  alignment)

set where the widget should align itself along the y-axis

Parameters
alignment

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