Re: GtkD: New widget

2017-08-22 Thread Mike Wey via Digitalmars-d-learn

On 22-08-17 01:38, Johnson wrote:

On Monday, 21 August 2017 at 20:54:04 UTC, Mike Wey wrote:

On 21-08-17 03:45, Johnson Jones wrote:

[...]


If you want gtk to know about the functions you override you could use 
gtkd.Implement.ImplementCLass.


[...]


Thanks, I'll test it out when I get a chance. I was able to work around 
the issue for now but I imagine I'll need the ability to implement my 
own container in the future.


BTW, when I try to create a value I get an error about opCall

Value handleSize = new Value(0);

vs

Value handleSize = Value(0);

I'd rather not create a value on the heap when I only need it locally.

Could you add a way to create the value with the right type to Value?

Even static constructors would work(probably could templatize it).

Although, I'm not sure how much it matters since value itself seems to 
allocate on the heap ;/


 public this()
 {
 this(new GValue);
 }

But it might help reduce some memory waste.



`Value` is a class so you will need to use `new`.

--
Mike Wey


Re: GtkD: New widget

2017-08-21 Thread Johnson via Digitalmars-d-learn

On Monday, 21 August 2017 at 20:54:04 UTC, Mike Wey wrote:

On 21-08-17 03:45, Johnson Jones wrote:

[...]


If you want gtk to know about the functions you override you 
could use gtkd.Implement.ImplementCLass.


[...]


Thanks, I'll test it out when I get a chance. I was able to work 
around the issue for now but I imagine I'll need the ability to 
implement my own container in the future.


BTW, when I try to create a value I get an error about opCall

Value handleSize = new Value(0);

vs

Value handleSize = Value(0);

I'd rather not create a value on the heap when I only need it 
locally.


Could you add a way to create the value with the right type to 
Value?


Even static constructors would work(probably could templatize it).

Although, I'm not sure how much it matters since value itself 
seems to allocate on the heap ;/


public this()
{
this(new GValue);
}

But it might help reduce some memory waste.



Re: GtkD: New widget

2017-08-21 Thread Mike Wey via Digitalmars-d-learn

On 21-08-17 03:45, Johnson Jones wrote:

Hey Mike, I bet you can answer this!

I'd like to extend a widget to add some functionality.

class MyBox : Box
{
 protected GtkBox* gtkBox;

 import std.typecons;
 _gtk.Box Wrapped;
 mixin Proxy!Wrapped;

 public this(Box b)
 {
 this.gtkBox = b.getBoxStruct();
 super(gtkBox, false);
 }

}

Trying something like the above does extend the box, as far as allowing 
one to replace it, I think(using the code);


auto b = new MyBox(W1);
auto p = W1.getParent();
auto c = cast(Box)W4;
c.remove(W1);
c.add(b);

So, W4 is the main boxx, W1 is the box inside the main box I replaced 
with the new box b.


When running that code, nothing changes, which, assuming we are actually 
using the new box, then that is fine.


But I'm pretty sure that gtk never has a clue about `MyBox`? I say this 
because I'd like to simply modify the reported sizes of the box.


A gtkBox is not the same as a gtk.Box.

It seems like the best I can do is use a gtk.Container and inherit from 
that.



e.g.,

class FixableSizedBox : Container
{
 protected GtkContainer* gtkContainer;

 import std.typecons;
 _gtk.Container Wrapped;
 mixin Proxy!Wrapped;

 public this(Container b)
 {
 this.gtkContainer = b.getContainerStruct();
 super(gtkContainer, false);
 }

}

But even the GtkD container doesn't seem to contain any code to deal 
with handling the sizes.



All I'm really looking to do is set the size of a container to whatever 
I want.




If you want gtk to know about the functions you override you could use 
gtkd.Implement.ImplementCLass.


It's only in master and not completely finished yet, but you could use 
it to for example overrride the getPreferredHeight and getPreferredWidth 
functions.


I'm not completely clear on what you want to do with the size so they 
might not be the correct functions to override.



```
class MyBox : Box
{
  import gtkd.Implement;
  import gobject.c.functions : g_object_newv;

  mixin ImplementClass!GtkBox;

  this()
  {
//TODO: sort out the constructor.
super(cast(GtkApplication*)g_object_newv(getType(), 0, null), true);

  }

  override public void getPreferredHeight(out int minimumHeight, out 
int naturalHeight)

  {
//Set minimumHeight and naturalHeight.
  }

  override public void getPreferredWidth(out int minimumWidth, out int 
naturalWidth)

  {
//Set minimumWidth and naturalWidth.
  }
}
```

--
Mike Wey


GtkD: New widget

2017-08-20 Thread Johnson Jones via Digitalmars-d-learn

Hey Mike, I bet you can answer this!

I'd like to extend a widget to add some functionality.

class MyBox : Box
{
protected GtkBox* gtkBox;

import std.typecons;
_gtk.Box Wrapped;
mixin Proxy!Wrapped;

public this(Box b)
{
this.gtkBox = b.getBoxStruct();
super(gtkBox, false);
}

}

Trying something like the above does extend the box, as far as 
allowing one to replace it, I think(using the code);


auto b = new MyBox(W1);
auto p = W1.getParent();
auto c = cast(Box)W4;
c.remove(W1);
c.add(b);

So, W4 is the main boxx, W1 is the box inside the main box I 
replaced with the new box b.


When running that code, nothing changes, which, assuming we are 
actually using the new box, then that is fine.


But I'm pretty sure that gtk never has a clue about `MyBox`? I 
say this because I'd like to simply modify the reported sizes of 
the box.


A gtkBox is not the same as a gtk.Box.

It seems like the best I can do is use a gtk.Container and 
inherit from that.



e.g.,

class FixableSizedBox : Container
{
protected GtkContainer* gtkContainer;

import std.typecons;
_gtk.Container Wrapped;
mixin Proxy!Wrapped;

public this(Container b)
{
this.gtkContainer = b.getContainerStruct();
super(gtkContainer, false);
}

}

But even the GtkD container doesn't seem to contain any code to 
deal with handling the sizes.



All I'm really looking to do is set the size of a container to 
whatever I want.