Re: Replace Gtk::manage() with std::unique_ptr<>?



On Mon, 2016-02-08 at 00:08 +0100, Murray Cumming wrote:
I think I'd be content with needing a call to a getter method after a
std::move(). I think that would make sense to people.

But, for simple setup code, to arrange widgets in their initial
working
state, it would be nice if our API didn't require this. At the moment
it's only necessary in a few places, and maybe we can improve them.

Currently, the worst part of the API for this, which has never felt
quite right, is this:

  auto cell = std::make_unique<Gtk::CellRendererText>();
  cell->property_style() = Pango::STYLE_ITALIC

  auto column = std::make_unique<Gtk::TreeViewColumn>("something",
cell);
  column->add_attribute(cell->property_text(), columns.title);
  column->add_attribute(cell->property_style_set(), columns.italic);

  m_TreeView.append_column(std::move(column));


The TreeViewColumn constructor does a pack_start(), which actually
takes the unique_ptr<>, so I hoped I could move that pack_start() to
later:

  auto cell = std::make_unique<Gtk::CellRendererText>();
  cell
->property_style() = Pango::STYLE_ITALIC

  auto column = std::make_unique<Gtk::TreeViewColumn>("something");
  column->add_attribute(cell->property_text(), columns.title);
  column->add_attribute(cell->property_style_set(), columns.italic);
  column->pack_start(std::move(cell));

  m_TreeView.append_column(std::move(column));

But that cell->add_attribute() really fails, in GTK+, if the Column doesn't contain a CellRenderer yet.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]