31 #include "../../Core/Math/rect.h"
32 #include "../../Core/Math/easing.h"
33 #include "../../Core/Signals/signal.h"
34 #include "../../UI/Events/event.h"
35 #include "../View/view_geometry.h"
36 #include "../Style/style.h"
37 #include "../Style/style_cascade.h"
38 #include "../Style/style_get_value.h"
39 #include "focus_policy.h"
49 class ActivationChangeEvent;
51 class FocusChangeEvent;
56 class CursorDescription;
61 class View :
public std::enable_shared_from_this<View>
71 const std::shared_ptr<Style> &
style(
const std::string &
state = std::string())
const;
74 bool state(
const std::string &name)
const;
77 void set_state(
const std::string &name,
bool value);
89 const std::vector<std::shared_ptr<View>> &
subviews()
const;
207 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()>());
294 View &operator=(
const View &) =
delete;
296 std::unique_ptr<ViewImpl> impl;
void prev_focus()
Give focus to the previous view in the keyboard tab index order.
Pointf from_root_pos(const Pointf &pos)
Map from root content to local content coordinates.
Signal< void(FocusChangeEvent &)> & sig_focus_lost(bool use_capture=false)
View lost focus event.
Signal< void(KeyEvent &)> & sig_key_press(bool use_capture=false)
Key pressed event.
Signal< void(PointerEvent &)> & sig_pointer_press(bool use_capture=false)
Pointer button pressed event.
const Mat4f & view_transform() const
Current view transform.
Signal< void(FocusChangeEvent &)> & sig_focus_gained(bool use_capture=false)
View gained focus event.
const std::vector< std::shared_ptr< View > > & subviews() const
List of all immediate child views.
Pointer (mouse/tablet) event.
Definition: pointer_event.h:68
void remove_focus()
Remove focus from this view.
std::shared_ptr< View > find_view_at(const Pointf &pos) const
Find descendant view at the specified content relative position.
virtual float get_preferred_width(Canvas &canvas)
Calculates the preferred width of this view.
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.
void set_needs_render()
Signals this view needs to be rendered again.
Signal< void(PointerEvent &)> & sig_pointer_enter(bool use_capture=false)
Pointer entering view geometry event.
void remove_from_super()
Remove view from parent.
bool local_root() const
Indicates if the view acts as a local root for layout and rendering.
void set_focus_policy(FocusPolicy policy)
Set if this view automatically can gain focus.
friend class ViewImpl
Definition: view.h:299
Window resize event.
Definition: resize_event.h:37
Window was activated or deactivated event.
Definition: activation_change_event.h:44
bool is_static_position_and_visible() const
Test if view should participate in static layout calculations (layout_subviews)
Signal< void(KeyEvent &)> & sig_key_release(bool use_capture=false)
Key released event.
Pointf to_root_pos(const Pointf &pos)
Map from local content to root content coordinates.
Signal< void(PointerEvent &)> & sig_pointer_double_click(bool use_capture=false)
Pointer button double clicked event.
void set_geometry(const ViewGeometry &geometry)
View focus changed event.
Definition: focus_change_event.h:44
Signal< void(ResizeEvent &)> & sig_resize(bool use_capture=false)
Window resize event.
FocusPolicy
Automatic focus policy.
Definition: focus_policy.h:35
2D (x,y) point structure - Float
Definition: point.h:73
void set_state_cascade(const std::string &name, bool value)
Sets the state for this view and all siblings recursively, until a manually set state of the same nam...
virtual float get_preferred_height(Canvas &canvas, float width)
Calculates the preferred height of this view.
Signal< void(ActivationChangeEvent &)> & sig_deactivated(bool use_capture=false)
Window deactivated event.
bool state(const std::string &name) const
Test if a style state is currently set.
void update_cursor(DisplayWindow &window)
Update window cursor to the cursor used by this view.
View * focus_view() const
The view receiving keyboard events or nullptr if no view has the focus.
void clear_exception_encountered()
void next_focus()
Give focus to the next view in the keyboard tab index order.
2D Graphics Canvas
Definition: canvas.h:73
const StyleCascade & style_cascade() const
Style cascade currently active for this view.
Signal< void(PointerEvent &)> & sig_pointer_proximity_change(bool use_capture=false)
Pointer proximity change event.
void set_cursor(const CursorDescription &cursor)
Set the cursor icon used when cursor is above this view.
Base class for views participating as a root view in the user interface.
Definition: root_view.h:38
virtual float get_first_baseline_offset(Canvas &canvas, float width)
Calculates the offset to the first baseline.
static void dispatch_event(View *target, EventUI *e, bool no_propagation=false)
Dispatch event to signals listening for events.
bool content_clipped() const
Content clipping flag.
void set_cursor(StandardCursor type)
static float linear(float t)
void set_content_clipped(bool clipped)
Specifies if content should be clipped during rendering.
unsigned int tab_index() const
Tab index for keyboard focus changes.
bool needs_layout() const
Test if view geometry needs to be recalculated.
Canvas get_canvas() const
bool hidden() const
Test if view is set to hidden.
View for an area of the user interface.
Definition: view.h:62
void set_view_transform(const Mat4f &transform)
Specifies the view transform to be applied before its contents and children are rendered.
Base class for events being dispatched through the view hiarchy.
Definition: UI/Events/event.h:48
FocusPolicy focus_policy() const
Focus policy active for this view.
Pointf to_screen_pos(const Pointf &pos)
Map from local content to screen coordinates.
Pointf from_screen_pos(const Pointf &pos)
Map from screen to local content coordinates.
virtual void render_content(Canvas &canvas)
Renders the content of a view.
Definition: view.h:284
void set_focus()
Set this view as the focused view.
bool has_focus() const
Test if this view is receiving keyboard input.
Definition: view.h:198
4D matrix
Definition: mat2.h:51
virtual void subview_removed(const std::shared_ptr< View > &view)
Child view was removed from this view.
Definition: view.h:290
This class contains everything to construct a cursor - its data, default settings etc.
Definition: cursor_description.h:71
virtual void subview_added(const std::shared_ptr< View > &view)
Child view was added to this view.
Definition: view.h:287
void set_needs_layout()
Forces recalculation of view geometry before next rendering.
Signal< void(PointerEvent &)> & sig_pointer_release(bool use_capture=false)
Pointer button released event.
Signal< void(CloseEvent &)> & sig_close(bool use_capture=false)
Window close button clicked event.
void set_tab_index(unsigned int index)
Sets the tab index used for keyboard focus changes.
Signal< void(PointerEvent &)> & sig_pointer_move(bool use_capture=false)
Pointer moved above view event.
Window close button was clicked event.
Definition: close_event.h:37
void stop_animations()
Stop all activate animation functions.
const View * root_view() const
Root view in view hierachy.
Definition: view_geometry.h:39
virtual void layout_subviews(Canvas &canvas)
Sets the view geometry for all subviews of this view.
void set_hidden(bool value=true)
Hides a view from layout and rendering.
StandardCursor
Standard Cursor.
Definition: display_window.h:71
SlotContainer slots
Slot container helping with automatic disconnection of connected slots when the view is destroyed.
Definition: view.h:83
Signal< void(PointerEvent &)> & sig_pointer_leave(bool use_capture=false)
Pointer leaving view geometry event.
View * owner_view() const
View hierachy owner or nullptr if there is no owner.
void add_subview(const std::shared_ptr< View > &view)
Add a child view.
Top-level window class.
Definition: display_window.h:102
void set_inherit_cursor()
Specify that the cursor icon is inherited from the super view.
const ViewGeometry & geometry() const
Actual view position and size after layout.
Style value resolver.
Definition: style_cascade.h:66
Keyboard key event.
Definition: key_event.h:48
Signal< void(ActivationChangeEvent &)> & sig_activated(bool use_capture=false)
Window activated event.
const std::shared_ptr< Style > & style(const std::string &state=std::string()) const
Style properties for the specified state.
View * superview() const
Parent view node or nullptr if the view is the current root node.
void set_state(const std::string &name, bool value)
Set or clear style state.
bool render_exception_encountered() const
Test if this view generated an exception during rendering.
virtual float get_last_baseline_offset(Canvas &canvas, float width)
Calculates the offset to the last baseline.