mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 15:38:21 +08:00
Capture mouse for the slider component.
This commit is contained in:
14
include/ftxui/component/captured_mouse.hpp
Normal file
14
include/ftxui/component/captured_mouse.hpp
Normal 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 */
|
@@ -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>;
|
||||
|
@@ -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_;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user