neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
scrollable_widget.hpp
Go to the documentation of this file.
1// scrollable_widget.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
25
26namespace neogfx
27{
35
37 {
38 return static_cast<scrolling_disposition>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
39 }
40
42 {
43 return static_cast<scrolling_disposition>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
44 }
45
46 template <typename Base = widget<>>
48 {
51 protected:
61 {
62 public:
64 neolib::scoped_flag{ aParent.iSuppressScrollbarVisibilityUpdates }
65 {}
66 };
67 public:
68 template <typename... Args>
69 scrollable_widget(Args&&... aArgs) :
70 scrollable_widget{ neogfx::scrollbar_style::Normal, std::forward<Args>(aArgs)... }
71 {
72 }
73 template <typename... Args>
74 scrollable_widget(neogfx::scrollbar_style aScrollbarStyle, Args&&... aArgs) :
75 base_type{ std::forward<Args>(aArgs)... },
76 iScrollbarStyle{ aScrollbarStyle },
77 iVerticalScrollbar{ *this, scrollbar_orientation::Vertical, aScrollbarStyle },
78 iHorizontalScrollbar{ *this, scrollbar_orientation::Horizontal, aScrollbarStyle },
79 iIgnoreScrollbarUpdates{ 0 },
80 iUpdatingScrollbarVisibility{ false },
81 iMovingWidgets{ false },
82 iSuppressScrollbarVisibilityUpdates{ false }
83 {
84 init();
85 }
86 template <typename... Args>
87 scrollable_widget(i_widget& aParent, Args&&... aArgs) :
88 scrollable_widget{ aParent, neogfx::scrollbar_style::Normal, std::forward<Args>(aArgs)... }
89 {
90 }
91 template <typename... Args>
92 scrollable_widget(i_widget& aParent, neogfx::scrollbar_style aScrollbarStyle, Args&&... aArgs) :
93 base_type{ aParent, std::forward<Args>(aArgs)... },
94 iScrollbarStyle{ aScrollbarStyle },
95 iVerticalScrollbar{ *this, scrollbar_orientation::Vertical, aScrollbarStyle },
96 iHorizontalScrollbar{ *this, scrollbar_orientation::Horizontal, aScrollbarStyle },
97 iIgnoreScrollbarUpdates{ 0 },
98 iUpdatingScrollbarVisibility{ false },
99 iMovingWidgets{ false },
100 iSuppressScrollbarVisibilityUpdates{ false }
101 {
102 init();
103 }
104 template <typename... Args>
105 scrollable_widget(i_layout& aLayout, Args&&... aArgs) :
106 scrollable_widget{ aLayout, neogfx::scrollbar_style::Normal, std::forward<Args>(aArgs)... }
107 {
108 }
109 template <typename... Args>
110 scrollable_widget(i_layout& aLayout, neogfx::scrollbar_style aScrollbarStyle, Args&&... aArgs) :
111 base_type{ aLayout, std::forward<Args>(aArgs)... },
112 iScrollbarStyle{ aScrollbarStyle },
113 iVerticalScrollbar{ *this, scrollbar_orientation::Vertical, aScrollbarStyle },
114 iHorizontalScrollbar{ *this, scrollbar_orientation::Horizontal, aScrollbarStyle },
115 iIgnoreScrollbarUpdates{ 0 },
116 iUpdatingScrollbarVisibility{ false },
117 iMovingWidgets{ false },
118 iSuppressScrollbarVisibilityUpdates{ false }
119 {
120 init();
121 }
124 public:
126 public:
127 point scroll_position() const;
128 void scroll_to(i_widget& aChild);
129 public:
130 void layout_items_started() override;
131 void layout_items_completed() override;
132 public:
133 void resized() override;
134 rect client_rect(bool aExtendIntoPadding = true) const override;
135 widget_part part(point const& aPosition) const override;
136 public:
137 void paint_non_client_after(i_graphics_context& aGc) const override;
138 public:
139 bool mouse_wheel_scrolled(mouse_wheel aWheel, point const& aPosition, delta aDelta, key_modifiers_e aKeyModifiers) override;
140 void mouse_button_pressed(mouse_button aButton, point const& aPosition, key_modifiers_e aKeyModifiers) override;
141 void mouse_button_double_clicked(mouse_button aButton, point const& aPosition, key_modifiers_e aKeyModifiers) override;
142 void mouse_button_released(mouse_button aButton, point const& aPosition) override;
143 void mouse_moved(point const& aPosition, key_modifiers_e aKeyModifiers) override;
144 void mouse_entered(point const& aPosition) override;
145 void mouse_left() override;
146 public:
147 bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override;
148 public:
149 virtual scrollbar const& vertical_scrollbar() const;
150 virtual scrollbar& vertical_scrollbar();
151 virtual scrollbar const& horizontal_scrollbar() const;
154 virtual neogfx::scrolling_disposition scrolling_disposition(i_widget const& aChildWidget) const;
155 public:
156 rect scroll_area() const override;
157 size scroll_page() const override;
158 protected:
159 rect scrollbar_geometry(i_scrollbar const& aScrollbar) const override;
160 void scrollbar_updated(i_scrollbar const& aScrollbar, i_scrollbar::update_reason_e aReason) override;
161 color scrollbar_color(i_scrollbar const& aScrollbar) const override;
162 protected:
163 i_widget const& as_widget() const override;
164 i_widget& as_widget() override;
165 protected:
166 virtual bool use_scrollbar_container_updater() const;
167 void update_scrollbar_visibility() override;
168 virtual bool update_scrollbar_visibility(usv_stage_e aStage);
169 virtual void scroll_page_updated();
170 protected:
171 void init_scrollbars();
172 private:
173 void init();
174 private:
175 sink iSink;
176 std::optional<widget_timer> iScrollbarUpdater;
177 neogfx::scrollbar_style iScrollbarStyle;
178 scrollbar iVerticalScrollbar;
179 scrollbar iHorizontalScrollbar;
180 point iOldScrollPosition;
181 uint32_t iIgnoreScrollbarUpdates;
182 bool iUpdatingScrollbarVisibility;
183 bool iMovingWidgets;
184 bool iSuppressScrollbarVisibilityUpdates;
185 };
186
187 extern template class scrollable_widget<framed_widget<widget<>>>;
189
190}
widget_part part(point const &aPosition) const override
rect scroll_area() const override
bool mouse_wheel_scrolled(mouse_wheel aWheel, point const &aPosition, delta aDelta, key_modifiers_e aKeyModifiers) override
bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override
rect scrollbar_geometry(i_scrollbar const &aScrollbar) const override
scrollable_widget(const scrollable_widget &)=delete
void mouse_entered(point const &aPosition) override
size scroll_page() const override
virtual bool use_scrollbar_container_updater() const
virtual neogfx::scrolling_disposition scrolling_disposition() const
scrollable_widget(i_widget &aParent, neogfx::scrollbar_style aScrollbarStyle, Args &&... aArgs)
neogfx::scrollbar_style scrollbar_style() const
void mouse_button_released(mouse_button aButton, point const &aPosition) override
scrollable_widget(i_layout &aLayout, Args &&... aArgs)
scrollable_widget(neogfx::scrollbar_style aScrollbarStyle, Args &&... aArgs)
scrollable_widget(i_layout &aLayout, neogfx::scrollbar_style aScrollbarStyle, Args &&... aArgs)
void layout_items_completed() override
virtual scrollbar const & vertical_scrollbar() const
rect client_rect(bool aExtendIntoPadding=true) const override
void scrollbar_updated(i_scrollbar const &aScrollbar, i_scrollbar::update_reason_e aReason) override
void update_scrollbar_visibility() override
void mouse_button_pressed(mouse_button aButton, point const &aPosition, key_modifiers_e aKeyModifiers) override
void paint_non_client_after(i_graphics_context &aGc) const override
i_widget const & as_widget() const override
scrollable_widget(i_widget &aParent, Args &&... aArgs)
void mouse_button_double_clicked(mouse_button aButton, point const &aPosition, key_modifiers_e aKeyModifiers) override
virtual scrollbar const & horizontal_scrollbar() const
void scroll_to(i_widget &aChild)
scrollable_widget(Args &&... aArgs)
void mouse_moved(point const &aPosition, key_modifiers_e aKeyModifiers) override
color scrollbar_color(i_scrollbar const &aScrollbar) const override
scoped_flag(bool &aFlag, bool aValue=true)
Definition scoped.hpp:47
scrollbar_orientation
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:60
mouse_wheel
Definition i_mouse.hpp:42
mouse_button
Definition i_mouse.hpp:31
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:55
scrollable_widget< framed_widget< widget<> > > framed_scrollable_widget
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28