Re: arsd-minigui - couple of questions

2022-03-28 Thread Adam Ruppe via Digitalmars-d-learn
In fact, using a pragma now, I think I got it so you don't even 
need the manifest now (the pragma includes a default one now).


Only works when doing dmd -m32mscoff or dmd -m64 builds (which 
are also what dub uses fyi), will NOT work with a default dmd 
no-switch build.


Re: arsd-minigui - couple of questions

2022-03-28 Thread Adam Ruppe via Digitalmars-d-learn
oooh it actually is even easier than I thought, just a changed 
flag plus the manifest.


Just pushed to minigui master. only ended up being 4 lines for 
this little thing.


Try rebuilding with that AND be sure to use the manifest file 
too, same as dwt. Then you should be able to find some joy.


Re: How to make a generic function to take a class or struct by reference?

2022-03-28 Thread Ali Çehreli via Digitalmars-d-learn

On 3/27/22 22:32, vit wrote:

> int* getX(T)(return auto ref T t)
> if(is(T == class) || (is(T == struct) && __traits(isRef, t))){
>  return &t.x;
> }

I also think 'return' parameter is needed but I could not come up with 
an example where that 'return' provides any more safety. Compiler 
already warns without it. (I tried with and without -preview=dip1000 
-preview=dip25).


Ali



Re: How to make a generic function to take a class or struct by reference?

2022-03-28 Thread Ali Çehreli via Digitalmars-d-learn

On 3/27/22 09:27, JN wrote:
> I would like to have only one definition of getX if possible, because
> they both are doing the same thing. I can't remove the ref one, because
> without a ref it will pass the struct as a temporary and compiler won't
> like that.

Combining all responses, the code at the bottom is a working example.

First, we should remove the by-value getX function but then class 
function fails expectedly:


class Bar
{
int x;

void doStuff()
{
  *getX(this) = 5;  // <-- Compilation ERROR
}
}

It may be worth going over why it fails to compile: 'this' happens to be 
of type Bar. Since classes are reference types, the 'this' is of type 
Bar (a reference) but it is an rvalue. (It is an rvalue because there is 
no one variable 'this' for this or any object.) rvalues cannot be passed 
by-reference; so the compilation fails.


So, assuming the by-value getX() is removed, the following would make 
the code compile:


class Bar
{
int x;

void doStuff()
{
  auto this_ = this;
  *getX(this_) = 5;  // <-- Now compiles
}
}

In that case we pass 'this_', which is clearly an lvalue and it can be 
passed by-reference. (lvalue becaues it is a variable sitting on the stack.)


But we don't want to do the above everywhere, so 'auto ref' is a 
solution. The reason is, it would copy the rvalue (the object reference) 
arguments and it wouldn't be an error because the copied rvalue would be 
another reference to the same class object and it would work.


import std.stdio;

struct Foo
{
int x;

void doStuff()
{
  *getX(this) = 5;
}
}

class Bar
{
int x;

void doStuff()
{
  *getX(this) = 5;
}
}

auto getX(T)(auto ref T t)
{
  return &t.x;
}

void main()
{
Foo foo;
Bar bar = new Bar();

foo.doStuff();
bar.doStuff();

assert(foo.x == 5);
assert(bar.x == 5);
}

Ali



Re: arsd-minigui - couple of questions

2022-03-28 Thread Adam Ruppe via Digitalmars-d-learn

On Monday, 28 March 2022 at 21:10:47 UTC, Sai wrote:
FWIW, DWT which uses native controls on windows can show 
transparent pngs and also both image & text at the same time. 
However I had to add the following app.exe.manifest


Yeah, this tells me they used owner-drawn buttons, which is only 
supported if you use version 6 controls. The version 6 controls 
are nice btw even if you don't use this specific feature, they 
also come with automatic theme support and a few other nice 
things. I actually recommend in the docs that you use this for 
simpledisplay/minigui applications too, just then you also need 
to provide a draw method to do the text+image.


It isn't hard to do, about a dozen lines for this basic case that 
you can just opt into and use the default draw for other cases.


I was thinking about adding one of those anyway (another nice 
thing you can do is change the background color), I just haven't 
gotten around to it yet. Maybe I'll do it tomorrow.


Keep an eye on this thread, if I do, I'll let you know.



Re: arsd-minigui - couple of questions

2022-03-28 Thread Sai via Digitalmars-d-learn

On Monday, 28 March 2022 at 18:03:32 UTC, Adam Ruppe wrote:

On Monday, 28 March 2022 at 17:00:42 UTC, sai wrote:
1. I assume arsd-minigui library does not support transparent 
images by itself, does it? I am trying to show a png image 
with transparent areas on a button, but those transparent 
areas shows as black color.


Well, I tried forwarding the flag, I can custom draw it this 
way but the standard Windows button's normal draw doesn't 
appear to care...


There might be a trick I just don't know, but the problem is I 
don't know it lol.



Thanks for the reply and the help.

FWIW, DWT which uses native controls on windows can show 
transparent pngs and also both image & text at the same time. 
However I had to add the following app.exe.manifest file in the 
same folder as the app.exe file. Otherwise it only shows text or 
image but not both. Not sure if this helps, but just want to let 
you know. Honestly I have no idea how this works under the hood.


```

manifestVersion="1.0">

  
  
  

  

  

```



Re: arsd-minigui - couple of questions

2022-03-28 Thread Adam Ruppe via Digitalmars-d-learn

On Monday, 28 March 2022 at 17:00:42 UTC, sai wrote:
1. I assume arsd-minigui library does not support transparent 
images by itself, does it? I am trying to show a png image with 
transparent areas on a button, but those transparent areas 
shows as black color.


Well, I tried forwarding the flag, I can custom draw it this way 
but the standard Windows button's normal draw doesn't appear to 
care...


There might be a trick I just don't know, but the problem is I 
don't know it lol.





Re: arsd-minigui - couple of questions

2022-03-28 Thread Adam Ruppe via Digitalmars-d-learn

On Monday, 28 March 2022 at 17:00:42 UTC, sai wrote:
1. I assume arsd-minigui library does not support transparent 
images by itself, does it? I am trying to show a png image with 
transparent areas on a button, but those transparent areas 
shows as black color.


I added that to simpledisplay last year, but never forwarded the 
flag to minigui since it didn't seem important should be easy 
enough to add, I'll take a look.


2. I want to show both image and text on a button, but looks 
like it shows image or text, but not both at the same time. Or 
am I missing some weird windows manifest stuff?


Yeah, it is one or the other right now. I don't think the 
standard Windows control supports that without owner draw, which 
is something I've generally tried to avoid (but it isn't that 
hard to do at least in some cases...).


Re: arsd-minigui - couple of questions

2022-03-28 Thread sai via Digitalmars-d-learn

On Monday, 28 March 2022 at 17:00:42 UTC, sai wrote:
1. I assume arsd-minigui library does not support transparent 
images by itself, does it? I am trying to show a png image with 
transparent areas on a button, but those transparent areas 
shows as black color.



2. I want to show both image and text on a button, but looks 
like it shows image or text, but not both at the same time. Or 
am I missing some weird windows manifest stuff?


I am using latest arsd library on windows 10.

Thanks


BTW, the code is very simple:

```d
import arsd.minigui;

void main() {
auto window = new Window();
	auto headBut = new Button(ImageLabel("Button name", 
MemoryImage.fromImage("file.png")), window);

window.loop();
}
```


arsd-minigui - couple of questions

2022-03-28 Thread sai via Digitalmars-d-learn
1. I assume arsd-minigui library does not support transparent 
images by itself, does it? I am trying to show a png image with 
transparent areas on a button, but those transparent areas shows 
as black color.



2. I want to show both image and text on a button, but looks like 
it shows image or text, but not both at the same time. Or am I 
missing some weird windows manifest stuff?


I am using latest arsd library on windows 10.

Thanks