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

Container widget that displays a number of items in a single row, nested lists are possible. More...

#include <list_view.hpp>

Inheritance diagram for mousetrap::ListView:
mousetrap::has_signal_unmap< ListView > mousetrap::has_signal_map< ListView > mousetrap::has_signal_show< ListView > mousetrap::has_signal_hide< ListView > mousetrap::has_signal_destroy< ListView > mousetrap::has_signal_unrealize< ListView > mousetrap::has_signal_realize< ListView > mousetrap::has_signal_activate_item< ListView > mousetrap::Widget

Public Types

using Iterator = detail::_ListViewItem *
 iterator to a list, specifying it as the target during an operationt that adds an item to a list view will create a sublist at that iterator
 

Public Member Functions

 ListView (Orientation orientation=Orientation::HORIZONTAL, SelectionMode selection_mode=SelectionMode::NONE)
 ctor list view
 
 ListView (detail::ListViewInternal *)
 construct from internal
 
 ~ListView ()
 dtor
 
NativeObject get_internal () const override
 expose internal
 
Iterator push_back (const Widget &widget, Iterator iterator=nullptr)
 add widget to the back of the list
 
Iterator push_front (const Widget &widget, Iterator iterator=nullptr)
 add a widget to the front of the list
 
Iterator insert (const Widget &widget, uint64_t index, Iterator iterator=nullptr)
 add a widget at a specific position to the list
 
void remove (uint64_t index, Iterator iterator=nullptr)
 remove n-th element from list specified by iterator
 
void clear (Iterator iterator=nullptr)
 clear list at iterator
 
void set_widget_at (uint64_t i, const Widget &widget, Iterator iterator=nullptr)
 set widget at i-th position in list
 
int find (const Widget &widget, Iterator iterator=nullptr) const
 get index of widget, or -1 if widget is not in list
 
void set_enable_rubberband_selection (bool b)
 enable users to select multiple elements by click-dragging
 
bool get_enable_rubberband_selection () const
 get whether users can select multiple elements by click-dragging
 
void set_show_separators (bool b)
 set whether separators should be shown in between each item, this applies to the toplevel and all sub-lists
 
bool get_show_separators () const
 get whether separator should be shown in between each item
 
void set_single_click_activate (bool b)
 set whether the activate signal should be emitted when the user selects an item, as opposed to selected and activating it
 
bool get_single_click_activate () const
 get whether the activate signal should be emitted when the user selects an item, as opposed to selected and activating it
 
SelectionModelget_selection_model ()
 expose the selection model, connect to its signals to monitor list item selection
 
uint64_t get_n_items () const
 get number of itmes in list and all sub lists
 
void set_orientation (Orientation)
 
Orientation get_orientation () const
 
- Public Member Functions inherited from mousetrap::Widget
 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
 
- Public Member Functions inherited from mousetrap::has_signal_activate_item< ListView >
void connect_signal_activate_item (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_activate_item (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_activate_item_blocked (bool b)
 
bool get_signal_activate_item_blocked () const
 
void emit_signal_activate_item (guint position)
 invoke signal handler manually
 
void disconnect_signal_activate_item ()
 
- Public Member Functions inherited from mousetrap::has_signal_realize< ListView >
void connect_signal_realize (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_realize (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_realize_blocked (bool b)
 
bool get_signal_realize_blocked () const
 
void emit_signal_realize ()
 invoke signal handler manually
 
void disconnect_signal_realize ()
 
- Public Member Functions inherited from mousetrap::has_signal_unrealize< ListView >
void connect_signal_unrealize (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_unrealize (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_unrealize_blocked (bool b)
 Set whether signal emission should trigger the signal handler.
 
bool get_signal_unrealize_blocked () const
 get whether signal emission should trigger the signal handler
 
void emit_signal_unrealize ()
 invoke signal handler manually
 
void disconnect_signal_unrealize ()
 disconnect the signal handler
 
- Public Member Functions inherited from mousetrap::has_signal_destroy< ListView >
void connect_signal_destroy (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_destroy (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_destroy_blocked (bool b)
 Set whether signal emission should trigger the signal handler.
 
bool get_signal_destroy_blocked () const
 get whether signal emission should trigger the signal handler
 
void emit_signal_destroy ()
 invoke signal handler manually
 
void disconnect_signal_destroy ()
 disconnect the signal handler
 
- Public Member Functions inherited from mousetrap::has_signal_hide< ListView >
void connect_signal_hide (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_hide (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_hide_blocked (bool b)
 
bool get_signal_hide_blocked () const
 
void emit_signal_hide ()
 invoke signal handler manually
 
void disconnect_signal_hide ()
 
- Public Member Functions inherited from mousetrap::has_signal_show< ListView >
void connect_signal_show (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_show (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_show_blocked (bool b)
 
bool get_signal_show_blocked () const
 
void emit_signal_show ()
 invoke signal handler manually
 
void disconnect_signal_show ()
 
- Public Member Functions inherited from mousetrap::has_signal_map< ListView >
void connect_signal_map (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_map (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_map_blocked (bool b)
 
bool get_signal_map_blocked () const
 
void emit_signal_map ()
 invoke signal handler manually
 
void disconnect_signal_map ()
 
- Public Member Functions inherited from mousetrap::has_signal_unmap< ListView >
void connect_signal_unmap (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_unmap (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_unmap_blocked (bool b)
 
bool get_signal_unmap_blocked () const
 
void emit_signal_unmap ()
 invoke signal handler manually
 
void disconnect_signal_unmap ()
 

Static Public Attributes

static const uint64_t indent_per_depth = 20
 number of pixels a nested list item should be offset to the right
 
- Static Public Attributes inherited from mousetrap::has_signal_activate_item< ListView >
static const char * signal_id
 glib ID
 
- Static Public Attributes inherited from mousetrap::has_signal_realize< ListView >
static const char * signal_id
 glib ID
 
- Static Public Attributes inherited from mousetrap::has_signal_unrealize< ListView >
static const char * signal_id
 
- Static Public Attributes inherited from mousetrap::has_signal_destroy< ListView >
static const char * signal_id
 
- Static Public Attributes inherited from mousetrap::has_signal_hide< ListView >
static const char * signal_id
 glib ID
 
- Static Public Attributes inherited from mousetrap::has_signal_show< ListView >
static const char * signal_id
 glib ID
 
- Static Public Attributes inherited from mousetrap::has_signal_map< ListView >
static const char * signal_id
 glib ID
 
- Static Public Attributes inherited from mousetrap::has_signal_unmap< ListView >
static const char * signal_id
 glib ID
 

Additional Inherited Members

- Protected Member Functions inherited from mousetrap::Widget
 Widget (NativeWidget widget)
 ctor protected. Only inheriting classes should call this
 
- Protected Member Functions inherited from mousetrap::SignalEmitter
 SignalEmitter ()
 ctor
 
 ~SignalEmitter ()
 destructor
 
- Protected Member Functions inherited from mousetrap::has_signal_activate_item< ListView >
 has_signal_activate_item (ListView *instance)
 
- Protected Member Functions inherited from mousetrap::has_signal_realize< ListView >
 has_signal_realize (ListView *instance)
 
- Protected Member Functions inherited from mousetrap::has_signal_unrealize< ListView >
 has_signal_unrealize (ListView *instance)
 ctor protected
 
- Protected Member Functions inherited from mousetrap::has_signal_destroy< ListView >
 has_signal_destroy (ListView *instance)
 ctor protected
 
- Protected Member Functions inherited from mousetrap::has_signal_hide< ListView >
 has_signal_hide (ListView *instance)
 
- Protected Member Functions inherited from mousetrap::has_signal_show< ListView >
 has_signal_show (ListView *instance)
 
- Protected Member Functions inherited from mousetrap::has_signal_map< ListView >
 has_signal_map (ListView *instance)
 
- Protected Member Functions inherited from mousetrap::has_signal_unmap< ListView >
 has_signal_unmap (ListView *instance)
 

Detailed Description

Container widget that displays a number of items in a single row, nested lists are possible.

signal id signature emitted when...
selection_changed (ListView&, uint32_t position, (Data_t)) -> void Selection state changes, usually because the user selected a different item or the internal list of items was otherwise modified
Signals inherited from Widget
realize (ListView&, (Data_t)) -> void Widget is realized, usually right before it is drawn for the first time
unrealize (ListView&, (Data_t)) -> void Widget is unmapped and will no longer be drawn
destroy (ListView&, (Data_t)) -> void Widgets internal state is deallocated, calling Widget::~Widget() may not necessarily emit this signal
hide (ListView&, (Data_t)) -> void Widget is actively hidden, leaves the visible area of the window, or its opacity is set to 0
show (ListView&, (Data_t)) -> void Widget is drawn for the first time after being realized
map (ListView&, (Data_t)) -> void Widget is mapped, this happens the first time it and all its parents become visible
unmap (ListView&, (Data_t)) -> void Widget and all of its parents become hidden

Constructor & Destructor Documentation

◆ ListView()

mousetrap::ListView::ListView ( Orientation  orientation = Orientation::HORIZONTAL,
SelectionMode  selection_mode = SelectionMode::NONE 
)

ctor list view

Parameters
orientationOrientation, horizontal for left to right, vertical for top to bottom
selection_mode

Member Function Documentation

◆ clear()

void mousetrap::ListView::clear ( Iterator  iterator = nullptr)

clear list at iterator

Parameters
iteratoriterator to list to clear, or nullptr to clear the toplevel list

◆ find()

int mousetrap::ListView::find ( const Widget widget,
Iterator  iterator = nullptr 
) const

get index of widget, or -1 if widget is not in list

Parameters
widget
iterator

◆ get_enable_rubberband_selection()

bool mousetrap::ListView::get_enable_rubberband_selection ( ) const

get whether users can select multiple elements by click-dragging

Returns
true if enabled, false otherwise

◆ get_internal()

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

expose internal

Reimplemented from mousetrap::SignalEmitter.

◆ get_n_items()

uint64_t mousetrap::ListView::get_n_items ( ) const

get number of itmes in list and all sub lists

Returns
n items

◆ get_orientation()

Orientation mousetrap::ListView::get_orientation ( ) const

◆ get_selection_model()

SelectionModel * mousetrap::ListView::get_selection_model ( )

expose the selection model, connect to its signals to monitor list item selection

Returns
point to selection model, the instance is owned by the list view

◆ get_show_separators()

bool mousetrap::ListView::get_show_separators ( ) const

get whether separator should be shown in between each item

Returns
true if separators should be shown, false otherwise

◆ get_single_click_activate()

bool mousetrap::ListView::get_single_click_activate ( ) const

get whether the activate signal should be emitted when the user selects an item, as opposed to selected and activating it

Returns
true if emission already happens on selection, false otherwise

◆ insert()

ListView::Iterator mousetrap::ListView::insert ( const Widget widget,
uint64_t  index,
Iterator  iterator = nullptr 
)

add a widget at a specific position to the list

Parameters
widget
index
iteratoriterator to sub-list, or nullptr to add to the toplevel list
Returns
iterator to list the widget was inserted in

References mousetrap::log::critical().

Referenced by push_front().

◆ push_back()

ListView::Iterator mousetrap::ListView::push_back ( const Widget widget,
Iterator  iterator = nullptr 
)

add widget to the back of the list

Parameters
widget
iteratoriterator to sub-list, or nullptr to add to the toplevel list
Returns
iterator to list the widget was inserted in

References mousetrap::log::critical().

◆ push_front()

ListView::Iterator mousetrap::ListView::push_front ( const Widget widget,
Iterator  iterator = nullptr 
)

add a widget to the front of the list

Parameters
widget
iteratoriterator to sub-list, or nullptr to add to the toplevel list
Returns
iterator to list the widget was inserted in

References mousetrap::log::critical(), and insert().

◆ remove()

void mousetrap::ListView::remove ( uint64_t  index,
Iterator  iterator = nullptr 
)

remove n-th element from list specified by iterator

Parameters
index
iteratoriterator to list to remove from, or nullptr to remove from toplevel list

◆ set_enable_rubberband_selection()

void mousetrap::ListView::set_enable_rubberband_selection ( bool  b)

enable users to select multiple elements by click-dragging

Parameters
btrue if enabled, false otherwise

◆ set_orientation()

void mousetrap::ListView::set_orientation ( Orientation  orientation)

◆ set_show_separators()

void mousetrap::ListView::set_show_separators ( bool  b)

set whether separators should be shown in between each item, this applies to the toplevel and all sub-lists

Parameters
btrue if separators should be shown, false oherwise

◆ set_single_click_activate()

void mousetrap::ListView::set_single_click_activate ( bool  b)

set whether the activate signal should be emitted when the user selects an item, as opposed to selected and activating it

Parameters
btrue if emission should already happen on selection, false otherwise

◆ set_widget_at()

void mousetrap::ListView::set_widget_at ( uint64_t  i,
const Widget widget,
Iterator  iterator = nullptr 
)

set widget at i-th position in list

Parameters
iindex
widget
iteratoriterator to list, or nullptr to set widget in toplevel list

References mousetrap::log::critical().


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