mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-16 08:04:21 +08:00
Add mouse implementation of most components.
This commit is contained in:
@@ -25,6 +25,8 @@ class Button : public Component {
|
||||
// Component implementation.
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
private:
|
||||
Box box_;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -38,7 +38,11 @@ class CheckBox : public Component {
|
||||
bool OnEvent(Event) override;
|
||||
|
||||
private:
|
||||
bool OnMouseEvent(Event event);
|
||||
|
||||
int cursor_position = 0;
|
||||
Box box_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -36,6 +36,9 @@ class Container : public Component {
|
||||
|
||||
int selected_ = 0;
|
||||
int* selector_ = nullptr;
|
||||
|
||||
private:
|
||||
bool OnMouseEvent(Event event);
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -59,6 +59,7 @@ struct Event {
|
||||
bool is_character() const { return type_ == Type::Character;}
|
||||
wchar_t character() const { return character_; }
|
||||
|
||||
bool is_mouse() const;
|
||||
bool is_mouse_left_down() const { return type_ == Type::MouseLeftDown; }
|
||||
bool is_mouse_left_move() const { return type_ == Type::MouseLeftMove; }
|
||||
bool is_mouse_middle_down() const { return type_ == Type::MouseMiddleDown; }
|
||||
@@ -74,6 +75,8 @@ struct Event {
|
||||
|
||||
bool operator==(const Event& other) const { return input_ == other.input_; }
|
||||
|
||||
void MoveMouse(int dx, int dy);
|
||||
|
||||
//--- State section ----------------------------------------------------------
|
||||
private:
|
||||
enum class Type {
|
||||
|
@@ -31,6 +31,11 @@ class Menu : public Component {
|
||||
// Component implementation.
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
|
||||
private:
|
||||
bool OnMouseEvent(Event);
|
||||
|
||||
std::vector<Box> boxes_;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -39,7 +39,9 @@ class RadioBox : public Component {
|
||||
bool OnEvent(Event) override;
|
||||
|
||||
private:
|
||||
bool OnMouseEvent(Event event);
|
||||
int cursor_position = 0;
|
||||
std::vector<Box> boxes_;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -30,6 +30,10 @@ class Toggle : public Component {
|
||||
// Component implementation.
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
|
||||
private:
|
||||
bool OnMouseEvent(Event event);
|
||||
std::vector<Box> boxes_;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/screen/box.hpp"
|
||||
#include "ftxui/screen/color.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
|
||||
@@ -77,6 +78,9 @@ enum Direction { WIDTH, HEIGHT };
|
||||
enum Constraint { LESS_THAN, EQUAL, GREATER_THAN };
|
||||
Decorator size(Direction, Constraint, int value);
|
||||
|
||||
// --
|
||||
Decorator reflect(Box& box);
|
||||
|
||||
// --- Frame ---
|
||||
// A frame is a scrollable area. The internal area is potentially larger than
|
||||
// the external one. The internal area is scrolled in order to make visible the
|
||||
|
@@ -10,6 +10,7 @@ struct Box {
|
||||
int y_max;
|
||||
|
||||
static Box Intersection(Box a, Box b);
|
||||
bool Contain(int x, int y);
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
Reference in New Issue
Block a user