Browse Source

implement page close on tab label double click

CPP-GTK4
yggverse 4 months ago
parent
commit
a7bd2ae078
  1. 45
      src/app/browser/main/tab.cpp
  2. 10
      src/app/browser/main/tab.hpp

45
src/app/browser/main/tab.cpp

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
#include "tab.hpp"
#include "gtkmm/label.h"
using namespace app::browser::main;
@ -17,13 +16,36 @@ void Tab::append( @@ -17,13 +16,36 @@ void Tab::append(
bool open,
bool focus
) {
Gtk::Label * data = new Gtk::Label("data"); // @TODO
// Init new tab label
Gtk::Label * name = new Gtk::Label(
LABEL
);
// Setup label controller
auto controller = Gtk::GestureClick::create();
/* @TODO remove as default
controller->set_button(
GDK_BUTTON_PRIMARY
);*/
controller->signal_pressed().connect(
sigc::mem_fun(
* this,
& Tab::on_label_click
)
);
name->add_controller(
controller
);
// Init tab data container @TODO
Gtk::Label * data = new Gtk::Label("data");
append_page(
* data,
* new Gtk::Label(
LABEL
)
* name
);
set_tab_reorderable(
@ -40,3 +62,16 @@ void Tab::append( @@ -40,3 +62,16 @@ void Tab::append(
);
}
};
void Tab::on_label_click(
int n,
double x,
double y
) {
if (n == 2) // double click
{
remove_page(
get_current_page()
);
}
}

10
src/app/browser/main/tab.hpp

@ -2,12 +2,22 @@ @@ -2,12 +2,22 @@
#define APP_BROWSER_MAIN_TAB_H
#include <glibmm/i18n.h>
#include <gtkmm/gestureclick.h>
#include <gtkmm/label.h>
#include <gtkmm/notebook.h>
namespace app::browser::main
{
class Tab : public Gtk::Notebook
{
private:
void on_label_click(
int n,
double x,
double y
);
public:
const bool SCROLLABLE = true;

Loading…
Cancel
Save