From 722036eab018d8cd57511a38b15d3fe9714ac244 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Fri, 12 Dec 2003 14:35:34 +0000 Subject: alignment --- src/Container.cc | 63 +++++++++++++++++++++++++++++++++++++++++--------------- src/Container.hh | 9 +++++++- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/Container.cc b/src/Container.cc index d3072a6..b6bc5b8 100644 --- a/src/Container.cc +++ b/src/Container.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Container.cc,v 1.8 2003/12/07 15:45:28 fluxgen Exp $ +// $Id: Container.cc,v 1.9 2003/12/12 14:35:34 fluxgen Exp $ #include "Container.hh" @@ -28,7 +28,10 @@ #include "FbTk/EventManager.hh" Container::Container(const FbTk::FbWindow &parent): - FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), m_selected(0), + FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), + m_align(RELATIVE), + m_max_size_per_client(60), + m_selected(0), m_update_lock(false) { FbTk::EventManager::instance()->add(*this, *this); } @@ -161,6 +164,14 @@ void Container::setSelected(int pos) { } +void Container::setMaxSizePerClient(unsigned int size) { + m_max_size_per_client = size; +} + +void Container::setAlignment(Container::Alignment a) { + m_align = a; +} + void Container::exposeEvent(XExposeEvent &event) { if (!m_update_lock) clearArea(event.x, event.y, event.width, event.height); @@ -182,15 +193,21 @@ void Container::repositionItems() { int next_x = -borderW; // zero so the border of the first shows int extra = 0; - for (; it != it_end; ++it, next_x += max_width_per_client + borderW + extra) { + int direction = 1; + if (alignment() == RIGHT) { + direction = -1; + next_x = width() - max_width_per_client + borderW; + } + + for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) { //!! TODO: check this more carefully, seems like error doesn't work with even numbers /* - if (rounding_error != 0) { - --rounding_error; - extra = 0; - } else { - extra = 0; - } + if (rounding_error != 0) { + --rounding_error; + extra = 0; + } else { + extra = 0; + } */ // resize each clients including border in size (*it)->moveResize(next_x, @@ -199,17 +216,29 @@ void Container::repositionItems() { height()); (*it)->clear(); } + } unsigned int Container::maxWidthPerClient() const { - int count = size(); - if (count == 0) - return width(); - else { - int borderW = m_item_list.front()->borderWidth(); - // there're count-1 borders to fit in with the windows - // -> 1 per window plus end - return (width() - (count - 1) * borderW) / count; + switch (alignment()) { + case RIGHT: + case LEFT: + return m_max_size_per_client; + break; + case RELATIVE: + int count = size(); + if (count == 0) + return width(); + else { + int borderW = m_item_list.front()->borderWidth(); + // there're count-1 borders to fit in with the windows + // -> 1 per window plus end + return (width() - (count - 1) * borderW) / count; + } + break; } + + // this will never happen anyway + return 1; } diff --git a/src/Container.hh b/src/Container.hh index 5f2ca4b..f620d3a 100644 --- a/src/Container.hh +++ b/src/Container.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Container.hh,v 1.3 2003/09/08 16:28:32 fluxgen Exp $ +// $Id: Container.hh,v 1.4 2003/12/12 14:35:34 fluxgen Exp $ #ifndef CONTAINER_HH #define CONTAINER_HH @@ -33,6 +33,7 @@ class Container:public FbTk::FbWindow, public FbTk::EventHandler, private FbTk::NotCopyable { public: + enum Alignment { LEFT, RELATIVE, RIGHT }; typedef FbTk::FbWindow * Item; typedef std::list ItemList; @@ -51,6 +52,9 @@ public: void removeAll(); int find(Item item); void setSelected(int index); + void setMaxSizePerClient(unsigned int size); + void setAlignment(Alignment a); + /// force update inline void update() { repositionItems(); } /// so we can add items without having an graphic update for each item @@ -60,6 +64,7 @@ public: void exposeEvent(XExposeEvent &event); /// accessors + inline Alignment alignment() const { return m_align; } inline int size() const { return m_item_list.size(); } inline const Item selected() const { return m_selected; } inline Item selected() { return m_selected; } @@ -70,6 +75,8 @@ public: private: void repositionItems(); + Alignment m_align; + unsigned int m_max_size_per_client; ItemList m_item_list; Item m_selected; bool m_update_lock; -- cgit v0.11.2