Hi, I decided to make new structure of GtkWidget's and also a function which will organise them in my order, it looks like:
Structures:
Code:
typedef struct{
std::string tytul,opis,typ;
short int godzina,minuta,p_godzina,p_minuta,dzien,miesiac,rok,ID,ilosc;
} Wydarzenie;
typedef struct{
std::string kawalek_opisu;
short int ID;
GtkWidget* Labels[5];
GtkWidget* Vbox;
GtkWidget* Hboxs[2];
GtkWidget* Event_Box;
} NowyWidget;
Function to create "new" widget:
Code:
NowyWidget nowy_widget_init(Wydarzenie wydarzenie)
{
std::string czas;
char bufor[3] = {0};
NowyWidget widget;
widget.Event_Box = gtk_event_box_new();
gtk_widget_set_events (widget.Event_Box, GDK_BUTTON_PRESS_MASK);
for (int i = 0; i < 2; ++i) widget.Hboxs[i] = gtk_hbox_new(FALSE,0);
widget.ID = wydarzenie.ID;
widget.kawalek_opisu.assign(wydarzenie.opis,0,20);
widget.kawalek_opisu += "...";
widget.Labels[0] = gtk_label_new(wydarzenie.tytul.c_str()); // Labels[0] tytul;
widget.Labels[1] = gtk_label_new(wydarzenie.typ.c_str()); //Labels [1] typ;
widget.Labels[2] = gtk_label_new(widget.kawalek_opisu.c_str());
itoa(wydarzenie.p_godzina,bufor,10);
czas = bufor;
czas += ":";
itoa(wydarzenie.p_minuta,bufor,10);
czas += bufor;
widget.Labels[3] = gtk_label_new(czas.c_str());
czas.clear();
itoa(wydarzenie.godzina,bufor,10);
czas = bufor;
czas += ":";
itoa(wydarzenie.minuta,bufor,10);
czas += bufor;
widget.Labels[4] = gtk_label_new(czas.c_str());
widget.ID = wydarzenie.ID;
widget.Vbox = gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(widget.Event_Box),widget.Vbox);
gtk_box_pack_start(GTK_BOX(widget.Vbox),widget.Hboxs[0],FALSE,FALSE,0);
gtk_box_pack_start(GTK_BOX(widget.Hboxs[0]),widget.Labels[0],FALSE,FALSE,0);
gtk_box_pack_end(GTK_BOX(widget.Hboxs[0]),widget.Labels[1],FALSE,FALSE,0);
gtk_box_pack_start(GTK_BOX(widget.Vbox),widget.Hboxs[1],FALSE,FALSE,0);
gtk_box_pack_start(GTK_BOX(widget.Hboxs[1]),widget.Labels[2],FALSE,FALSE,0);
gtk_box_pack_start(GTK_BOX(widget.Hboxs[1]),widget.Labels[3],FALSE,FALSE,0);
gtk_box_pack_end(GTK_BOX(widget.Hboxs[1]),widget.Labels[4],FALSE,FALSE,0);
return widget;
}
I also made a vector of this "new" widgets and use it like that in code:
std::vector<NowyWidget> zbior_widgetow;
Code:
Wydarzenie temp;
NowyWidget duzo;
temp.dzien = 1;
temp.godzina = 1;
temp.ID = 1;
temp.ilosc = 1;
temp.miesiac = 1;
temp.minuta = 1;
temp.opis = "test";
temp.p_godzina = 1;
temp.p_minuta = 1;
temp.rok = 1;
temp.typ = "TEST";
temp.tytul = "TESTING";
for (int i = 0; i < 10; ++i)
{
memset((void*)&duzo,0,sizeof(NowyWidget));
duzo = nowy_widget_init(temp);
zbior_widgetow.push_back(duzo);
}
for (unsigned i = 0; i < zbior_widgetow.size(); ++i) gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(Okno_przesuw),zbior_widgetow[i].Event_Box);
And GTK allows me to place only one widget, with the rest I get:
"gtk_scrolled_window_add_with_viewport : assertion 'GTK_BIN (bin->child)->child == NULL' FAILED, and it palces only the first one widget in window.
Any help needed