Add mouse implementation of most components.

This commit is contained in:
ArthurSonzogni
2021-04-18 22:33:41 +02:00
parent d685a8655e
commit 890a41a64c
20 changed files with 239 additions and 12 deletions

View File

@@ -25,6 +25,8 @@ class Button : public Component {
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
private:
Box box_;
};
} // namespace ftxui

View File

@@ -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

View File

@@ -36,6 +36,9 @@ class Container : public Component {
int selected_ = 0;
int* selector_ = nullptr;
private:
bool OnMouseEvent(Event event);
};
} // namespace ftxui

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -10,6 +10,7 @@ struct Box {
int y_max;
static Box Intersection(Box a, Box b);
bool Contain(int x, int y);
};
} // namespace ftxui