Skip to content

Commit 23c785b

Browse files
committed
stuff
1 parent 24ce4c2 commit 23c785b

3 files changed

Lines changed: 48 additions & 8 deletions

File tree

src/ruis/widget/base/touch/flickable.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#include "flickable.hpp"
2323

24+
#include <utki/time.hpp>
25+
2426
using namespace ruis::touch;
2527

2628
ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
@@ -45,6 +47,8 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
4547
case state::idle:
4648
utki::assert(event.action == button_action::press, SL);
4749

50+
this->last_touch_move_timestamp_ms = utki::get_ticks_ms();
51+
4852
this->cur_state = state::within_scroll_threshold;
4953
this->prev_touch_point = event.pos;
5054
this->cur_pointer_id = event.pointer_id;
@@ -66,6 +70,8 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
6670
utki::assert(event.action == button_action::release, SL);
6771
this->cur_state = state::idle;
6872

73+
// TODO: start updating
74+
6975
// std::cout << "idle\n";
7076

7177
return event_status::consumed;
@@ -81,11 +87,22 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
8187
}
8288
}
8389

90+
uint32_t cur_ticks_ms = utki::get_ticks_ms();
91+
uint32_t dt_ms = cur_ticks_ms - this->last_touch_move_timestamp_ms;
92+
this->last_touch_move_timestamp_ms = cur_ticks_ms;
93+
94+
vec2 delta = event.pos - this->prev_touch_point;
95+
96+
this->touch_velocity_px_per_ms = delta / ruis::real(dt_ms);
97+
98+
std::cout << "dt_ms = " << dt_ms << std::endl;
99+
std::cout << "touch velocity = " << this->touch_velocity_px_per_ms << std::endl;
100+
84101
switch (this->cur_state) {
85102
default:
86-
utki::assert(false, SL);
87103
[[fallthrough]];
88104
case state::idle:
105+
utki::assert(false, SL);
89106
return this->flickable_on_mouse_move(event);
90107
case state::within_scroll_threshold:
91108
{
@@ -96,7 +113,6 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
96113

97114
return event_status::consumed;
98115
}
99-
vec2 delta = event.pos - this->prev_touch_point;
100116
vec2 abs_delta = abs(delta);
101117

102118
// std::cout << "mouse move: within scroll threshold, delta: " << delta << ", abs_delta: " << abs_delta << "\n";
@@ -136,12 +152,15 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
136152
return this->flickable_on_mouse_move(event);
137153
case state::scrolling:
138154
{
139-
auto delta = event.pos - this->prev_touch_point;
140-
141155
// std::cout << "mouse move: scrolling, delta: " << delta << "\n";
142156
this->flickable_scroll_by(-delta);
143157
this->prev_touch_point = event.pos;
144158
return event_status::consumed;
145159
}
146160
}
147161
}
162+
163+
void flickable::update(uint32_t dt_ms)
164+
{
165+
// TODO:
166+
}

src/ruis/widget/base/touch/flickable.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525

2626
namespace ruis::touch {
2727

28-
class flickable : virtual public ruis::widget
28+
class flickable :
29+
virtual public ruis::widget, //
30+
private updateable
2931
{
3032
constexpr static auto scroll_threshold_pp = 5;
3133

@@ -46,6 +48,14 @@ class flickable : virtual public ruis::widget
4648
// This variable holds the pointer ID of the current touch.
4749
unsigned cur_pointer_id = std::numeric_limits<unsigned>::max();
4850

51+
// timestamp of the last touch move event (i.e. mouse_move event)
52+
uint32_t last_touch_move_timestamp_ms;
53+
54+
// delta of the last touch move
55+
vec2 last_touch_move_delta;
56+
57+
vec2 touch_velocity_px_per_ms;
58+
4959
public:
5060
event_status on_mouse_button(const mouse_button_event& event) override;
5161
event_status on_mouse_move(const mouse_move_event& event) override;
@@ -61,6 +71,9 @@ class flickable : virtual public ruis::widget
6171
* @return Number of pixels actually scrolled.
6272
*/
6373
virtual vec2 flickable_scroll_by(const vec2& delta) = 0;
74+
75+
private:
76+
void update(uint32_t dt_ms) override;
6477
};
6578

6679
} // namespace ruis::touch

tests/touch/src/scroll_area_page.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ruis::widget_list make_scroll_area_page_contents(utki::shared_ref<ruis::context>
7676
),
7777
m::text(c, {}, U"some text"s)
7878
};
79-
// clang-format on
79+
// clang-format on
8080
}
8181

8282
class scroll_area_page :
@@ -85,7 +85,15 @@ class scroll_area_page :
8585
{
8686
public:
8787
scroll_area_page(utki::shared_ref<ruis::context> c) :
88-
ruis::widget(std::move(c), {}, {}),
88+
// clang-format off
89+
ruis::widget(
90+
std::move(c),
91+
{},
92+
{
93+
.clip = true
94+
}
95+
),
96+
// clang-format on
8997
ruis::page(this->context, {}),
9098
// clang-format off
9199
ruis::touch::scroll_area(
@@ -95,7 +103,7 @@ class scroll_area_page :
95103
m::column(
96104
this->context,
97105
{
98-
.layout_params = {
106+
.layout_params{
99107
.dims = {ruis::dim::fill, ruis::dim::min}
100108
}
101109
},

0 commit comments

Comments
 (0)