Capture mouse for the slider component.

This commit is contained in:
ArthurSonzogni
2021-05-01 18:13:56 +02:00
parent 0af8201023
commit eb399d20c5
15 changed files with 157 additions and 35 deletions

View File

@@ -0,0 +1,14 @@
#ifndef FTXUI_CAPTURED_MOUSE_HPP
#define FTXUI_CAPTURED_MOUSE_HPP
#include <memory>
namespace ftxui {
class CapturedMouseInterface {
public:
virtual ~CapturedMouseInterface() {}
};
using CapturedMouse = std::unique_ptr<CapturedMouseInterface>;
} // namespace ftxui
#endif /* end of include guard: FTXUI_CAPTURED_MOUSE_HPP */

View File

@@ -52,13 +52,13 @@ class Component {
// Configure all the ancestors to give focus to this component.
void TakeFocus();
protected:
std::vector<Component*> children_;
private:
Component* parent_ = nullptr;
void Detach();
void Attach(Component* parent);
protected:
std::vector<Component*> children_;
};
using ComponentPtr = std::unique_ptr<Component>;

View File

@@ -10,6 +10,8 @@
namespace ftxui {
class ScreenInteractive;
/// @brief Represent an event. It can be key press event, a terminal resize, or
/// more ...
///
@@ -65,6 +67,9 @@ struct Event {
const std::string& input() const { return input_; }
ScreenInteractive* screen() { return screen_; }
void SetScreen(ScreenInteractive* screen) { screen_ = screen; }
bool operator==(const Event& other) const { return input_ == other.input_; }
//--- State section ----------------------------------------------------------
@@ -88,6 +93,8 @@ struct Event {
struct Cursor cursor_;
};
std::string input_;
ScreenInteractive* screen_;
};

View File

@@ -9,6 +9,7 @@
#include <mutex>
#include <queue>
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/screen/screen.hpp"
@@ -27,6 +28,7 @@ class ScreenInteractive : public Screen {
std::function<void()> ExitLoopClosure();
void PostEvent(Event event);
CapturedMouse CaptureMouse();
private:
void Draw(Component* component);
@@ -55,6 +57,8 @@ class ScreenInteractive : public Screen {
int cursor_x_ = 0;
int cursor_y_ = 0;
bool mouse_captured = false;
};
} // namespace ftxui

View File

@@ -11,11 +11,14 @@ namespace ftxui {
// float max = 100.f,
// float increment = (max - min) * 0.05f);
template<class T> // T = {int, float}
ComponentPtr Slider(std::wstring label,
int* value,
int min,
int max,
int increment);
T* value,
T min,
T max,
T increment);
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_SLIDER_HPP */