guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gmenu.hpp
1 //
2 // Menu Gadgets
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef Guit_Menu_hpp
9 #define Guit_Menu_hpp
10 #include <gwindow.hpp>
11 namespace guit {
12 
14 class GMenu : public GBox {
15 protected:
16  GMenu(GadgetType&, GString const& css);
17 
18 public:
20  enum struct MenuPlacement {
21  BelowParent, AboveParent, BelowMouse, AroundMouse
22  };
23 
24  GMenu(GString const& css = "");
25  GMenu& clone(GClone const&) override;
26 
27  GMenu* toMenu() override {return this;}
28 
30  GMenu& show(bool state = true) override;
31 
33  virtual void show(GPoint const& pos, MenuPlacement = MenuPlacement::BelowMouse);
34 
35  virtual void show(GEvent&, bool autoplace);
36 
37  GPoint pos() const override {return GPoint(frame_.x, frame_.y);}
38  float x() const override {return frame_.x;}
39  float y() const override {return frame_.y;}
40 
41  bool isTopLevel() const override {return true;}
42  void setPseudoParent(Gadget* parent) {parent_ = parent;}
43  void setPlacement(MenuPlacement placement) {place_ = placement;}
44 
45  using GType = GadgetType_<GMenu,GBox>;
46  static GType& Type();
47  GType& type() const override {return Type();}
48 
51  Gadget& createDefaultItem(GString const& arg) override;
52  MenuPlacement place_{};
53  GPoint pos_;
55 };
56 
57 
59 GMenu& Menu(GString const& css = "");
60 
61 
62 
64 class GPieMenu : public GMenu {
65 protected:
66  GPieMenu(GadgetType&, GString const& css);
67 
68 public:
69  GPieMenu(GString const& css = "");
70  GPieMenu& clone(GClone const&) override;
71 
72  using GMenu::show;
73  void show(GEvent&, bool autoplace) override;
74 
76  static GType& Type();
77  GType& type() const override {return Type();}
78 };
79 
81 GPieMenu& PieMenu(GString const& css = "");
82 
83 }
84 #endif