Thread overview
GtkD CRUD Application
IRe: GtkD CRUD Application
Oct 17
aberba
October 17
I've written the beginning but dont know how to end.
What is the way to add functionality for the add,edit,delete button ?
//==================================
import gtk.Button;
import gtk.Box;
import gtk.Label;
import gtk.Entry;
import gtk.Grid;
import gtk.Main;
import gtk.MainWindow;
import gtk.Widget;
import gdk.Event: Event;
import std.array: assocArray;
import std.conv: to;
import std.format : format;
import std.range: iota, retro, drop, zip;
import std.stdio: writeln;



struct nameage {
	string name;
	int age;
}

class Row: Box {
	ulong index;
	this(nameage anameage,ulong index){
		this.index=index;
		super(Orientation.HORIZONTAL,5);
	    this.packStart((new Label(anameage.name)),0,0,0);
	    this.packStart((new Label(to!string(anameage.age))),0,0,0);
	    this.packStart((new Button("Edit")),0,0,0);
	    this.packStart((new Button("Delete")),0,0,0);

	}
}

class MyWindow : MainWindow {
	
	Box vbox;
	nameage []mynameage;
	
	void quit(){
		this.quit();
	}

	void addclicked(){
	}

	this(int sizex,int sizey){
		nameage nameage1=nameage("Alain",20);
		nameage nameage2=nameage("Eddy",30);
		mynameage ~= nameage1;
		mynameage ~= nameage2;
		super("My Locate D-lang App");
		setSizeRequest(sizex,sizey);
		setHexpand(0);
		addOnDestroy(delegate void(Widget w) { quit(); } );
		vbox=new Box(Orientation.VERTICAL,5);
			foreach (ulong i,anameage;mynameage){
				Row arow=new Row(anameage,i);
				vbox.packStart(arow,0,0,0);
			}
			Button addbutton=new Button("Add");
			addbutton.addOnClicked(delegate void(Button b){addclicked();});
	        vbox.packStart(addbutton,0,0,0);

		add(vbox);
		showAll();
	}
}


int main(string[] args){
	int sizex=800;
	int sizey=600;
	Main.init(args);
	MyWindow window=new MyWindow(sizex,sizey);
	Main.run();
	return 0;
}
//==================================

October 17
On Saturday, 17 October 2020 at 14:53:35 UTC, Alaindevos wrote:
> I've written the beginning but dont know how to end.
> What is the way to add functionality for the add,edit,delete button ?
> //==================================
> import gtk.Button;
> import gtk.Box;
> import gtk.Label;
> import gtk.Entry;
> import gtk.Grid;
> import gtk.Main;
> import gtk.MainWindow;
> import gtk.Widget;
> import gdk.Event: Event;
> import std.array: assocArray;
> import std.conv: to;
> import std.format : format;
> import std.range: iota, retro, drop, zip;
> import std.stdio: writeln;
>
> [...]



I haven't used GTK in d myself in a long time. But gtkdcoding.com is s great place to see some code. You might want to start from the first post
October 17
On Saturday, 17 October 2020 at 14:53:35 UTC, Alaindevos wrote:
> I've written the beginning but dont know how to end.
> What is the way to add functionality for the add,edit,delete button ?
> //==================================

I put an example[1] here. The fields are not editable. You will have to implement it. I think you will get the idea to do that.

My example uses ListBox with a fake header as a bonus. You can use TreeView, but it is a complex widget.

[1] https://gist.github.com/aferust/47cb782b55cdab1f7775b7755bc50982