1
votes

I've been developing a cross-platform program with GTK and Glade as I've been used to only creating for windows applications. This question involves widgets (I believe that is what they are called) and how they can be 'added' to the main window. It's better explained with images as well.

I have a mainwindow which is like so:

Main Window

You can see the right side is intentionally left blank. This is because it will have dynamic content like player info, a minimap, inventory, etc. Here is one of the widgets I want to be included on the right side:

Player Info

It mostly has only basic information that will be added. Ignoring the whole main window and just focusing on the right portion, in coding I want it to display something like this:

Final Right Side Bar

The issue is, I don't fully understand if this is actually how you can do it, or I should actually code the right side bar directly into the client instead.. Or to code it dynamically from scratch *I.E. Crete the labels/etc at runtime rather then this PlayerInfo window.

I am curious onto what functions can do this and if someone can point me on the right direction to understanding this. I might be completely wrong to how this should be working.

I assume you need to add the widget with C# coding at creation though.

2
Also I've tried something like Widget newWidget = new Widget(builder.GetObject("PlayerInfo").Handle); Box test = builder.GetObject("boxDropDown"); test.Add(newWidget); Where boxDropDown is the right hand box where all the dropdown boxs will go, I.E. the player stats. I can test.show() to show it, but it's on it's own window instead. I assume I am missing something small here.Valleriani

2 Answers

2
votes

If I undestand correctly your question, you may consider to ceate the labels in building your interface directly in glade, have it "blank" or withount the number at the start (build/connect it at the creation as all the others widgets so it is sure that it will be inside your window) and then dinamically update the text (the whole text or only the value of the caratheristics) with the instruction

set_label (see here) for example I write in python (self. is the handler)

self.my_label_widget.set_label("STR: 26")

I am working in Python, I can't give you a C code but I think the base idea is the same.

1
votes

I just realized that

Widget newWidget = new Widget(builder.GetObject("PlayerInfo").Handle); 
Box test = builder.GetObject("boxDropDown");
test.Add(newWidget);

was correct in general, but in glade I don't define it as a window, I can actually have a separate widget as a box, grid, etc. and have it show. So this code does work.