Re: Blog Post #0062: Cairo Load & Display Images
On Friday, 16 August 2019 at 12:58:23 UTC, Andre Pany wrote: This causes some distruction on mobile phone as you have scroll horizontally although it would fit the screen if the source code would start at column 0. That didn't take as long as I thought it would. I removed all excess indentation, so let me know if it's any better now.
Re: Slow UDF call?
On Saturday, 17 August 2019 at 20:57:44 UTC, Giovanni Di Maria wrote: On Saturday, 17 August 2019 at 20:15:02 UTC, Stefan Koch wrote: On Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria wrote: [...] Yes they do A function call has a cost. In case of a function which performes a 1 cycle (nominally without ILP) operation, the overhead of the function call dominates. try compiling with -inline and compare again. Hi Stefan Koch Thank you very much. With the option -inline, now the execution is very fast, only 4 seconds Thnak you thank you very much. Giovanni I have also compiled with: dmd program.d -O -release -inline -boundscheck=off and the execution speed is very very fast. Giovanni
Re: Setting up Dlang Environment
On Saturday, 17 August 2019 at 20:42:41 UTC, Mike Brown wrote: Hi All, I've tried installing and setting up Dlang a few times now. I'm struggling to get it reliable and to a decent environment in place. I don't really want to make this thread about specific issues - Id very much like to know if there's a decent tutorial or guide to setup Dlang? * I'd like to get the basic's down solid (One of my issues is a linker issue on release but not debug, etc) * A decent IDE which allows debugging, understanding the stack traces, step through etc? * The package management, Should I be using DUB or doing packaging etc with make files etc? I appriciate some of this is down to choice, but an idiots guide and recommended practises - to setting up the above so I can just get on with coding would be great. Kind Regards, Mike Hi Mike, Which OS do you target? Setting up DMD on e.g. Ubuntu is just installing package build-essentials and installing the dmd deb file. On Windows you just extract the 7z file and add the bin path to th PATH environment variable. I tried so far IntelliJ IDEA and Visual Studio Code. Both are multi platform and free to use. Both supports debugging but here the details really depends on your OS. For Visual Studio Code there are even different D plugins available. I used vscode-dlang and it was just a fantastic experience. (I still prefer the kind of development flow IntelliJ provides, but Intellij D support is more complex to setup). If you target Windows, there is also Visual Studio, this plugin has no dub integration as far as I know. Kind regards Andre
Re: Blog Post #0062: Cairo Load & Display Images
On Saturday, 17 August 2019 at 19:22:54 UTC, Ron Tarrant wrote: On Friday, 16 August 2019 at 12:44:15 UTC, bauss wrote: Amazing! You might be able to answer me something, whether you could use gtkd solely for image manipulation using ex. Pixbuf? or would it only work with the internals of gtkd? Like can you manipulate the image and save it to disk etc. Those are very good questions, bauss. I haven't dug in that deep yet, but I see no reason why Cairo couldn't be used to build a full-featured paint, manipulation, or structured drawing application. But it won't only be about Pixbufs. The Cairo Context seems to be where all the action is as far as drawing routines go. Over the next few months, off and on, I'll be exploring stuff like that. I'm still working on getting through all the unsexy stuff first (the basic widgets) but every once in a while, I just have to let my hair down and do something that's a bit more complex. After the basic image and drawing stuff is covered, I'll be digging into simple animation and how to tame the Timeout. Then, after a short side-trip to finish off MVC and do some more base-level widgets such as the Toolbar, Statusbar, and Expander, there's another Cairo miniseries coming up that covers nodes and noodles, something I've wanted to dig into for several years. Thanks for reading and thanks for the kind words. Thank you for the answer. I'll take a look at it myself sometime in the near future and see what I can come up with and if I can figure it out :) Also thank you for these blog posts. I enjoy reading them, also the MVC ones.
Adam D. Ruppe's Minigui using example
https://forum.dlang.org/post/mumgkqopnsnowcmhi...@forum.dlang.org On Saturday, 16 January 2016 at 03:14:01 UTC, Adam D. Ruppe wrote: On Saturday, 16 January 2016 at 01:27:32 UTC, Andre Polykanine wrote: Does anyone have an actual example of, say, a simple form with a set of radio buttons or check boxes to start with? Thanks in advance! Sort of. I still haven't used it in a real world program so it isn't complete but here's one of my test programs: --- import arsd.minigui; void main() { auto window = new MainWindow(); auto exitAction = new Action("E"); exitAction.triggered ~= { window.close(); }; window.statusTip = "D ROX!"; auto button = new Checkbox("Uses D!", window); button.isChecked = true; auto hlayout = new HorizontalLayout(window); auto gb = new Fieldset("Type", hlayout); auto gb2 = new Fieldset("cool", hlayout); auto boxlol1 = new Radiobox("Test", gb); auto boxlol2 = new Radiobox("Test2", gb2); auto boxlol3 = new Radiobox("Test", gb); auto boxlol4 = new Radiobox("Test2", gb2); auto group = new MutuallyExclusiveGroup(); group.addMember(new Radiobox("Heavyweight", gb)); auto btn = group.addMember(new Radiobox("Small library", gb)); btn.isChecked = true; btn.statusTip = "205 KB exe on Windows"; //auto spinner = new Spinner(window); ComboboxBase cb = new DropDownSelection(window); cb.addOption("test"); cb.addOption("cool"); cb.setSelection(1); //cb.addEventListener("changed", (Event ev) { //auto bm = new MessageBox("changed " ~ cb.options[cb.selection]); //}); // FIXME: adding this to gb2 instead of window causes wtf stuff cb = new ComboBox(window); cb.addOption("test"); cb.addOption("cool"); cb.setSelection(1); cb = new FreeEntrySelection(window); cb.addOption("test"); cb.addOption("cool"); cb.setSelection(1); auto lineEdit = new LineEdit(window); auto menu = new MenuBar(); auto fileMenu = new Menu(""); auto exitButton = fileMenu.addItem(new MenuItem(exitAction)); menu.addItem(fileMenu); window.loop(); } --- On Windows, it uses the native controls, so it should work reasonably well, though on Linux it does its own thing and is far from complete. BTW simplewindow doesn't seem to compile on newest dmd because of the new core.sys.windows.windows so I'll have to update that if you're on the newest release... While searching for a minigui example in Google, you likely will find this old outdated example. Therefore I answer this very old post. Here a new example from Adam: module menutest; import arsd.minigui; struct Info { string name; string email; } class MyWindow : MainWindow { this() { super("Menu Demo", 250, 400); setMenuAndToolbarFromAnnotatedCode(this); statusTip = "gnarley"; textEdit = new TextEdit(this); auto hl = new HorizontalLayout(this); auto btn = new Button("test", hl); auto btn2 = new Button("test", hl); btn.addEventListener("click", () { messageBox("You clicked"); }); btn2.addEventListener(EventType.triggered, () { dialog!Info((info) { import std.conv; textEdit.content = to!string(info); }); }); textEdit.content = "generic content here"; } TextEdit textEdit; @menu("File") { @toolbar("") @icon(GenericIcons.New) @accelerator("Ctrl+Shift+N") void New() { textEdit.content = ""; } @toolbar("") @icon(GenericIcons.Open) @accelerator("Ctrl+O") void Open() { getOpenFileName( (string s) { //import std.file; //textEdit.content = (readText(s)); } ); } @toolbar("") @icon(GenericIcons.Save) void Save() @accelerator("Ctrl+S") { getSaveFileName( (string s) {} ); } void SaveAs() {} @separator void Exit() @accelerator("Alt+F4") { this.close(); } } @menu("Edit") { @toolbar("") @icon(GenericIcons.Undo) @accelerator("Ctrl+Z") void Undo() {} @toolbar("") @icon(GenericIcons.Redo) @accelerator("Ctrl+R") void Redo() {}
Re: Slow UDF call?
On Saturday, 17 August 2019 at 20:15:02 UTC, Stefan Koch wrote: On Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria wrote: [...] Yes they do A function call has a cost. In case of a function which performes a 1 cycle (nominally without ILP) operation, the overhead of the function call dominates. try compiling with -inline and compare again. Hi Stefan Koch Thank you very much. With the option -inline, now the execution is very fast, only 4 seconds Thnak you thank you very much. Giovanni
Setting up Dlang Environment
Hi All, I've tried installing and setting up Dlang a few times now. I'm struggling to get it reliable and to a decent environment in place. I don't really want to make this thread about specific issues - Id very much like to know if there's a decent tutorial or guide to setup Dlang? * I'd like to get the basic's down solid (One of my issues is a linker issue on release but not debug, etc) * A decent IDE which allows debugging, understanding the stack traces, step through etc? * The package management, Should I be using DUB or doing packaging etc with make files etc? I appriciate some of this is down to choice, but an idiots guide and recommended practises - to setting up the above so I can just get on with coding would be great. Kind Regards, Mike
Re: Slow UDF call?
On Saturday, 17 August 2019 at 19:43:22 UTC, Giovanni Di Maria wrote: Hi, i have seen that a simple operation (in a loop) is faster than the equivalent UDF. The first example takes 4 seconds, the second example takes 16 seconds. Local variables influence the speed of execution? Thank you very much. Giovanni == import std.stdio; void main() { int a,b; int s; int k; writeln("START"); for(k=1;k<=2_000_000_000;k++) { a=7; b=20; s=a+b; } writeln("Fine ",k," ",s); } == import std.stdio; void main() { int a,b; int s; int k; writeln("START"); for(k=1;k<=2_000_000_000;k++) { a=7; b=20; s=somma(a,b); } writeln("Fine ",k," ",s); } int somma(int n1,int n2) { return n1+n2; } Yes they do A function call has a cost. In case of a function which performes a 1 cycle (nominally without ILP) operation, the overhead of the function call dominates. try compiling with -inline and compare again.
Slow UDF call?
Hi, i have seen that a simple operation (in a loop) is faster than the equivalent UDF. The first example takes 4 seconds, the second example takes 16 seconds. Local variables influence the speed of execution? Thank you very much. Giovanni == import std.stdio; void main() { int a,b; int s; int k; writeln("START"); for(k=1;k<=2_000_000_000;k++) { a=7; b=20; s=a+b; } writeln("Fine ",k," ",s); } == import std.stdio; void main() { int a,b; int s; int k; writeln("START"); for(k=1;k<=2_000_000_000;k++) { a=7; b=20; s=somma(a,b); } writeln("Fine ",k," ",s); } int somma(int n1,int n2) { return n1+n2; }
Re: Blog Post #0062: Cairo Load & Display Images
On Friday, 16 August 2019 at 12:58:23 UTC, Andre Pany wrote: Thanks a lot Ron, your page is really helpful. You're welcome, Andre. And thanks for saying so. Is there a reason why the source code starts after a lot of whitespaces on every line? This causes some distruction on mobile phone as you have scroll horizontally although it would fit the screen if the source code would start at column 0. Thanks for bringing this to my attention. I've recently switched from basic MD for displaying source and the way I was doing it demanded that everything be indented one tab. I've since switched to Jekyll/Liquid's {% highlight d %} system which doesn't have this limitation. Now that I know this is an issue, give me a some time and I'll get all those extra indents removed.
Re: Blog Post #0062: Cairo Load & Display Images
On Friday, 16 August 2019 at 12:44:15 UTC, bauss wrote: Amazing! You might be able to answer me something, whether you could use gtkd solely for image manipulation using ex. Pixbuf? or would it only work with the internals of gtkd? Like can you manipulate the image and save it to disk etc. Those are very good questions, bauss. I haven't dug in that deep yet, but I see no reason why Cairo couldn't be used to build a full-featured paint, manipulation, or structured drawing application. But it won't only be about Pixbufs. The Cairo Context seems to be where all the action is as far as drawing routines go. Over the next few months, off and on, I'll be exploring stuff like that. I'm still working on getting through all the unsexy stuff first (the basic widgets) but every once in a while, I just have to let my hair down and do something that's a bit more complex. After the basic image and drawing stuff is covered, I'll be digging into simple animation and how to tame the Timeout. Then, after a short side-trip to finish off MVC and do some more base-level widgets such as the Toolbar, Statusbar, and Expander, there's another Cairo miniseries coming up that covers nodes and noodles, something I've wanted to dig into for several years. Thanks for reading and thanks for the kind words.
Re: advise about safety of using move in an opAssign with __traits(isRef
On Friday, 16 August 2019 at 08:07:28 UTC, aliak wrote: Hi, I'm trying to fix a use-case where you have a wrapper template type (it's an optional) and the wrapping type has @disable this(this). And having this scenario work: struct S { @disable this(this); } Optional!S fun() {...} Optional!S a; a = fun.move; Now that won't work because of the disabled copy Are you sure? I tried to reproduce the error you're describing, and I couldn't do it. The following compiles and runs without any issues: struct Wrapper(T) { T value; } struct NoCopy { @disable this(this); } Wrapper!NoCopy fun() { return Wrapper!NoCopy(); } void main() { Wrapper!NoCopy a; a = fun(); // already an rvalue, so moved implicitly } Can you give a more complete example of the problem you're having?
Re: advise about safety of using move in an opAssign with __traits(isRef
On Friday, 16 August 2019 at 14:29:26 UTC, Paul Backus wrote: On Friday, 16 August 2019 at 08:07:28 UTC, aliak wrote: [...] Even simpler: void opAssign(auto ref Optional!T rhs) { import core.lifetime: forward; this._value = forward!rhs; } That doesn't work with private members unfortunately :( - i.e. this.value = forward!(rhs._value) - member inaccessible. Is there a known workaround for that? If not then should I just copy the implementation in place to be correct?