Skip to content

Commit

Permalink
Update the MultiCellRenderer demo.
Browse files Browse the repository at this point in the history
There is still an GTK error when editing a cell, not sure if it's caused by code in this demo.
  • Loading branch information
MikeWey committed Mar 1, 2021
1 parent 15339b1 commit 12989bb
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 152 deletions.
187 changes: 87 additions & 100 deletions demos/gtkD/DemoMultiCellRenderer/DemoMultiCellRenderer.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
*****************************************************************************/
module DemoMultiCellRenderer;

import gtk.Main;
import gtk.Application;
import gtk.ApplicationWindow;
import gdk.Event;
import gtk.Window;
import gtk.Widget;
Expand All @@ -51,116 +52,102 @@ import gtk.CellRendererToggle;
import gtk.ListStore;

import gdk.RGBA;
import gdk.Color;

import pango.PgFontDescription;
import std.stdio;
import gobject.Value;

enum {
COLUMN_NAME,
COLUMN_TEXT,
COLUMN_TEXT_VISIBLE,
COLUMN_BOOL,
COLUMN_BOOL_VISIBLE,
COLUMN_TEXT_COLOR,
COLUMN_TEXT_COLOR_RGBA,
COLUMN_TEXT_FONT_DESCRIPTION,
}

void main(string[] args){
Main.init(args);
ListStore store = new ListStore( [
GType.STRING,
GType.STRING,
GType.INT,
GType.INT,
GType.INT,
Color.getType(),
RGBA.getType(),
PgFontDescription.getType(),
] );

void appendRecord( string name, string value, bool isBoolean, RGBA rgba, Color color ){
auto it = store.createIter();
store.setValue( it, COLUMN_NAME, name );
store.setValue( it, COLUMN_TEXT, value );
store.setValue( it, COLUMN_TEXT_VISIBLE, !isBoolean );
store.setValue( it, COLUMN_BOOL, value == "true" );
store.setValue( it, COLUMN_BOOL_VISIBLE, isBoolean );
store.setValue( it, COLUMN_TEXT_COLOR_RGBA, rgba );
store.setValue( it, COLUMN_TEXT_COLOR, color );
store.setValue( it, COLUMN_TEXT_FONT_DESCRIPTION, new PgFontDescription() );
class DemoMultiCellRenderer : ApplicationWindow
{
this(Application application)
{
super(application);
setTitle("Celleditor Demo");

ListStore store = new ListStore( [
GType.STRING,
GType.STRING,
GType.INT,
GType.INT,
GType.INT,
RGBA.getType(),
] );

void appendRecord( string name, string value, bool isBoolean, RGBA rgba){
auto it = store.createIter();
store.setValue( it, COLUMN_NAME, name );
store.setValue( it, COLUMN_TEXT, value );
store.setValue( it, COLUMN_TEXT_VISIBLE, !isBoolean );
store.setValue( it, COLUMN_BOOL, value == "true" );
store.setValue( it, COLUMN_BOOL_VISIBLE, isBoolean );
store.setValue( it, COLUMN_TEXT_COLOR_RGBA, rgba );
}
// fill store with data
appendRecord( "Loops", "10", false, new RGBA(1.0,0.0,0.0,1.0) );
appendRecord( "Name", "keinfarbton", false, new RGBA(0.0,1.0,0.0,1.0) );
appendRecord( "Verbose", "true", true, new RGBA(0.0,0.0,1.0,1.0) );

auto tv = new TreeView();
setChild(tv);

// create first column with text renderer
TreeViewColumn column = new TreeViewColumn();
column.setTitle( "Name" );
tv.appendColumn(column);

CellRendererText cell_text = new CellRendererText();
column.packStart(cell_text, 0 );
column.addAttribute(cell_text, "text", COLUMN_NAME);
column.addAttribute(cell_text, "foreground-rgba", COLUMN_TEXT_COLOR_RGBA);

// create second column with two renderers
column = new TreeViewColumn();
column.setTitle( "Value" );
tv.appendColumn(column);

CellRendererToggle cell_bool = new CellRendererToggle();
column.packStart(cell_bool, 0 );
column.addAttribute(cell_bool, "active", COLUMN_BOOL);
column.addAttribute(cell_bool, "visible", COLUMN_BOOL_VISIBLE);

cell_text = new CellRendererText();
column.packStart(cell_text, 0 );
column.addAttribute(cell_text, "text", COLUMN_TEXT);
column.addAttribute(cell_text, "visible", COLUMN_TEXT_VISIBLE);
cell_text.setProperty( "editable", 1 );

// change value in store on toggle event
cell_bool.addOnToggled( delegate void(string p, CellRendererToggle){
auto path = new TreePath( p );
TreeIter it;
store.getIter(it, path);
store.setValue(it, COLUMN_BOOL, store.getValue!int(it, COLUMN_BOOL) ? 0 : 1 );
});

// change the text in the store on end of edit
cell_text.addOnEdited( delegate void(string p, string v, CellRendererText cell ){
auto path = new TreePath( p );
TreeIter it;
store.getIter(it, path);
store.setValue( it, COLUMN_TEXT, v );
});

tv.setModel(store);
show();
}
// fill store with data
appendRecord( "Loops", "10", false, new RGBA(1.0,0.0,0.0,1.0), new Color(64,64,64) );
appendRecord( "Name", "keinfarbton", false, new RGBA(0.0,1.0,0.0,1.0), new Color(127,127,127) );
appendRecord( "Verbose", "true", true, new RGBA(0.0,0.0,1.0,1.0), new Color(200,200,200) );

auto wnd = new Window( "Celleditor Demo" );
auto tv = new TreeView();
wnd.add(tv);

// create first column with text renderer
TreeViewColumn column = new TreeViewColumn();
column.setTitle( "Name" );
tv.appendColumn(column);

CellRendererText cell_text = new CellRendererText();
column.packStart(cell_text, 0 );
column.addAttribute(cell_text, "text", COLUMN_NAME);
column.addAttribute(cell_text, "background-gdk", COLUMN_TEXT_COLOR);
column.addAttribute(cell_text, "foreground-rgba", COLUMN_TEXT_COLOR_RGBA);

// create second column with two renderers
column = new TreeViewColumn();
column.setTitle( "Value" );
tv.appendColumn(column);

CellRendererToggle cell_bool = new CellRendererToggle();
column.packStart(cell_bool, 0 );
column.addAttribute(cell_bool, "active", COLUMN_BOOL);
column.addAttribute(cell_bool, "visible", COLUMN_BOOL_VISIBLE);

cell_text = new CellRendererText();
column.packStart(cell_text, 0 );
column.addAttribute(cell_text, "text", COLUMN_TEXT);
column.addAttribute(cell_text, "visible", COLUMN_TEXT_VISIBLE);
cell_text.setProperty( "editable", 1 );

// change value in store on toggle event
cell_bool.addOnToggled( delegate void(string p, CellRendererToggle){
auto path = new TreePath( p );
auto it = new TreeIter( store, path );
store.setValue(it, COLUMN_BOOL, it.getValueInt( COLUMN_BOOL ) ? 0 : 1 );

auto val = store.getValue(it, COLUMN_TEXT_FONT_DESCRIPTION);

import gobject.Type;

writeln(Type.isA(PgFontDescription.getType(), GType.BOXED));
writeln(PgFontDescription.getType(), " ", val.gType);

auto font = val.get!PgFontDescription();

writeln(font.getFamily());
});

// change the text in the store on end of edit
cell_text.addOnEdited( delegate void(string p, string v, CellRendererText cell ){
auto path = new TreePath( p );
auto it = new TreeIter( store, path );
store.setValue( it, COLUMN_TEXT, v );
});

tv.setModel(store);
wnd.showAll();

wnd.addOnDelete( delegate bool (Event event, Widget widget) {
widget.destroy();
Main.quit();
return false;
});

Main.run();
}


int main(string[] args)
{
auto application = new Application("org.gtkd.demo.multicellrenderer", GApplicationFlags.FLAGS_NONE);
application.addOnActivate(delegate void(_) { new DemoMultiCellRenderer(application); });
return application.run(args);
}
26 changes: 26 additions & 0 deletions generated/gtkd/gdk/RGBA.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ public final class RGBA
gdk_rgba_free(gdkRGBA);
}

/**
* Creates a new RGBA Color
*/
this()
{
GdkRGBA rgba = GdkRGBA(0, 0, 0, 0);

this(gdk_rgba_copy(&rgba), true);
}

/** ditto */
this(double red, double green, double blue, double alpha = 1.0)
{
GdkRGBA rgba;

rgba.red = red;
rgba.green = green;
rgba.blue = blue;
rgba.alpha = alpha;

this(gdk_rgba_copy(&rgba), true);
}


/**
*/

/**
* The intensity of the red channel from 0.0 to 1.0 inclusive
Expand Down
48 changes: 24 additions & 24 deletions generated/gtkd/gtk/Dialog.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,30 @@ private import std.algorithm;


/**
* Dialog boxes are a convenient way to prompt the user for a small amount
* Dialogs are a convenient way to prompt the user for a small amount
* of input, e.g. to display a message, ask a question, or anything else
* that does not require extensive effort on the user’s part.
*
* GTK treats a dialog as a window split vertically. The top section is a
* #GtkBox, and is where widgets such as a #GtkLabel or a #GtkEntry should
* be packed. The bottom area is known as the
* “action area”. This is generally used for
* packing buttons into the dialog which may perform functions such as
* cancel, ok, or apply.
* The main area of a GtkDialog is called the "content area", and is yours
* to populate with widgets such a #GtkLabel or #GtkEntry, to present
* your information, questions, or tasks to the user. In addition, dialogs
* allow you to add "action widgets". Most commonly, action widgets are
* buttons. Depending on the platform, action widgets may be presented
* in the header bar at the top of the window, or at the bottom of the window.
* To add action widgets, use GtkDialog using gtk_dialog_new_with_buttons(),
* gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
* gtk_dialog_add_action_widget().
*
* Clicking a button that was added as an action widget will emit the
* #GtkDialog::response signal with a response ID that you specified.
* GTK will never assign a meaning to positive response IDs; these are
* entirely user-defined. But for convenience, you can use the response
* IDs in the #GtkResponseType enumeration (these all have values less
* than zero). If a dialog receives a delete event, the
* #GtkDialog::response signal will be emitted with the
* #GTK_RESPONSE_DELETE_EVENT response ID.
*
* #GtkDialog boxes are created with a call to gtk_dialog_new() or
* Dialogs are created with a call to gtk_dialog_new() or
* gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is
* recommended; it allows you to set the dialog title, some convenient
* flags, and add simple buttons.
Expand All @@ -60,20 +72,9 @@ private import std.algorithm;
* gtk_dialog_new() into a #GtkWindow. When using gtk_dialog_new_with_buttons()
* you can also pass the #GTK_DIALOG_MODAL flag to make a dialog modal.
*
* If you add buttons to #GtkDialog using gtk_dialog_new_with_buttons(),
* gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
* gtk_dialog_add_action_widget(), clicking the button will emit a signal
* called #GtkDialog::response with a response ID that you specified. GTK
* will never assign a meaning to positive response IDs; these are entirely
* user-defined. But for convenience, you can use the response IDs in the
* #GtkResponseType enumeration (these all have values less than zero). If
* a dialog receives a delete event, the #GtkDialog::response signal will
* be emitted with a response ID of #GTK_RESPONSE_DELETE_EVENT.
*
* For the simple dialog in the following example, in reality you’d probably
* use #GtkMessageDialog to save yourself some effort. But you’d need to
* create the dialog contents manually if you had more than a simple message
* in the dialog.
* For the simple dialog in the following example, a #GtkMessageDialog would
* save some effort. But you’d need to create the dialog contents manually if
* you had more than a simple message in the dialog.
*
* An example for simple GtkDialog usage:
* |[<!-- language="C" -->
Expand Down Expand Up @@ -112,8 +113,7 @@ private import std.algorithm;
* # GtkDialog as GtkBuildable
*
* The GtkDialog implementation of the #GtkBuildable interface exposes the
* @content_area and @action_area as internal children with the names
* “content_area” and “action_area”.
* @content_area as an internal child with the name “content_area”.
*
* GtkDialog supports a custom <action-widgets> element, which can contain
* multiple <action-widget> elements. The “response” attribute specifies a
Expand Down
1 change: 0 additions & 1 deletion generated/gtkd/gtk/Entry.d
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,6 @@ public class Entry : Widget, CellEditableIF, EditableIF
*
* This is equivalent to getting @entry's #GtkEntryBuffer and
* calling gtk_entry_buffer_set_max_length() on it.
* ]|
*
* Params:
* max = the maximum length of the entry, or 0 for no maximum.
Expand Down
5 changes: 5 additions & 0 deletions generated/gtkd/gtk/FileChooserNative.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public import gtk.c.types;
* Showing, hiding and running the dialog is handled by the #GtkNativeDialog
* functions.
*
* Note that unlike #GtkFileChooserDialog, #GtkFileChooserNative objects are
* not toplevel widgets, and GTK does not keep them alive. It is your
* responsibility to keep a reference until you are done with the
* object.
*
* ## Typical usage ## {#gtkfilechoosernative-typical-usage}
*
* In the simplest of cases, you can the following code to use
Expand Down
20 changes: 20 additions & 0 deletions generated/gtkd/gtk/ListStore.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ public class ListStore : ObjectG, BuildableIF, TreeDragDestIF, TreeDragSourceIF,
// add the TreeSortable capabilities
mixin TreeSortableT!(GtkListStore);

/**
* Creates a top level iteractor.
* I don't think lists have but the top level iteractor
*/
TreeIter createIter()
{
GtkTreeIter* iter = new GtkTreeIter;
gtk_list_store_append(getListStoreStruct(), iter);
return new TreeIter(iter);
}

/** */
void setValue(TYPE)(TreeIter iter, int column, TYPE value)
{
Value v = new Value(value);
gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct());
}

/**
*/

/** */
public static GType getType()
Expand Down
5 changes: 5 additions & 0 deletions generated/gtkd/gtk/NativeDialog.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ private import std.algorithm;
* various common properties on the dialog, as well as show and hide
* it and get a #GtkNativeDialog::response signal when the user finished
* with the dialog.
*
* Note that unlike #GtkDialog, #GtkNativeDialog objects are not
* toplevel widgets, and GTK does not keep them alive. It is your
* responsibility to keep a reference until you are done with the
* object.
*/
public class NativeDialog : ObjectG
{
Expand Down
2 changes: 1 addition & 1 deletion generated/gtkd/gtk/PopoverMenu.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public import gtk.c.types;
* `<link name="section">`, you can use `<submenu>` or `<section>`
* elements.
*
* |[<!--language: xml -->
* |[<!-- language="xml" -->
* <menu id='app-menu'>
* <section>
* <item>
Expand Down
Loading

0 comments on commit 12989bb

Please sign in to comment.