32#include "../../Core/Math/mat4.h"
33#include "../../Core/Math/rect.h"
34#include "../../Core/Math/easing.h"
35#include "../../Core/Signals/signal.h"
36#include "../../UI/Events/event.h"
37#include "../View/view_geometry.h"
38#include "../Style/style.h"
39#include "../Style/style_cascade.h"
40#include "../Style/style_get_value.h"
41#include "focus_policy.h"
51 class ActivationChangeEvent;
53 class FocusChangeEvent;
58 class CursorDescription;
65 class View :
public std::enable_shared_from_this<View>
75 const std::shared_ptr<Style> &
style(
const std::string &
state = std::string())
const;
78 bool state(
const std::string &name)
const;
81 void set_state(
const std::string &name,
bool value);
93 const std::vector<std::shared_ptr<View>> &
children()
const;
98 template<
typename T,
typename... Types>
101 auto child = std::make_shared<T>(std::forward<Types>(args)...);
108 return add_child<View>();
117 template<
typename T,
typename... Types>
120 auto action = std::make_shared<T>(std::forward<Types>(args)...);
126 const std::vector<std::shared_ptr<ViewAction>> &
actions()
const;
244 void animate(
float from,
float to,
const std::function<
void(
float)> &setter,
int duration_ms = 400,
const std::function<
float(
float)> &easing =
Easing::linear, std::function<
void()> animation_end = std::function<
void()>());
360 View &operator=(
const View &) =
delete;
362 std::unique_ptr<ViewImpl> impl;
Window was activated or deactivated event.
Definition activation_change_event.h:44
2D Graphics Canvas
Definition canvas.h:72
Window close button was clicked event.
Definition close_event.h:37
This class contains everything to construct a cursor - its data, default settings etc.
Definition cursor_description.h:70
Top-level window class.
Definition display_window.h:101
static float linear(float t)
Base class for events being dispatched through the view hiarchy.
Definition UI/Events/event.h:48
View focus changed event.
Definition focus_change_event.h:44
Keyboard key event.
Definition key_event.h:48
4D matrix
Definition mat4.h:78
Pointer event.
Definition pointer_event.h:68
2D (x,y) point structure - Float
Definition point.h:72
Window resize event.
Definition resize_event.h:37
Style value resolver.
Definition style_cascade.h:68
Recognizes actions in a view and captures input for the duration of the action.
Definition view_action.h:45
Definition view_geometry.h:39
Base class for managing a tree of views.
Definition view_tree.h:42
View for an area of the user interface.
Definition view.h:66
bool needs_layout() const
Test if view geometry needs to be recalculated.
virtual float calculate_preferred_height(Canvas &canvas, float width)
Calculates the preferred height of this view.
virtual float calculate_first_baseline_offset(Canvas &canvas, float width)
Calculates the offset to the first baseline.
void set_state_cascade(const std::string &name, bool value)
Sets the state for this view and all children recursively, until a manually set state of the same nam...
virtual float calculate_preferred_width(Canvas &canvas)
Calculates the preferred width of this view.
bool render_exception_encountered() const
Test if this view generated an exception during rendering.
void draw_without_layout()
Render view and its children directly, without re-layout.
View * parent() const
Parent view node or nullptr if the view is the current root node.
Signal< void(FocusChangeEvent &)> sig_focus_lost)(bool use_capture=false)
View lost focus event.
bool has_focus() const
Test if this view is receiving keyboard input.
Definition view.h:235
void add_action(const std::shared_ptr< ViewAction > &action)
Add an action recognizer.
Signal< void(PointerEvent &)> sig_pointer_leave)(bool use_capture=false)
Pointer leaving view geometry event.
Signal< void(PointerEvent &)> sig_pointer_release)(bool use_capture=false)
Pointer button released event.
void set_focus()
Set this view as the focused view.
bool hidden() const
Test if view is set to hidden.
virtual void render_border(Canvas &canvas)
Renders the border of a view.
void set_cursor(const CursorDescription &cursor)
Set the cursor icon used when cursor is above this view.
float last_baseline_offset(Canvas &canvas, float width)
Calculates the offset to the last baseline.
const std::vector< std::shared_ptr< View > > & children() const
List of all immediate child views.
const ViewGeometry & geometry() const
Actual view position and size after layout.
const StyleCascade & style_cascade() const
Style cascade currently active for this view.
const std::vector< std::shared_ptr< ViewAction > > & actions() const
List of all action recognizers.
void set_inherit_cursor()
Specify that the cursor icon is inherited from the parent view.
virtual float calculate_definite_width(bool &out_is_definite)
The content width used for percentages or other definite calculations.
std::shared_ptr< T > add_child(Types &&... args)
Definition view.h:99
Pointf from_screen_pos(const Pointf &pos)
Map from screen to local content coordinates.
static void dispatch_event(View *target, EventUI *e, bool no_propagation=false)
Dispatch event to signals listening for events.
void set_content_clipped(bool clipped)
Specifies if content should be clipped during rendering.
Signal< void(ActivationChangeEvent &)> sig_activated)(bool use_capture=false)
Window activated event.
void stop_animations()
Stop all activate animation functions.
virtual void child_added(const std::shared_ptr< View > &view)
Child view was added to this view.
Definition view.h:333
void set_tab_index(unsigned int index)
Sets the tab index used for keyboard focus changes.
bool state(const std::string &name) const
Test if a style state is currently set.
Pointf to_root_pos(const Pointf &pos, bool relative_to_margin=false)
Map from local content to root content or margin (plus content, padding, border and margin) coordinat...
Signal< void(CloseEvent &)> sig_close)(bool use_capture=false)
Window close button clicked event.
friend class ViewImpl
Definition view.h:365
void set_focus_policy(FocusPolicy policy)
Set if this view automatically can gain focus.
Pointf to_screen_pos(const Pointf &pos)
Map from local content to screen coordinates.
float definite_height()
The content height used for percentages or other definite calculations.
float preferred_height(Canvas &canvas, float width)
Calculates the preferred height of this view.
Signal< void(PointerEvent &)> sig_pointer_move)(bool use_capture=false)
Pointer moved above view event.
Signal< void(KeyEvent &)> sig_key_release)(bool use_capture=false)
Key released event.
bool is_width_definite()
Test if the view has a definite width.
Signal< void(FocusChangeEvent &)> sig_focus_gained)(bool use_capture=false)
View gained focus event.
virtual void updated_view_tree()
Definition view.h:356
float first_baseline_offset(Canvas &canvas, float width)
Calculates the offset to the first baseline.
Signal< void(PointerEvent &)> sig_pointer_press)(bool use_capture=false)
Pointer button pressed event.
void next_focus()
Give focus to the next view in the keyboard tab index order.
void set_state(const std::string &name, bool value)
Set or clear style state.
float preferred_width(Canvas &canvas)
Calculates the preferred width of this view.
Signal< void(ResizeEvent &)> sig_resize)(bool use_capture=false)
Window resize event.
virtual float calculate_last_baseline_offset(Canvas &canvas, float width)
Calculates the offset to the last baseline.
void set_hidden(bool value=true)
Hides a view from layout and rendering.
void add_child(const std::shared_ptr< View > &view)
Add a child view.
std::shared_ptr< View > add_child()
Definition view.h:106
Signal< void(ActivationChangeEvent &)> sig_deactivated)(bool use_capture=false)
Window deactivated event.
SlotContainer slots
Slot container helping with automatic disconnection of connected slots when the view is destroyed.
Definition view.h:87
Signal< void(KeyEvent &)> sig_key_press)(bool use_capture=false)
Key pressed event.
View * focus_view() const
The view receiving keyboard events or nullptr if no view has the focus.
virtual void render_content(Canvas &canvas)
Renders the content of a view.
Definition view.h:324
Signal< void(PointerEvent &)> sig_pointer_enter)(bool use_capture=false)
Pointer entering view geometry event.
void animate(float from, float to, const std::function< void(float)> &setter, int duration_ms=400, const std::function< float(float)> &easing=Easing::linear, std::function< void()> animation_end=std::function< void()>())
Continously call an animation function for the specified duration.
virtual void render_background(Canvas &canvas)
Renders the background of a view.
Signal< void(PointerEvent &)> sig_pointer_double_click)(bool use_capture=false)
Pointer button double clicked event.
FocusPolicy focus_policy() const
Focus policy active for this view.
virtual float calculate_definite_height(bool &out_is_definite)
The content height used for percentages or other definite calculations.
void set_needs_render()
Signals this view needs to be rendered again.
void set_cursor(StandardCursor type)
unsigned int tab_index() const
Tab index for keyboard focus changes.
void set_geometry(const ViewGeometry &geometry)
bool is_static_position_and_visible() const
Test if view should participate in static layout calculations (layout_children)
void set_needs_layout()
Forces recalculation of view geometry before next rendering.
std::shared_ptr< T > add_action(Types &&... args)
Definition view.h:118
float definite_width()
The content width used for percentages or other definite calculations.
void prev_focus()
Give focus to the previous view in the keyboard tab index order.
void remove_focus()
Remove focus from this view.
virtual void child_removed(const std::shared_ptr< View > &view)
Child view was removed from this view.
Definition view.h:336
bool is_height_definite()
Test if the view has a definite height.
virtual void layout_children(Canvas &canvas)
Sets the view geometry for all children of this view.
void update_cursor(DisplayWindow &window)
Update window cursor to the cursor used by this view.
const ViewTree * view_tree() const
Tree in view hierachy.
const std::shared_ptr< Style > & style(const std::string &state=std::string()) const
Style properties for the specified state.
std::shared_ptr< View > find_view_at(const Pointf &pos) const
Find descendant view at the specified content relative position.
bool content_clipped() const
Content clipping flag.
Pointf from_root_pos(const Pointf &pos)
Map from root content to local content coordinates.
void remove_from_parent()
Remove view from parent.
const Mat4f & view_transform() const
Current view transform.
void clear_exception_encountered()
Signal< void(PointerEvent &)> sig_pointer_proximity_change)(bool use_capture=false)
Pointer proximity change event.
void set_view_transform(const Mat4f &transform)
Specifies the view transform to be applied before its contents and children are rendered.
StandardCursor
Standard Cursor.
Definition display_window.h:69
FocusPolicy
Automatic focus policy.
Definition focus_policy.h:35