FWDialogBuilder

FWLayoutBuilder

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
#ifndef Fireworks_Core_FWDialogBuilder_h
#define Fireworks_Core_FWDialogBuilder_h

#include "TGNumberEntry.h"

class TGCompositeFrame;
class TGLayoutHints;
class TGVerticalFrame;
class TGLabel;
class FWColorSelect;
class TGTextView;
class TGTextEntry;
class TGTextButton;
class TGHSlider;
class FWTableManagerBase;
class FWTableWidget;
class TGCheckButton;
class FWGUIValidatingTextEntry;
class TGTab;
class FWColorManager;
class TGTextEdit;
class TGHtml;

class FWLayoutBuilder {
protected:
  FWLayoutBuilder(TGCompositeFrame *window, bool expandY = true);
  FWLayoutBuilder &newRow();

  FWLayoutBuilder &indent(int left = 2, int right = -1);

  FWLayoutBuilder &unindent(void);
  TGCompositeFrame *currentFrame(void) { return m_currentFrame; }
  FWLayoutBuilder &floatLeft(size_t spacing);
  FWLayoutBuilder &spaceUp(size_t spacing);
  FWLayoutBuilder &spaceDown(size_t spacing);
  FWLayoutBuilder &spaceLeft(size_t spacing);
  FWLayoutBuilder &spaceRight(size_t spacing);
  FWLayoutBuilder &frameSpaceUp(size_t spacing);
  FWLayoutBuilder &frameSpaceDown(size_t spacing);
  FWLayoutBuilder &frameSpaceLeft(size_t spacing);
  FWLayoutBuilder &frameSpaceRight(size_t spacing);
  FWLayoutBuilder &expand(bool expandX = true, bool expandY = false);

  bool isFloatingLeft() { return m_floatLeft; }
  TGLayoutHints *nextHints();
  TGCompositeFrame *nextFrame();
  TGVerticalFrame *verticalFrame();
  void frameForTab();

private:
  TGCompositeFrame *m_window;

  std::vector<TGVerticalFrame *> m_framesStack;
  //  TGCompositeFrame *m_lastFrame;
  TGCompositeFrame *m_currentFrame;

  bool m_floatLeft;
  size_t m_topSpacing;
  size_t m_leftSpacing;
  TGLayoutHints *m_currentHints;
  TGLayoutHints *m_currentFrameHints;
};

/** Helper class to construct dialogs in a more readable ways.

    Encapsulated TGUI layout hiccups and exposes the developer an API which
    allows to layout items in a top->bottom, right->left manner.
    
    Example:
    
      FWDialogBuilder builder(parent);
      parent.newRow(2)              // New row which has a 2 pixel padding on top.
            .addLabel("MyLabel:")    // A new label.
            .indent(20)             // Whatever follows is indented 20 pixels 
                                    // on the right.
            .addLabel("MyLabel2")   // Another label.
            .spaceDown(4)
            .addTextButton("Aligned to MyLabel2 ").floatLeft()
            .addTextButton("Same Row as previous")
            .unindent()              // back one level in the indentation.
            .addLabel("Aligned to MyLabel:")
            
    Because in ROOT layout and parenting of widgets are mixed we need to take
    responsibility for creating the widget objects (sigh!), so we have one
    "addXYZ" method per widget that can be added. If we find our way around
    this it would be better to have a generic "addWidget()" method and create
    widgets outside this class.
    
    TODO: For higher configurability we should have an 
          "addWithCallback(Callbak)"  method which can be used to specify a 
          generic widget creation action.
  */
class FWDialogBuilder : public FWLayoutBuilder {
public:
  FWDialogBuilder(TGCompositeFrame *window, FWDialogBuilder *parent = nullptr, bool expandY = true);

  FWDialogBuilder &newRow();
  FWDialogBuilder &indent(int left = 2, int right = -1);
  FWDialogBuilder &unindent(void);

  FWDialogBuilder &addLabel(const char *text, size_t fontSize = 12, size_t weight = 0, TGLabel **out = nullptr);

  FWDialogBuilder &addTextView(const char *defaultText = nullptr, TGTextView **out = nullptr);

  // Is default text meaningful here as the html is
  // a document with structure?
  FWDialogBuilder &addHtml(TGHtml **out = nullptr);

  FWDialogBuilder &addTextEdit(const char *defaultText = nullptr, TGTextEdit **out = nullptr);
  FWDialogBuilder &addColorPicker(const FWColorManager *manager, FWColorSelect **out = nullptr);

  FWDialogBuilder &addHSlider(size_t size, TGHSlider **out = nullptr);

  FWDialogBuilder &addTextButton(const char *text, TGTextButton **out = nullptr);
  FWDialogBuilder &addValidatingTextEntry(const char *defaultText, FWGUIValidatingTextEntry **out);
  FWDialogBuilder &addTextEntry(const char *defaultText, TGTextEntry **out);
  FWDialogBuilder &addNumberEntry(
      float defaultValue, size_t digits, TGNumberFormat::EStyle style, int min, int max, TGNumberEntry **out);

  FWDialogBuilder &addCheckbox(const char *text, TGCheckButton **out = nullptr);
  FWDialogBuilder &addTable(FWTableManagerBase *manager, FWTableWidget **out = nullptr);

  FWDialogBuilder &addHSeparator(size_t horizontalPadding = 4, size_t verticalPadding = 3);

  FWDialogBuilder &tabs(TGTab **out);
  FWDialogBuilder &untabs(void);
  FWDialogBuilder &beginTab(const char *label);
  FWDialogBuilder &endTab(void);

  FWDialogBuilder &floatLeft(size_t spacing = 3);

  FWDialogBuilder &spaceUp(size_t spacing = 3);
  FWDialogBuilder &spaceDown(size_t spacing = 3);
  FWDialogBuilder &spaceUpDown(size_t spacing = 3);
  FWDialogBuilder &spaceLeft(size_t spacing = 3);
  FWDialogBuilder &spaceRight(size_t spacing = 3);
  FWDialogBuilder &spaceLeftRight(size_t spacing = 3);

  FWDialogBuilder &frameSpaceUp(size_t spacing = 3);
  FWDialogBuilder &frameSpaceDown(size_t spacing = 3);
  FWDialogBuilder &frameSpaceUpDown(size_t spacing = 3);
  FWDialogBuilder &frameSpaceLeft(size_t spacing = 3);
  FWDialogBuilder &frameSpaceRight(size_t spacing = 3);
  FWDialogBuilder &frameSpaceLeftRight(size_t spacing = 3);

  FWDialogBuilder &expand(size_t expandX = true, size_t expandY = false);
  FWDialogBuilder &vSpacer(size_t size = 0);
  FWDialogBuilder &hSpacer(size_t size = 0);

protected:
  template <class T>
  FWDialogBuilder &extract(T *in, T **out) {
    if (out)
      *out = in;
    return *this;
  }

private:
  FWDialogBuilder *m_parent;
  TGTab *m_tabs;
};

#endif