Re: UI Library

2022-05-19 Thread harakim via Digitalmars-d-learn

On Friday, 20 May 2022 at 02:53:39 UTC, Craig Dillabaugh wrote:

On Friday, 20 May 2022 at 02:37:48 UTC, harakim wrote:
I need to write a piece of software to track and categorize 
some purchases. It's the kind of thing I could probably write 
in a couple of hours in C#/Java + html/css/javascript. 
However, something keeps drawing me to D and as this is a 
simple application, it would be a good one to get back in 
after almost a year hiatus.


[...]


Maybe you can use minigui from arsd

https://github.com/adamdruppe/arsd


Thank you. I will definitely give that a try.


Re: UI Library

2022-05-19 Thread Craig Dillabaugh via Digitalmars-d-learn

On Friday, 20 May 2022 at 02:37:48 UTC, harakim wrote:
I need to write a piece of software to track and categorize 
some purchases. It's the kind of thing I could probably write 
in a couple of hours in C#/Java + html/css/javascript. However, 
something keeps drawing me to D and as this is a simple 
application, it would be a good one to get back in after almost 
a year hiatus.


[...]


Maybe you can use minigui from arsd

https://github.com/adamdruppe/arsd


UI Library

2022-05-19 Thread harakim via Digitalmars-d-learn
I need to write a piece of software to track and categorize some 
purchases. It's the kind of thing I could probably write in a 
couple of hours in C#/Java + html/css/javascript. However, 
something keeps drawing me to D and as this is a simple 
application, it would be a good one to get back in after almost a 
year hiatus.


For this, I need a UI library to use. I need text inputs, buttons 
and that sort of thing. My My order of preference is:

1. Native component library that works on linux and windows
2. Something like SDL
3. Native component library that works on linux or windows
4. vibe.d + web

I mostly value that it works over lots of functionality and 
stability over the way the UI looks. Is there an obvious native 
application component library to use? If not, is bindbc the best 
way to go for the sdl-like option? I think I can figure out 
option Vibe.d if there are no good non-web solutions.


PS I'm surprised the forum search didn't turn up topics about 
desktop applications or UI libraries because I know I've seen 
them.


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Mike Parker via Digitalmars-d-learn

On Friday, 20 May 2022 at 00:12:44 UTC, Chris Katko wrote:

Yeah that occurred to me as I was falling asleep. Though, do I 
have to a specify


```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the 
world, but ideally, these are static / hardcoded values that 
can be used thousands of times a second.


If the declarations are at module scope, `static` has no effect, 
and CTFE will be used for initialization.


Re: vibe.d requestHTTP in static this causes infinite loop?

2022-05-19 Thread Ali Çehreli via Digitalmars-d-learn

On 5/19/22 16:44, Vijay Nayar wrote:

> If I remove the call from `static this()`, then the web call works as
> normal. Any idea why calling vibe.d's `requestHTTP` function inside of a
> module's static construction would cause an infinite loop?

I am not experienced with vibe.d.

'static this' is executed per thread. If requestHTTP starts a new 
thread, then I can see how you would be in an infinite loop. I wonder 
whether it should be 'shared static this' (which is executed once per 
program, not per thread).


Ali



Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/19/22 8:29 PM, Steven Schveighoffer wrote:

Given a CTFE function it's very easy to wrap for ensuring compile-time 
usage:


```d
enum ctGrey(float f) = grey(f);

auto myColor = ctGrey!(0.5);
```


That being said, if it's calculatable at compile time, chances are the 
compiler is already going to do it, even for a standard constructor 
call, especially if there's no custom constructor.


-Steve


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/19/22 8:12 PM, Chris Katko wrote:

On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote:

On 19.05.22 12:15, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


What's wrong with a simple plain function?

COLOR grey(float rgb)
{
    return COLOR(rgb, rgb, rgb, 1);
}
auto myColor = grey(0.5);


Yeah that occurred to me as I was falling asleep. Though, do I have to a 
specify


```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the world, but 
ideally, these are static / hardcoded values that can be used thousands 
of times a second.


Given a CTFE function it's very easy to wrap for ensuring compile-time 
usage:


```d
enum ctGrey(float f) = grey(f);

auto myColor = ctGrey!(0.5);
```

-Steve


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Chris Katko via Digitalmars-d-learn

On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote:

On 19.05.22 12:15, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


What's wrong with a simple plain function?

COLOR grey(float rgb)
{
return COLOR(rgb, rgb, rgb, 1);
}
auto myColor = grey(0.5);


Yeah that occurred to me as I was falling asleep. Though, do I 
have to a specify


```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the 
world, but ideally, these are static / hardcoded values that can 
be used thousands of times a second.


vibe.d requestHTTP in static this causes infinite loop?

2022-05-19 Thread Vijay Nayar via Digitalmars-d-learn
I've encountered an unusual behavior that I have no good 
explanation for. Consider the following code example:


```d
import vibe.core.log : logInfo;
import vibe.http.client : requestHTTP, HTTPClientRequest, 
HTTPClientResponse;

import vibe.http.common : HTTPMethod;
import vibe.stream.operations : readAllUTF8;

void doThing() {
  requestHTTP("http://example.com/;,
  (scope HTTPClientRequest req) {
logInfo("Setting request method.");
req.method = HTTPMethod.GET;
  },
  (scope HTTPClientResponse res) {
logInfo("Log point 1");
string data = res.bodyReader.readAllUTF8();
logInfo("Log point 2: %s", data);
  });
}

static this() {
  logInfo("--- static this() ---");
  doThing();
}

void main(string[] args) {
  logInfo("--- main() ---");
  doThing();
}
```

The output of this program is actually an infinite loop with 
output of the form:

```
[Eventcore DNS Lookup() INF] --- static this() ---
[Eventcore DNS Lookup() INF] --- static this() ---
```

If I remove the call from `static this()`, then the web call 
works as normal. Any idea why calling vibe.d's `requestHTTP` 
function inside of a module's static construction would cause an 
infinite loop?


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

On Thursday, 19 May 2022 at 22:13:06 UTC, Adam Ruppe wrote:

On Thursday, 19 May 2022 at 21:41:50 UTC, Marcone wrote:
Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


-L/entry:mainCRTStartup


try the w one too. both doing the same result?


Both is doing the same result.


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam Ruppe via Digitalmars-d-learn

On Thursday, 19 May 2022 at 21:41:50 UTC, Marcone wrote:
Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


-L/entry:mainCRTStartup


try the w one too. both doing the same result?


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

On Thursday, 19 May 2022 at 20:33:34 UTC, Adam D Ruppe wrote:

On Thursday, 19 May 2022 at 20:20:49 UTC, Marcone wrote:

I am using a main() function.
I am compiling on Windows x86 32 bits.
I am using DMD 2.100.0
This error is only in version 2.100.0 of DMD.


Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


-L/entry:mainCRTStartup


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam D Ruppe via Digitalmars-d-learn

On Thursday, 19 May 2022 at 20:20:49 UTC, Marcone wrote:

I am using a main() function.
I am compiling on Windows x86 32 bits.
I am using DMD 2.100.0
This error is only in version 2.100.0 of DMD.


Are you using the `-L/entry:mainCRTStartup` or the 
`L/entry:wmainCRTStartup` ?


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

On Thursday, 19 May 2022 at 19:35:20 UTC, Adam D Ruppe wrote:

On Thursday, 19 May 2022 at 19:29:25 UTC, Marcone wrote:

Using -L/SUBSYSTEM:windows user32.lib


you using a main() function right?

Please note when compiling on Win64, you need to explicitly 
list -Lgdi32.lib -Luser32.lib on the build command. If you want 
the Windows subsystem too, use -L/subsystem:windows 
-L/entry:mainCRTStartup.


If using ldc instead of dmd, use -L/entry:wmainCRTStartup 
instead of mainCRTStartup; note the "w".



see some deets i wrote here

http://arsd-official.dpldocs.info/arsd.simpledisplay.html#installation-instructions


I am using a main() function.
I am compiling on Windows x86 32 bits.
I am using DMD 2.100.0
This error is only in version 2.100.0 of DMD.


Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam D Ruppe via Digitalmars-d-learn

On Thursday, 19 May 2022 at 19:29:25 UTC, Marcone wrote:

Using -L/SUBSYSTEM:windows user32.lib


you using a main() function right?

Please note when compiling on Win64, you need to explicitly list 
-Lgdi32.lib -Luser32.lib on the build command. If you want the 
Windows subsystem too, use -L/subsystem:windows 
-L/entry:mainCRTStartup.


If using ldc instead of dmd, use -L/entry:wmainCRTStartup instead 
of mainCRTStartup; note the "w".



see some deets i wrote here

http://arsd-official.dpldocs.info/arsd.simpledisplay.html#installation-instructions


Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Marcone via Digitalmars-d-learn

Using -L/SUBSYSTEM:windows user32.lib

Error:

lld-link: error: undefined symbol: _WinMain@16
referenced by 
msvcrt120.lib(msvcrt_stub2.obj):(_WinMainCRTStartup)

Error: linker exited with status 1


Re: Unexplainable behaviour with direct struct assignment.

2022-05-19 Thread frame via Digitalmars-d-learn

On Wednesday, 18 May 2022 at 21:49:14 UTC, HuskyNator wrote:

After updating to `DMD 2.100.0` & `DUB 1.29.0`, I still get 
this behavior.
Only when I use `dub run --b=debug` however (default for me). 
`dub run --b=release` does return what one would expect.


I'm still on 2098.1, Windows 10 and get this at 64bit only

```
9.18366e-40
50
nan
```

but no matter if debug build or not.


Re: Unexplainable behaviour with direct struct assignment.

2022-05-19 Thread HuskyNator via Digitalmars-d-learn

On Thursday, 19 May 2022 at 04:33:01 UTC, Tejas wrote:

Does this happen with LDC as well?


I tried it using `LDC 1.29.0` and it prints correctly under both 
`--b=release` and `--b=debug` builds.


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread ag0aep6g via Digitalmars-d-learn

On 19.05.22 12:15, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


What's wrong with a simple plain function?

COLOR grey(float rgb)
{
return COLOR(rgb, rgb, rgb, 1);
}
auto myColor = grey(0.5);


Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread bauss via Digitalmars-d-learn

On Thursday, 19 May 2022 at 10:18:38 UTC, user1234 wrote:

On Thursday, 19 May 2022 at 10:15:32 UTC, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


average is a bad way to grayscale FYI ;)


This is correct, you actually have to do something like this:

```d
uint g = (uint)((0.3f * r) + (0.59f * g) + (0.11f * b));
```

Where g is the new value for the current pixel's rgb value.

However, OP doesn't seem to be grayscaling images, but rather 
just wanting to specify gray colors.


In which case something like this could work:

```d
COLOR GREY(float amount)() { return COLOR(amount, amount, amount, 
1.0); }


...

auto myColor = GREY!(0.5);

myColor is COLOR(0.5, 0.5, 0.5, 1.0)
```



Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread user1234 via Digitalmars-d-learn

On Thursday, 19 May 2022 at 10:15:32 UTC, Chris Katko wrote:

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


average is a bad way to grayscale FYI ;)


template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Chris Katko via Digitalmars-d-learn

given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}

auto red   = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue  = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```

is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes COLOR(0.5, 0.5, 0.5, 1.0);
```


Re: Why are structs and classes so different?

2022-05-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Wednesday, 18 May 2022 at 10:53:03 UTC, forkit wrote:

Here is a very interesting article that researches this subject.


Yeah, he got it right. It is syntax sugar that makes verbose C++ 
code easier to read. Use struct for internal objects and tuple 
like usage and class for major objects in your model.


But Simula used class for more: coroutines and library modules. 
So, you could take a class and use its scope in your code and 
thereby get access to the symbols/definitions in it.


The successor to Simula, called Beta, took it one step further 
and used the class concept for functions, block scopes, loops, 
almost everything.


The language Self went even further and collapsed the concept of 
class and object into one... perhaps too far... People prefer 
Typescript over Javascript for a reason. 


Re: class destructors must be @disabled?

2022-05-19 Thread bauss via Digitalmars-d-learn

On Wednesday, 18 May 2022 at 19:58:09 UTC, Ali Çehreli wrote:


Hmm. Perhaps the guideline should be "all destructors must be 
@nogc".


Ali


It should probably just default to that and with no exception, 
since you will never end up in a situation where you don't want 
@nogc for a destructor.


At least I can't imagine one, and if there is one then it's 
probably due to another design issue in one's program.


Re: Unexplainable behaviour with direct struct assignment.

2022-05-19 Thread bauss via Digitalmars-d-learn

On Wednesday, 18 May 2022 at 21:52:18 UTC, HuskyNator wrote:

On Wednesday, 18 May 2022 at 21:49:14 UTC, HuskyNator wrote:
After updating to `DMD 2.100.0` & `DUB 1.29.0`, I still get 
this behavior.
Only when I use `dub run --b=debug` however (default for me). 
`dub run --b=release` does return what one would expect.


I don't know if this matters either, but I'm using windows 10 
(64 bits).


Can confirm this is the case for me too on Windows 10.

Release prints 50 3 times, debug prints 0, 50, nan.

This is with DMD, I currently don't have LDC or GDC installed on 
this machine.


So it looks like a Windows bug, critical at that.


Re: I need to use delete as the method name. But now it's still a keyword, right?

2022-05-19 Thread bauss via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 15:33:09 UTC, Steven Schveighoffer 
wrote:

On 5/18/22 2:13 AM, bauss wrote:

On Wednesday, 18 May 2022 at 02:12:42 UTC, zoujiaqing wrote:

https://dlang.org/changelog/2.100.0.html#deprecation_delete

My code:

```D
import std.stdio;

class HttpClient
{
string get(string url)
{
    return "";
}

string delete(string url)
{
    return "";
}
}

void main()
{
auto http = new HttpClient;

string content = 
http.get("https://forum.dlang.org/group/general;);
string content = 
http.delete("https://forum.dlang.org/newpost/general?;);

}
```

error message
```bash
% dub build --compiler=dmd
Performing "debug" build using dmd for x86_64.
test ~master: building configuration "application"...
source/app.d(10,9): Error: no identifier for declarator 
`string`

source/app.d(10,9): Error: declaration expected, not `delete`
source/app.d(14,1): Error: unmatched closing brace
dmd failed with exit code 1.
```

I wonder when I can use it. Because this will cause a 
software naming problem.


Considering the deprecation period has ended then IMO it 
should be able to be used as an identifier.


I would consider this a bug.


No, it's intentional.

https://dlang.org/changelog/2.100.0.html#deprecation_delete

> Starting with this release, using the delete *keyword* will
result in a *compiler error*.

It's still a keyword according to that. I'm assuming a future 
release will remove the error, and then you can use it as a 
symbol.


-Steve


To be honest, it's not clear that it's intentional from the 
description of the changelog. It just says using the keyword will 
result in an error, not using the keyword as an identifier, which 
isn't the same at all.