move new fractional pane utility functions into libs/gtkmm2ext

This commit is contained in:
Paul Davis 2016-04-22 22:53:39 -04:00
parent 02f2b90e96
commit a48fada3c7
3 changed files with 27 additions and 23 deletions

View file

@ -1861,25 +1861,6 @@ Mixer_UI::set_state (const XMLNode& node, int version)
return 0;
}
float
paned_position_as_fraction (Gtk::Paned& paned, bool h)
{
const guint pos = gtk_paned_get_position (const_cast<GtkPaned*>(static_cast<const Paned*>(&paned)->gobj()));
return (double) pos / (h ? paned.get_allocation().get_height() : paned.get_allocation().get_width());
}
void
gtk_paned_set_position_as_fraction (Gtk::Paned& paned, float fraction, bool h)
{
gint v = (h ? paned.get_allocation().get_height() : paned.get_allocation().get_width());
if (v < 1) {
return;
}
paned.set_position ((guint) floor (fraction * v));
}
XMLNode&
Mixer_UI::get_state ()
{
@ -1984,7 +1965,7 @@ Mixer_UI::pane_allocation_handler (Allocation& allocation, Gtk::Paned* which)
}
} else {
if ((done[0] = (allocation.get_height() > 1.0/pos))) {
gtk_paned_set_position_as_fraction (rhs_pane1, pos, true);
paned_set_position_as_fraction (rhs_pane1, pos, true);
}
}
}
@ -2007,7 +1988,7 @@ Mixer_UI::pane_allocation_handler (Allocation& allocation, Gtk::Paned* which)
}
} else {
if ((done[1] = (allocation.get_height() > 1.0/pos))) {
gtk_paned_set_position_as_fraction (rhs_pane2, pos, true);
paned_set_position_as_fraction (rhs_pane2, pos, true);
}
}
}
@ -2030,7 +2011,7 @@ Mixer_UI::pane_allocation_handler (Allocation& allocation, Gtk::Paned* which)
}
} else {
if ((done[2] = (allocation.get_width() > 1.0/pos))) {
gtk_paned_set_position_as_fraction (list_hpane, pos, false);
paned_set_position_as_fraction (list_hpane, pos, false);
}
}
}
@ -2053,7 +2034,7 @@ Mixer_UI::pane_allocation_handler (Allocation& allocation, Gtk::Paned* which)
}
} else {
if ((done[3] = (allocation.get_width() > 1.0/pos))) {
gtk_paned_set_position_as_fraction (inner_pane, pos, false);
paned_set_position_as_fraction (inner_pane, pos, false);
}
}
}

View file

@ -172,6 +172,9 @@ namespace Gtkmm2ext {
LIBGTKMM2EXT_API std::string markup_escape_text (std::string const& s);
LIBGTKMM2EXT_API void add_volume_shortcuts (Gtk::FileChooser& c);
LIBGTKMM2EXT_API float paned_position_as_fraction (Gtk::Paned& paned, bool h);
LIBGTKMM2EXT_API void paned_set_position_as_fraction (Gtk::Paned& paned, float fraction, bool h);
};
#endif /* __gtkmm2ext_utils_h__ */

View file

@ -992,3 +992,23 @@ Gtkmm2ext::add_volume_shortcuts (Gtk::FileChooser& c)
}
#endif
}
float
Gtkmm2ext::paned_position_as_fraction (Gtk::Paned& paned, bool h)
{
const guint pos = gtk_paned_get_position (const_cast<GtkPaned*>(static_cast<const Gtk::Paned*>(&paned)->gobj()));
return (double) pos / (h ? paned.get_allocation().get_height() : paned.get_allocation().get_width());
}
void
Gtkmm2ext::paned_set_position_as_fraction (Gtk::Paned& paned, float fraction, bool h)
{
gint v = (h ? paned.get_allocation().get_height() : paned.get_allocation().get_width());
if (v < 1) {
return;
}
paned.set_position ((guint) floor (fraction * v));
}