Skip to content

Commit 84e4451

Browse files
committed
stuff
1 parent 1336a5a commit 84e4451

6 files changed

Lines changed: 48 additions & 35 deletions

File tree

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
5050
utki::assert(event.action == button_action::press, SL);
5151

5252
this->push_touch_move_to_history({.position = event.pos, .timestamp_ms = utki::get_ticks_ms()});
53-
auto vel = this->calculate_touch_velocity();
54-
std::cout << "touch press, vel = " << vel << std::endl;
53+
54+
// std::cout << "touch press, vel = " << this->calculate_touch_velocity() << std::endl;
5555

5656
this->cur_state = state::within_scroll_threshold;
5757
this->prev_touch_point = event.pos;
@@ -69,14 +69,13 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
6969
utki::assert(event.action == button_action::release, SL);
7070
this->cur_state = state::idle;
7171

72-
auto vel = this->calculate_touch_velocity();
73-
std::cout << "touch release, vel = " << vel << std::endl;
72+
// std::cout << "touch release, vel = " << this->calculate_touch_velocity() << std::endl;
7473

7574
this->touch_history.clear();
7675

7776
return this->flickable_on_mouse_button(event);
7877
}
79-
case state::scrolling:
78+
case state::dragging:
8079
{
8180
utki::assert(event.action == button_action::release, SL);
8281
this->cur_state = state::idle;
@@ -107,8 +106,7 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
107106

108107
this->push_touch_move_to_history({.position = event.pos, .timestamp_ms = utki::get_ticks_ms()});
109108

110-
auto vel = this->calculate_touch_velocity();
111-
std::cout << "touch move, vel = " << vel << std::endl;
109+
// std::cout << "touch move, vel = " << this->calculate_touch_velocity() << std::endl;
112110

113111
switch (this->cur_state) {
114112
default:
@@ -132,29 +130,36 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
132130
// std::cout << "mouse move: within scroll threshold, delta: " << delta << ", abs_delta: " << abs_delta << "\n";
133131

134132
if (abs_delta.x() > this->scroll_threshold_px || abs_delta.y() > this->scroll_threshold_px) {
135-
this->cur_state = state::scrolling;
133+
this->cur_state = state::dragging;
136134

137135
// std::cout << "scrolling\n";
138136

139137
this->prev_touch_point = event.pos;
140138

141139
// send mouse button up event out of widget area to cancel any ongoing interactions
142140
{
143-
ruis::mouse_button_event mbe{
144-
button_action::release,
145-
[]() {
146-
using std::numeric_limits;
147-
148-
if constexpr (numeric_limits<ruis::real>::has_infinity) {
149-
return -numeric_limits<ruis::real>::infinity();
150-
} else {
151-
return numeric_limits<ruis::real>::min();
152-
}
153-
}(),
154-
mouse_button::left,
155-
this->cur_pointer_id
156-
};
157-
this->flickable_on_mouse_button(mbe);
141+
auto pos = []() {
142+
using std::numeric_limits;
143+
144+
if constexpr (numeric_limits<ruis::real>::has_infinity) {
145+
return -numeric_limits<ruis::real>::infinity();
146+
} else {
147+
return numeric_limits<ruis::real>::min();
148+
}
149+
}();
150+
151+
// move the cursor out of any widget to update hovered states
152+
this->flickable_on_mouse_move({
153+
.pos = pos,
154+
.pointer_id = this->cur_pointer_id
155+
});
156+
157+
this->flickable_on_mouse_button({
158+
.action = button_action::release,
159+
.pos = pos,
160+
.button = mouse_button::left,
161+
.pointer_id = this->cur_pointer_id
162+
});
158163
}
159164

160165
this->flickable_scroll_by(-delta);
@@ -164,7 +169,7 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
164169
case state::not_scrolling:
165170
// std::cout << "mouse move: not scrolling\n";
166171
return this->flickable_on_mouse_move(event);
167-
case state::scrolling:
172+
case state::dragging:
168173
{
169174
vec2 delta = event.pos - this->prev_touch_point;
170175
// std::cout << "mouse move: scrolling, delta: " << delta << "\n";

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class flickable :
4141
idle,
4242
within_scroll_threshold,
4343
not_scrolling,
44-
scrolling
44+
dragging,
45+
inertial_scrolling
4546
} cur_state = state::idle;
4647

4748
vec2 prev_touch_point;
@@ -62,6 +63,8 @@ class flickable :
6263

6364
ruis::vec2 calculate_touch_velocity_for_at_least_3_points_using_ols_method();
6465

66+
67+
6568
public:
6669
event_status on_mouse_button(const mouse_button_event& event) override;
6770
event_status on_mouse_move(const mouse_move_event& event) override;

src/ruis/widget/button/push_button.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ event_status push_button::on_mouse_button(const mouse_button_event& e)
5555
} else {
5656
if (this->is_pressed()) {
5757
if (this->pointer_id == e.pointer_id) {
58-
// check that released the same pointer which has pressed the button before
58+
// released the same pointer which has pressed the button before
59+
60+
std::cout << "push_button: released" << std::endl;
61+
5962
this->set_pressed(false);
6063
}
6164
}
@@ -66,7 +69,7 @@ event_status push_button::on_mouse_button(const mouse_button_event& e)
6669

6770
void push_button::on_hovered_change(unsigned pointer_id)
6871
{
69-
// TRACE(<< "push_button::on_hover_change(): enter" << std::endl)
72+
std::cout << "push_button::on_hover_change(): this->is_hovered(" << pointer_id << ") = " << this->is_hovered(pointer_id) << std::endl;
7073

7174
if (!this->is_hovered(pointer_id)) {
7275
if (this->is_pressed() && this->pointer_id == pointer_id) {

src/ruis/widget/container.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ void container::on_hovered_change(unsigned pointer_id)
262262
return;
263263
}
264264

265-
// un-hover all the children since container became un-hovered
265+
// the container has just became unhovered
266+
utki::assert([&](){return !this->is_hovered(pointer_id);}, SL);
267+
268+
// unhover all the children
266269
blocked_flag_guard blocked_guard(this->is_blocked);
267270
for (auto& w : this->children()) {
268271
w.get().set_hovered(false, pointer_id);

src/ruis/widget/group/scroll_area.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ void scroll_area::clamp_scroll_pos()
8383

8484
utki::assert(this->invisible_dims.is_positive_or_zero(), SL);
8585

86-
std::cout << "scroll_area::clamp_scroll_pos(): invisible_dims: " << this->invisible_dims << "\n";
87-
std::cout << "scroll_area::clamp_scroll_pos(): before clamping this->cur_scroll_pos: " << this->cur_scroll_pos
88-
<< "\n";
86+
// std::cout << "scroll_area::clamp_scroll_pos(): invisible_dims: " << this->invisible_dims << "\n";
87+
// std::cout << "scroll_area::clamp_scroll_pos(): before clamping this->cur_scroll_pos: " << this->cur_scroll_pos << "\n";
8988

9089
this->cur_scroll_pos =
9190
max(real(0), //
@@ -97,13 +96,13 @@ void scroll_area::set_scroll_pos(const vec2& new_scroll_pos)
9796
{
9897
using std::round;
9998

100-
std::cout << "sceoll_area::set_scroll_pos(): this->cur_scroll_pos: " << this->cur_scroll_pos << "\n";
99+
// std::cout << "sceoll_area::set_scroll_pos(): this->cur_scroll_pos: " << this->cur_scroll_pos << "\n";
101100

102101
this->cur_scroll_pos = round(new_scroll_pos);
103102

104103
this->clamp_scroll_pos();
105104

106-
std::cout << "sceoll_area::set_scroll_pos(): after clamping this->cur_scroll_pos: " << this->cur_scroll_pos << "\n";
105+
// std::cout << "sceoll_area::set_scroll_pos(): after clamping this->cur_scroll_pos: " << this->cur_scroll_pos << "\n";
107106

108107
this->update_scroll_factor();
109108

src/ruis/widget/widget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,10 @@ void widget::set_hovered(bool is_hovered, unsigned pointer_id)
442442
// TRACE(<< "widget::setHovered(): isHovered = " << isHovered << " this->name() = " << this->name() << std::endl)
443443

444444
if (is_hovered) {
445-
ASSERT(!this->is_hovered(pointer_id))
445+
utki::assert([&](){return !this->is_hovered(pointer_id);}, SL);
446446
this->hovered.insert(pointer_id);
447447
} else {
448-
ASSERT(this->is_hovered(pointer_id))
448+
utki::assert([&](){return this->is_hovered(pointer_id);}, SL);
449449
this->hovered.erase(pointer_id);
450450
}
451451

0 commit comments

Comments
 (0)