13
0

Tabbable overhaul: consistent toplevel packing

This commit is contained in:
Robin Gareus 2024-11-02 21:35:31 +01:00
parent 9f93f730c5
commit 8ca9e6bcdd
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 191 additions and 8 deletions

View File

@ -18,10 +18,12 @@
*/ */
#include <gtkmm/action.h> #include <gtkmm/action.h>
#include <gtkmm/frame.h>
#include <gtkmm/notebook.h> #include <gtkmm/notebook.h>
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <gtkmm/stock.h> #include <gtkmm/stock.h>
#include "gtkmm2ext/actions.h"
#include "gtkmm2ext/gtk_ui.h" #include "gtkmm2ext/gtk_ui.h"
#include "gtkmm2ext/utils.h" #include "gtkmm2ext/utils.h"
#include "gtkmm2ext/visibility_tracker.h" #include "gtkmm2ext/visibility_tracker.h"
@ -35,12 +37,13 @@ using namespace Gtk;
using namespace Gtkmm2ext; using namespace Gtkmm2ext;
using namespace ArdourWidgets; using namespace ArdourWidgets;
Tabbable::Tabbable (Widget& w, const string& visible_name, string const & nontranslatable_name, bool tabbed_by_default) Tabbable::Tabbable (Gtk::Widget& w, const string& visible_name, string const & nontranslatable_name, bool tabbed_by_default)
: WindowProxy (visible_name, nontranslatable_name) : WindowProxy (visible_name, nontranslatable_name)
, _contents (w) , _contents (w)
, _parent_notebook (0) , _parent_notebook (0)
, tab_requested_by_state (tabbed_by_default) , tab_requested_by_state (tabbed_by_default)
{ {
default_layout ();
} }
Tabbable::~Tabbable () Tabbable::~Tabbable ()
@ -51,6 +54,55 @@ Tabbable::~Tabbable ()
} }
} }
void
Tabbable::default_layout ()
{
left_attachment_button.set_text (_("Left"));
right_attachment_button.set_text (_("Right"));
bottom_attachment_button.set_text (_("Btm"));
content_attachment_hbox.set_border_width(3);
content_attachment_hbox.set_spacing(3);
content_attachment_hbox.pack_end (right_attachment_button, false, false);
content_attachment_hbox.pack_end (bottom_attachment_button, false, false);
content_attachment_hbox.pack_end (left_attachment_button, false, false);
content_attachments.add (content_attachment_hbox);
content_header_hbox.pack_start (content_app_bar, true, true);
content_header_hbox.pack_start (content_attachments, false, false);
content_header_hbox.pack_start (content_tabbables, false, false);
//wrap the header eboxen in a themeable frame
Gtk::Frame *toolbar_frame = manage(new Gtk::Frame);
toolbar_frame->set_name ("TransportFrame");
toolbar_frame->set_shadow_type (Gtk::SHADOW_NONE);
toolbar_frame->add (content_header_hbox);
_content_vbox.pack_start (*toolbar_frame, false, false);
_content_vbox.pack_start (content_hbox, true, true);
content_hbox.pack_start (content_att_left, false, false);
content_hbox.pack_start (content_midlevel_vbox, true, true);
content_midlevel_vbox.pack_start (content_right_pane, true, true);
content_midlevel_vbox.pack_start (content_att_bottom, false, false);
content_right_pane.add (content_inner_vbox);
content_right_pane.add (content_right_vbox);
//TODO: menu switcher here?
content_right_vbox.pack_start (content_att_right, true, true);
content_inner_vbox.pack_start (content_toolbar, false, false);
content_inner_vbox.pack_start (content_innermost_hbox, true, true);
content_right_pane.set_child_minsize (content_att_right, 160); /* rough guess at width of notebook tabs */
content_right_pane.set_check_divider_position (true);
content_right_pane.set_divider (0, 0.85);
_content_vbox.show_all();
}
void void
Tabbable::add_to_notebook (Notebook& notebook) Tabbable::add_to_notebook (Notebook& notebook)
{ {
@ -343,6 +395,8 @@ Tabbable::get_state() const
node.set_property (X_("tabbed"), tabbed()); node.set_property (X_("tabbed"), tabbed());
node.set_property (string_compose("%1%2", _menu_name, X_("-listpane-pos")).c_str(), content_right_pane.get_divider ());
return node; return node;
} }
@ -365,8 +419,14 @@ Tabbable::set_state (const XMLNode& node, int version)
if (window_node) { if (window_node) {
window_node->get_property (X_("tabbed"), tab_requested_by_state); window_node->get_property (X_("tabbed"), tab_requested_by_state);
float fract;
if ( window_node->get_property (string_compose("%1%2", _menu_name, X_("-listpane-pos")).c_str(), fract) ) {
fract = std::max (.05f, std::min (.95f, fract));
content_right_pane.set_divider (0, fract);
}
} }
if (!_visible) { if (!_visible) {
if (tab_requested_by_state) { if (tab_requested_by_state) {
attach (); attach ();
@ -391,3 +451,75 @@ Tabbable::window_unmapped ()
{ {
StateChange (*this); StateChange (*this);
} }
void
Tabbable::showhide_att_right (bool yn)
{
if (yn) {
content_right_vbox.show ();
} else {
content_right_vbox.hide ();
}
}
void
Tabbable::att_right_button_toggled ()
{
Glib::RefPtr<Gtk::Action> act = right_attachment_button.get_related_action();
if (act) {
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
if (tact) {
showhide_att_right (tact->get_active());
}
} else {
showhide_att_right (false);
}
}
void
Tabbable::showhide_att_left (bool yn)
{
if (yn) {
content_att_left.show ();
} else {
content_att_left.hide ();
}
}
void
Tabbable::att_left_button_toggled ()
{
Glib::RefPtr<Gtk::Action> act = left_attachment_button.get_related_action();
if (act) {
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
if (tact) {
showhide_att_left (tact->get_active());
}
} else {
showhide_att_left (false);
}
}
void
Tabbable::showhide_att_bottom (bool yn)
{
if (yn) {
content_att_bottom.show ();
} else {
content_att_bottom.hide ();
}
}
void
Tabbable::att_bottom_button_toggled ()
{
Glib::RefPtr<Gtk::Action> act = bottom_attachment_button.get_related_action();
if (act) {
Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
if (tact) {
showhide_att_bottom (tact->get_active());
}
} else {
showhide_att_bottom (false);
}
}

View File

@ -20,14 +20,18 @@
#ifndef _WIDGETS_TABBABLE_H_ #ifndef _WIDGETS_TABBABLE_H_
#define _WIDGETS_TABBABLE_H_ #define _WIDGETS_TABBABLE_H_
#include <gtkmm/bin.h>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/button.h> #include <gtkmm/button.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/image.h> #include <gtkmm/image.h>
#include <gtkmm/label.h> #include <gtkmm/label.h>
#include <gtkmm/notebook.h> #include <gtkmm/notebook.h>
#include "gtkmm2ext/window_proxy.h" #include "gtkmm2ext/window_proxy.h"
#include "widgets/ardour_button.h"
#include "widgets/eventboxext.h"
#include "widgets/pane.h"
#include "widgets/visibility.h" #include "widgets/visibility.h"
namespace Gtk { namespace Gtk {
@ -56,6 +60,12 @@ public:
Gtk::Widget& contents() const { return _contents; } Gtk::Widget& contents() const { return _contents; }
/* this is where ArdourUI packs the tab switchers
* (record/cues/edit/mix) into my toolbar area,
* in the case where I'm attached to the main window
*/
Gtk::EventBox& tab_btn_box () {return content_tabbables;}
Gtk::Window* get (bool create = false); Gtk::Window* get (bool create = false);
Gtk::Window* own_window () { return get (false); } Gtk::Window* own_window () { return get (false); }
virtual Gtk::Window* use_own_window (bool and_pack_it); virtual Gtk::Window* use_own_window (bool and_pack_it);
@ -68,7 +78,6 @@ public:
bool tabbed() const; bool tabbed() const;
bool tabbed_by_default () const; bool tabbed_by_default () const;
Gtk::Window* current_toplevel () const; Gtk::Window* current_toplevel () const;
Gtk::Notebook* tab_root_drop (); Gtk::Notebook* tab_root_drop ();
@ -80,23 +89,65 @@ public:
sigc::signal1<void,Tabbable&> StateChange; sigc::signal1<void,Tabbable&> StateChange;
void att_left_button_toggled();
void att_right_button_toggled();
void att_bottom_button_toggled();
protected: protected:
virtual void showhide_att_left (bool yn);
virtual void showhide_att_right (bool yn);
virtual void showhide_att_bottom (bool yn);
bool delete_event_handler (GdkEventAny *ev); bool delete_event_handler (GdkEventAny *ev);
sigc::signal1<void, bool> signal_tabbed_changed; sigc::signal1<void, bool> signal_tabbed_changed;
private: /* This is the heirarchy of a Tabbable's widget packing.
Gtk::Widget& _contents; * The end result is to provide 8(ish) event-boxen where the tab can put its contents
Gtk::Notebook _own_notebook; * Please maintain the indention here so the hierarchy is visible
Gtk::Notebook* _parent_notebook; */
bool tab_requested_by_state;
/* clang-format off */
/* _content_vbox * toplevel
* toolbar_frame * the frame is managed in the implementation */
Gtk::HBox content_header_hbox;
EventBoxExt content_app_bar; /* a placeholder for the transport bar, if you want one */
Gtk::EventBox content_attachments; /* a placeholder the (strip, list, props) visibility buttons for this tab */
Gtk::HBox content_attachment_hbox;
EventBoxExt content_tabbables; /* a placeholder for the tabbable switching buttons (used by ArdourUI) */
Gtk::HBox content_hbox;
EventBoxExt content_att_left; /* a placeholder for the mixer strip, if you want one */
Gtk::VBox content_midlevel_vbox;
HPane content_right_pane;
Gtk::VBox content_inner_vbox;
EventBoxExt content_toolbar; /* a placeholder for the content-specific toolbar, if you want one */
Gtk::HBox content_innermost_hbox; /* a placeholder for the innermost content (recorder, cues, editor, mixer) */
Gtk::VBox content_right_vbox;
EventBoxExt content_att_right; /* a placeholder for the sidebar list, if you want one */
EventBoxExt content_att_bottom; /* a placeholder for the property box, if you want one */
/* clang-format on */
/* visibility controls */
ArdourWidgets::ArdourButton left_attachment_button;
ArdourWidgets::ArdourButton right_attachment_button;
ArdourWidgets::ArdourButton bottom_attachment_button;
private:
void default_layout ();
void show_tab (); void show_tab ();
void hide_tab (); void hide_tab ();
bool tab_close_clicked (GdkEventButton*); bool tab_close_clicked (GdkEventButton*);
void show_own_window (bool and_pack_it); void show_own_window (bool and_pack_it);
void window_mapped (); void window_mapped ();
void window_unmapped (); void window_unmapped ();
Gtk::VBox _content_vbox; /* this is the root widget for a full-featured tabbable, which contains: */
Gtk::Widget& _contents; /* for most Tabbables this will be content_vbox; but rc_options, for example, does something different. */
Gtk::Notebook _own_notebook;
Gtk::Notebook* _parent_notebook;
bool tab_requested_by_state;
}; };
} /* end namespace */ } /* end namespace */