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
5
#include "
ftxui/component/mouse.hpp
"
6
7
namespace
ftxui
{
8
9
namespace
{
10
bool
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.
18
bool
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.
25
bool
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.
32
bool
Mouse::IsReleased
(
Button
btn)
const
{
33
return
!IsDown(
this
, btn) && (
previous
&& IsDown(
previous
, btn));
34
}
35
36
}
// namespace ftxui
mouse.hpp
ftxui
Definition:
animation.hpp:12
ftxui::Mouse::Button
Button
Definition:
mouse.hpp:12
ftxui::Mouse::Pressed
@ Pressed
Definition:
mouse.hpp:23
ftxui::Mouse::IsHeld
bool IsHeld(Button btn=Left) const
Definition:
mouse.cpp:25
ftxui::Mouse::previous
Mouse * previous
Definition:
mouse.hpp:47
ftxui::Mouse::IsPressed
bool IsPressed(Button btn=Left) const
Definition:
mouse.cpp:18
ftxui::Mouse::IsReleased
bool IsReleased(Button btn=Left) const
Definition:
mouse.cpp:32