mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 23:48:15 +08:00
Improve mouse support for menu and toggle.
This commit is contained in:
@@ -36,6 +36,7 @@ struct Event {
|
||||
static Event MouseMiddleDown(std::string, int x, int y);
|
||||
static Event MouseRightMove(std::string, int x, int y);
|
||||
static Event MouseRightDown(std::string, int x, int y);
|
||||
static Event CursorReporting(std::string, int x, int y);
|
||||
|
||||
// --- Arrow ---
|
||||
static const Event ArrowLeft;
|
||||
@@ -68,6 +69,7 @@ struct Event {
|
||||
bool is_mouse_right_move() const { return type_ == Type::MouseRightMove; }
|
||||
bool is_mouse_up() const { return type_ == Type::MouseUp; }
|
||||
bool is_mouse_move() const { return type_ == Type::MouseMove; }
|
||||
bool is_cursor_reporting() const { return type_ == Type::CursorReporting; }
|
||||
int mouse_x() const { return mouse_.x; }
|
||||
int mouse_y() const { return mouse_.y; }
|
||||
|
||||
@@ -90,6 +92,7 @@ struct Event {
|
||||
MouseMiddleMove,
|
||||
MouseRightDown,
|
||||
MouseRightMove,
|
||||
CursorReporting,
|
||||
};
|
||||
|
||||
struct Mouse {
|
||||
|
@@ -19,10 +19,12 @@ class Menu : public Component {
|
||||
// State.
|
||||
std::vector<std::wstring> entries = {};
|
||||
int selected = 0;
|
||||
int focused = 0;
|
||||
|
||||
Decorator normal_style = nothing;
|
||||
Decorator focused_style = inverted;
|
||||
Decorator selected_style = bold;
|
||||
Decorator normal_style = nothing;
|
||||
Decorator selected_focused_style = focused_style | selected_style;
|
||||
|
||||
// State update callback.
|
||||
std::function<void()> on_change = []() {};
|
||||
|
@@ -52,6 +52,9 @@ class ScreenInteractive : public Screen {
|
||||
std::string reset_cursor_position;
|
||||
|
||||
std::atomic<bool> quit_ = false;
|
||||
|
||||
int cursor_x_ = 0;
|
||||
int cursor_y_ = 0;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -16,12 +16,14 @@ class Toggle : public Component {
|
||||
~Toggle() override = default;
|
||||
|
||||
// State.
|
||||
int selected = 0;
|
||||
std::vector<std::wstring> entries = {L"On", L"Off"};
|
||||
int selected = 0;
|
||||
int focused = 0;
|
||||
|
||||
Decorator normal_style = dim;
|
||||
Decorator focused_style = inverted;
|
||||
Decorator selected_style = bold;
|
||||
Decorator normal_style = dim;
|
||||
Decorator selected_focused_style = focused_style | selected_style;
|
||||
|
||||
// Callback.
|
||||
std::function<void()> on_change = []() {};
|
||||
|
Reference in New Issue
Block a user