Is it possible to Shrink a widget Horizontally and expand it Vertically
at the same time?  and vice versa, Shrink a widget Vertically and Expand it
Horizontally?

I was just wondering because i keep running into this problem with gtkmm
where I want a widget to expand horizontal and at the same time shrink to
the minimum width vertically...or vica versa... and all I have is a
Gtk::Frame container add() or Gtk::ListBoxRow to put the widget inside of.
Its like gtkmm is missing the concept of having opposite "springs" for
veritical and horizonal directions.  pushing outwards or pulling inwards
differently on vertical and horizonal directions. So far, I can only figure
out how to get gtkmm to having inner springs that pull inwards in both
veritical and horizonal directions at the same time, or outwards springs
that push outwards in both the veritical and horizonal directions at the
same time.  But not a mix of these two concepts in the same container.
There's the set_hexpand, and set_vexpand..  which don't seem to work the
way i think they should... maybe somebody has a better understanding of how
these work?

Here's a problem i was trying to figure out the other day:

http://stackoverflow.com/questions/41344241/gtkmm-c11-how-to-create-a-custom-composite-widget-out-of-other-widgets

Here's another example where I can't figure out how to strink the label
height of each row, while expanding to fill the scrollable window with the
entire listbox.


 //======================================================
// GTKMM3/C++11
//======================================================
#include <gtkmm.h>
#include <iostream>
#include <string>
#include <sstream>
#include <initializer_list>

using namespace std;

//======================================================
// List Row
//======================================================
class ListRow : public Gtk::ListBoxRow
{
public:
    ListRow(const string text) : c1{text} {
       add(hbox);
       hbox.pack_start(c1, Gtk::PackOptions::PACK_SHRINK);
       set_halign(Gtk::Align::ALIGN_START);
       set_vexpand(false);
       show_all_children();
    }
protected:
    Gtk::Label c1;
    Gtk::Box   hbox {Gtk::ORIENTATION_HORIZONTAL};
};


//======================================================
// List Box with scrollbars
//======================================================
class ListBoxScroll : public Gtk::ScrolledWindow {
  public:
    ListBoxScroll();
    ListBoxScroll(initializer_list<string> list);
    void api_AddRow(string line);
    void api_AddRows(vector<string>& lines);
    void api_Clear();

  protected:
    Gtk::Box      hbox {Gtk::ORIENTATION_HORIZONTAL};
    Gtk::ListBox  listbox;
};


//======================================================
// ListBoxScroll
//======================================================
inline ListBoxScroll::ListBoxScroll()
{
    add(hbox);
    hbox.pack_start(listbox, Gtk::PackOptions::PACK_EXPAND_WIDGET);
    show_all_children();
}

inline ListBoxScroll::ListBoxScroll(initializer_list<string> list) {
  for (auto s : list) {
    api_AddRow(s);
  }
}

inline void ListBoxScroll::api_Clear() {
  vector<Gtk::Widget*> children = listbox.get_children();
  for (Widget* w : children) {
    listbox.remove(*w);
    delete w;
  }
}

inline void ListBoxScroll::api_AddRow(string text)
{
    auto row = Gtk::manage(new ListRow{text});
    listbox.append(*row);
    row->show();
}

inline void ListBoxScroll::api_AddRows(vector<string>& lines) {
  for (string& L : lines) {
    api_AddRow(L);
  }
}


class WnViewer : public Gtk::Window {
  public:
    WnViewer();
    ~WnViewer();

  private:
    Gtk::Box          m_vbox       {Gtk::ORIENTATION_VERTICAL};
    Gtk::Box          m_box        {Gtk::ORIENTATION_HORIZONTAL};
    Gtk::Box          m_boxleft    {Gtk::ORIENTATION_VERTICAL};
    Gtk::Box          m_boxbtn     {Gtk::ORIENTATION_HORIZONTAL};
    Gtk::Button       m_btnClear   {"Clear"};
    Gtk::Button       m_btnRefresh {"Refresh"};
    ListBoxScroll     m_listbox;
    Gtk::TextView     m_textview;
};

inline WnViewer::WnViewer() {
  set_title("Viewer");
  set_border_width(6);
  set_default_size(600, 600);

  add(m_vbox);
  m_vbox.pack_start(m_boxbtn, Gtk::PackOptions::PACK_SHRINK);
  m_vbox.pack_start(m_box);
  m_boxbtn.pack_start(m_btnClear,   Gtk::PackOptions::PACK_SHRINK);
  m_boxbtn.pack_start(m_btnRefresh, Gtk::PackOptions::PACK_SHRINK);

  m_box     .pack_start(m_boxleft,  Gtk::PackOptions::PACK_SHRINK);
  m_box     .pack_start(m_textview, Gtk::PackOptions::PACK_EXPAND_WIDGET);
  m_boxleft .pack_start(m_listbox,  Gtk::PackOptions::PACK_EXPAND_WIDGET);
  m_listbox.set_size_request(200);


  for(int i=0; i < 30; i++) {
    stringstream x;
    x << "Testing " << i << "\n";
    m_listbox.api_AddRow(x.str().c_str());
  }

  auto lamba_clear = [&]() {
      m_listbox.api_Clear();
  };

  auto lamba_refresh = [&]() {
    for(int i=0; i < 30; i++) {
      stringstream x;
         x << "Testing " << i << "\n";
      m_listbox.api_AddRow(x.str().c_str());
    }
  };

  m_btnClear   .signal_clicked().connect(lamba_clear);
  m_btnRefresh .signal_clicked().connect(lamba_refresh);

  show_all_children();
}

inline WnViewer::~WnViewer() {

}

//======================================================
// Main
//======================================================
int main(int argc, char** argv) {
    auto appMain = Gtk::Application::create(argc, argv,
"org.gtkmm.example");
    WnViewer WnViewer1;
    appMain->run(WnViewer1);
    return 0;
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to