Skip to content

Commit 483d4d8

Browse files
committed
some switch using enum
1 parent 50587da commit 483d4d8

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
128128
// std::cout << "touch move, vel = " << this->calculate_touch_velocity() << std::endl;
129129

130130
switch (this->cur_state) {
131-
case state::inertial_scrolling:
131+
using enum state;
132+
133+
case inertial_scrolling:
132134
// check for inertial_scrolling is done before the switch()
133135
[[fallthrough]];
134-
case state::idle:
136+
case idle:
135137
// check for idle is done before the switch()
136138
[[fallthrough]];
137139
default:
@@ -143,7 +145,7 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
143145
SL
144146
);
145147
return ruis::event_status::propagate;
146-
case state::within_scroll_threshold:
148+
case within_scroll_threshold:
147149
{
148150
if (this->flickable_on_mouse_move(event) == event_status::consumed) {
149151
this->cur_state = state::not_scrolling;
@@ -190,10 +192,10 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
190192
}
191193
}
192194
return event_status::consumed;
193-
case state::not_scrolling:
195+
case not_scrolling:
194196
// std::cout << "mouse move: not scrolling\n";
195197
return this->flickable_on_mouse_move(event);
196-
case state::dragging:
198+
case dragging:
197199
{
198200
vec2 delta = event.pos - this->prev_touch_point;
199201
// std::cout << "mouse move: scrolling, delta: " << delta << "\n";

tests/app/src/main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,18 @@ class application : public ruisapp::application{
212212
mouse_proxy->mouse_button_handler = [state, vl](ruis::mouse_proxy&,//
213213
const ruis::mouse_button_event& e){
214214
switch(e.button){
215-
case ruis::mouse_button::left:
215+
using enum ruis::mouse_button;
216+
217+
case left:
216218
state->is_left_button_pressed = (e.action == ruis::button_action::press);
217219
state->old_pos = e.pos;
218220
return ruis::event_status::consumed;
219-
case ruis::mouse_button::wheel_down:
221+
case wheel_down:
220222
if(auto l = vl.lock()){
221223
l->scroll_by(wheel_delta);
222224
}
223225
break;
224-
case ruis::mouse_button::wheel_up:
226+
case wheel_up:
225227
if(auto l = vl.lock()){
226228
l->scroll_by(-wheel_delta);
227229
}
@@ -290,19 +292,21 @@ class application : public ruisapp::application{
290292
) -> ruis::event_status {
291293
std::cout << "button = " << unsigned(e.button) << std::endl;
292294
switch(e.button){
293-
case ruis::mouse_button::left:
295+
using enum ruis::mouse_button;
296+
297+
case left:
294298
state->is_left_button_pressed = (e.action == ruis::button_action::press);
295299
state->old_pos = e.pos;
296300
return ruis::event_status::consumed;
297-
case ruis::mouse_button::wheel_left:
301+
case wheel_left:
298302
std::cout << "wheel_left" << std::endl;
299303
if(e.action == ruis::button_action::press){
300304
if(auto l = hl.lock()){
301305
l->scroll_by(-wheel_delta);
302306
}
303307
}
304308
break;
305-
case ruis::mouse_button::wheel_right:
309+
case wheel_right:
306310
std::cout << "wheel_right" << std::endl;
307311
if(e.action == ruis::button_action::press){
308312
if(auto l = hl.lock()){

tests/wire_area/src/wire_socket.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ std::array<ruis::vec2, 2> wire_socket::outlet_pos() const noexcept{
4949
ruis::vec2 dir;
5050
ruis::vec2 pos;
5151
switch(this->params.outlet_orientation){
52-
default:
53-
ASSERT(false)
54-
case orientation::bottom:
52+
using enum orientation;
53+
54+
case bottom:
5555
pos = this->rect().p + this->rect().d.comp_mul(ruis::vec2(0.5, 1));
5656
dir = ruis::vec2(0, 1);
5757
break;
58-
case orientation::left:
58+
case left:
5959
pos = this->rect().p + this->rect().d.comp_mul(ruis::vec2(0, 0.5));
6060
dir = ruis::vec2(-1, 0);
6161
break;
62-
case orientation::right:
62+
case right:
6363
pos = this->rect().p + this->rect().d.comp_mul(ruis::vec2(1, 0.5));
6464
dir = ruis::vec2(1, 0);
6565
break;
66-
case orientation::top:
66+
case top:
6767
pos = this->rect().p + this->rect().d.comp_mul(ruis::vec2(0.5, 0));
6868
dir = ruis::vec2(0, -1);
6969
break;

0 commit comments

Comments
 (0)