Add gtk101
This commit is contained in:
parent
2c6a9f2103
commit
e07328022a
|
@ -0,0 +1,30 @@
|
||||||
|
#A Simple Project Test
|
||||||
|
project('gtk101', 'cpp',
|
||||||
|
default_options : ['c_std=c17', 'cpp_std=c++17'])
|
||||||
|
|
||||||
|
#Initalize variants
|
||||||
|
# gnome=import('gnome')
|
||||||
|
|
||||||
|
#Compile Resource
|
||||||
|
# gresources = gnome.compile_resources(
|
||||||
|
# 'resources', 'res/gtk91.resource.xml',
|
||||||
|
# source_dir: 'res',
|
||||||
|
# c_name: 'resources'
|
||||||
|
# )
|
||||||
|
|
||||||
|
#The Gtkmm Library as a dependency
|
||||||
|
gtkdep = dependency('gtkmm-3.0')
|
||||||
|
|
||||||
|
#Additional include dirs
|
||||||
|
dir_include = include_directories('..')
|
||||||
|
|
||||||
|
#Use Different Build Opinions in windows and Linux
|
||||||
|
if host_machine.system() == 'windows'
|
||||||
|
win=import('windows')
|
||||||
|
icon_res=win.compile_resources('../icon.rc')
|
||||||
|
executable('gtk101', icon_res, 'src/main.cc', 'src/MyWin.cc', dependencies : gtkdep,
|
||||||
|
win_subsystem : 'windows', include_directories : dir_include)
|
||||||
|
else
|
||||||
|
executable('gtk101', 'src/main.cc', 'src/MyWin.cc', dependencies : gtkdep,
|
||||||
|
include_directories : dir_include)
|
||||||
|
endif
|
|
@ -0,0 +1,55 @@
|
||||||
|
#include "MyWin.hh"
|
||||||
|
|
||||||
|
MyWin::MyWin()
|
||||||
|
:main_box(Gtk::ORIENTATION_VERTICAL,5),
|
||||||
|
m_label("No Selection"),
|
||||||
|
btn_exit("Exit")
|
||||||
|
{
|
||||||
|
//Initalize window
|
||||||
|
set_icon_name("org.gtk.daleclack");
|
||||||
|
set_default_size(300,400);
|
||||||
|
|
||||||
|
//Add Widgets
|
||||||
|
scrolled.add(m_treeview);
|
||||||
|
scrolled.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
|
||||||
|
main_box.pack_start(scrolled);
|
||||||
|
main_box.pack_start(m_label,Gtk::PACK_SHRINK);
|
||||||
|
main_box.pack_start(btn_exit,Gtk::PACK_SHRINK);
|
||||||
|
add(main_box);
|
||||||
|
|
||||||
|
//Create and add model
|
||||||
|
ref_liststore=Gtk::ListStore::create(m_columns);
|
||||||
|
m_treeview.set_model(ref_liststore);
|
||||||
|
|
||||||
|
//Add Items
|
||||||
|
auto row=*(ref_liststore->append());
|
||||||
|
row[m_columns.m_col_id]=1;
|
||||||
|
row[m_columns.m_col_name]="Name1";
|
||||||
|
row[m_columns.m_col_number]="0000000";
|
||||||
|
|
||||||
|
row=*(ref_liststore->append());
|
||||||
|
row[m_columns.m_col_id]=2;
|
||||||
|
row[m_columns.m_col_name]="Name2";
|
||||||
|
row[m_columns.m_col_number]="0000001";
|
||||||
|
|
||||||
|
row=*(ref_liststore->append());
|
||||||
|
row[m_columns.m_col_id]=3;
|
||||||
|
row[m_columns.m_col_name]="Name3";
|
||||||
|
row[m_columns.m_col_number]="0000002";
|
||||||
|
|
||||||
|
m_treeview.append_column_editable("ID",m_columns.m_col_id);
|
||||||
|
m_treeview.append_column_editable("Name",m_columns.m_col_name);
|
||||||
|
m_treeview.append_column_editable("Number",m_columns.m_col_number);
|
||||||
|
|
||||||
|
selection=m_treeview.get_selection();
|
||||||
|
|
||||||
|
btn_exit.signal_clicked().connect(sigc::mem_fun(*this,&MyWin::hide));
|
||||||
|
selection->signal_changed().connect(sigc::mem_fun(*this,&MyWin::selection_changed));
|
||||||
|
|
||||||
|
show_all_children();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWin::selection_changed(){
|
||||||
|
auto model=*(selection->get_selected());
|
||||||
|
m_label.set_label(model[m_columns.m_col_name]);
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtkmm.h>
|
||||||
|
|
||||||
|
class MyWin : public Gtk::Window{
|
||||||
|
public:
|
||||||
|
MyWin();
|
||||||
|
private:
|
||||||
|
|
||||||
|
//Model Columns
|
||||||
|
class ModelColumns : public Gtk::TreeModelColumnRecord{
|
||||||
|
public:
|
||||||
|
ModelColumns()
|
||||||
|
{add(m_col_id); add(m_col_name); add(m_col_number);}
|
||||||
|
|
||||||
|
Gtk::TreeModelColumn<int> m_col_id;
|
||||||
|
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
|
||||||
|
Gtk::TreeModelColumn<Glib::ustring> m_col_number;
|
||||||
|
};
|
||||||
|
|
||||||
|
ModelColumns m_columns;
|
||||||
|
|
||||||
|
Glib::RefPtr<Gtk::ListStore> ref_liststore;
|
||||||
|
Glib::RefPtr<Gtk::TreeSelection> selection;
|
||||||
|
|
||||||
|
//Child Widgets
|
||||||
|
Gtk::TreeView m_treeview;
|
||||||
|
Gtk::Box main_box;
|
||||||
|
Gtk::ScrolledWindow scrolled;
|
||||||
|
Gtk::Label m_label;
|
||||||
|
Gtk::Button btn_exit;
|
||||||
|
|
||||||
|
//Signal Handlers
|
||||||
|
void selection_changed();
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "MyWin.hh"
|
||||||
|
|
||||||
|
int main(int argc,char **argv){
|
||||||
|
auto app=Gtk::Application::create(argc,argv,"org.gtk.daleclack");
|
||||||
|
MyWin window;
|
||||||
|
return app->run(window);
|
||||||
|
}
|
Loading…
Reference in New Issue