FTXUI  5.0.0
C++ functional terminal UI.
mouse.cpp
Go to the documentation of this file.
1// Copyright 2023 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4
6
7namespace ftxui {
8
9namespace {
10bool IsDown(const Mouse* mouse, Mouse::Button btn) {
11 return mouse->button == btn && mouse->motion == Mouse::Pressed;
12}
13} // namespace
14
15/// Return whether the mouse transitionned from released to pressed.
16/// This is useful to detect a click.
17/// @arg btn The button to check.
18bool Mouse::IsPressed(Button btn) const {
19 return IsDown(this, btn) && (!previous || !IsDown(previous, btn));
20}
21
22/// Return whether the mouse is currently held.
23/// This is useful to detect a drag.
24/// @arg btn The button to check.
25bool Mouse::IsHeld(Button btn) const {
26 return IsDown(this, btn) && previous && IsDown(previous, btn);
27}
28
29/// Return whether the mouse transitionned from pressed to released.
30/// This is useful to detect a click.
31/// @arg btn The button to check.
32bool Mouse::IsReleased(Button btn) const {
33 return !IsDown(this, btn) && (previous && IsDown(previous, btn));
34}
35
36} // namespace ftxui
bool IsHeld(Button btn=Left) const
Definition: mouse.cpp:25
Mouse * previous
Definition: mouse.hpp:47
bool IsPressed(Button btn=Left) const
Definition: mouse.cpp:18
bool IsReleased(Button btn=Left) const
Definition: mouse.cpp:32