Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_popup_window.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_POPUP_WINDOW_H
7 #define TB_POPUP_WINDOW_H
8 
9 #include "tb_window.h"
10 #include "tb_widgets_listener.h"
11 
12 namespace tb {
13 
20 {
21 public:
22  static const int UNSPECIFIED = TB_INVALID_DIMENSION;
23 
26  : pos_in_root(UNSPECIFIED, UNSPECIFIED)
27  , align(align)
28  , expand_to_target_width(true) {}
29 
31  TBPopupAlignment(const TBPoint &pos_in_root, TB_ALIGN align = TB_ALIGN_BOTTOM)
32  : pos_in_root(pos_in_root)
33  , align(align)
34  , expand_to_target_width(true) {}
35 
38  TBPopupAlignment(const TBPoint &pos_in_root, const TBPoint &pos_offset)
39  : pos_in_root(pos_in_root)
40  , pos_offset(pos_offset)
41  , align(TB_ALIGN_BOTTOM)
42  , expand_to_target_width(true) {}
43 
46  TBRect GetAlignedRect(TBWidget *popup, TBWidget *target) const;
47 
48  TBPoint pos_in_root;
49  TBPoint pos_offset;
50 
51  TB_ALIGN align;
55 };
56 
61 class TBPopupWindow : public TBWindow, private TBWidgetListener
62 {
63 public:
64  // For safe typecasting
65  TBOBJECT_SUBCLASS(TBPopupWindow, TBWindow);
66 
67  TBPopupWindow(TBWidget *target);
68  ~TBPopupWindow();
69 
70  bool Show(const TBPopupAlignment &alignment);
71 
72  virtual TBWidget *GetEventDestination() { return m_target.Get(); }
73 
74  virtual bool OnEvent(const TBWidgetEvent &ev);
75 private:
76  TBWidgetSafePointer m_target;
77  // TBWidgetListener
78  virtual void OnWidgetFocusChanged(TBWidget *widget, bool focused);
79  virtual bool OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev);
80  virtual void OnWidgetDelete(TBWidget *widget);
81  virtual bool OnWidgetDying(TBWidget *widget);
82 };
83 
84 } // namespace tb
85 
86 #endif // TB_POPUP_WINDOW_H
TBPopupAlignment describes the preferred alignment of a popup relative to a target widget or a given ...
Definition: tb_popup_window.h:19
The base TBWidget class.
Definition: tb_widgets.h:418
TBWidgetSafePointer keeps a pointer to a widget that will be set to nullptr if the widget is removed...
Definition: tb_widgets_listener.h:74
TBWidgetListener listens to some callbacks from TBWidget.
Definition: tb_widgets_listener.h:28
TBPopupAlignment(TB_ALIGN align=TB_ALIGN_BOTTOM)
Align relative to the target widget.
Definition: tb_popup_window.h:25
Definition: tb_widgets.h:112
TBPopupAlignment(const TBPoint &pos_in_root, const TBPoint &pos_offset)
Align relative to the given position (coordinates relative to the root widget).
Definition: tb_popup_window.h:38
TBWindow is a TBWidget that provides some window-like features.
Definition: tb_window.h:33
virtual TBWidget * GetEventDestination()
Get the widget that should receive the events this widget invoke.
Definition: tb_popup_window.h:72
Simple point class.
Definition: tb_geometry.h:15
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_popup_window.cpp:117
TBPopupAlignment(const TBPoint &pos_in_root, TB_ALIGN align=TB_ALIGN_BOTTOM)
Align relative to the given position (coordinates relative to the root widget).
Definition: tb_popup_window.h:31
TBWidget * Get() const
Return the widget, or nullptr if it has been deleted.
Definition: tb_widgets_listener.h:85
TB_ALIGN
Definition: tb_widgets.h:29
Align to the bottom (below)
Definition: tb_widgets.h:33
Simple rectangle class.
Definition: tb_geometry.h:25
TBRect GetAlignedRect(TBWidget *popup, TBWidget *target) const
Calculate a good rect for the given popup window using its preferred size and the preferred alignment...
Definition: tb_popup_window.cpp:13
TBPopupWindow is a popup window that redirects any child widgets events through the given target...
Definition: tb_popup_window.h:61
bool expand_to_target_width
If true, the width of the popup will be at least the same as the target widget if the alignment is TB...
Definition: tb_popup_window.h:54