digitalmars.D.learn - How to use dguihub package ?
- Vinod K Chandran (23/23) Jan 17 2021 Hi all,
- Mike Parker (6/7) Jan 17 2021 Three of those messages include the solution to fix the errors.
- Vinod K Chandran (11/17) Jan 19 2021 Hi Mike Parker, I just comment out the first area and write an
- Paul Backus (31/36) Jan 19 2021 `a |= b` is shorthand for `a = a | b`. Similarly, `a &= b` is
- Vinod K Chandran (15/21) Jan 20 2021 Hi Paul Backus,
- Paul Backus (35/59) Jan 20 2021 Not quite. If you print out TBSTATE_ENABLED in binary, you will
Hi all, I would like to use a gui package called "dguihub". So i did these steps. 1. Downloaded source files from Github. 2. Extract it and copy dguihub folder to my project folder. this folder contains all the source files of this package. 3. Write an import statement in my app.d "import dguihub;" 4. Copy paste the code from "hello" in example folder 5. Compiled with "rdmd app.d" And i got this result. dguihub\toolbar.d(103): Deprecation: integral promotion not done for ~TBSTATE_ENABLED, use '-preview=intpromote' switch or ~cast(int)(TBSTATE_ENABLED) dguihub\core\menu\abstractmenu.d(187): Deprecation: variable mi is shadowing variable dguihub.core.menu.abstractmenu.RootMenu.create.mi. Rename the foreach variable. dguihub\core\menu\abstractmenu.d(209): Deprecation: integral promotion not done for ~enabled, use '-preview=intpromote' switch or ~cast(int)(enabled) dguihub\core\utils.d(130): Error: template instance to!wstring template to is not defined Do i miss something ?
Jan 17 2021
On Sunday, 17 January 2021 at 13:04:33 UTC, Vinod K Chandran wrote:Do i miss something ?Three of those messages include the solution to fix the errors. The fourth one is a missing import (`import std.conv : to`) in dguihub.core.utils. You could fix these yourself and submit a pull request to the project, or submit an issue.
Jan 17 2021
On Sunday, 17 January 2021 at 14:00:48 UTC, Mike Parker wrote:On Sunday, 17 January 2021 at 13:04:33 UTC, Vinod K Chandran Three of those messages include the solution to fix the errors. The fourth one is a missing import (`import std.conv : to`) in dguihub.core.utils. You could fix these yourself and submit a pull request to the project, or submit an issue.Hi Mike Parker, I just comment out the first area and write an import statement as you said. But I omited the ": to" part. And Suddenly it worked. But I think I should need to work on the commented code because it's the "Enabled" property of toolbar class. But for me, this code looks Chinese. Anyhow, I am planning to study this from beginning. "b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED);" This is the problem line in that property. "b" is a boolean parameter. But I dont know what this "|="sign means in D.
Jan 19 2021
On Tuesday, 19 January 2021 at 16:22:35 UTC, Vinod K Chandran wrote:Anyhow, I am planning to study this from beginning. "b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED);" This is the problem line in that property. "b" is a boolean parameter. But I dont know what this "|="sign means in D.`a |= b` is shorthand for `a = a | b`. Similarly, `a &= b` is shorthand for `a = a & b`. The `|` symbol is the "bitwise or" operator, the `&` symbol is the "bitwise and" operator, and the `~` symbols is the "bitwise not" operator. [1] The way they're being used here is to implement a bit field [2]--a data structure in which each bit of an integer is treated as a boolean "flag", where 1 is true and 0 is false. In this usage, the expression field |= FLAG ...means "take all of the bits that are set to 1 in FLAG and set them to 1 in field"; or, in other words, "set FLAG to true in field." And the expression field &= ~FLAG ...means "take all of the bits that are set to 0 in FLAG and set them to 1 in field"; or, in other words, "set FLAG to false in field". You may want to take a minute with pen and paper to convince yourself that these particular bitwise operations actually do what I'm claiming they do, since it's not really obvious just from looking at them. Armed with this knowledge, we can now understand the line of code you quoted in your message: b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED); This means, "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false." [1] https://en.wikipedia.org/wiki/Bitwise_operation#Bitwise_operators [2] https://en.wikipedia.org/wiki/Bit_field
Jan 19 2021
On Tuesday, 19 January 2021 at 16:52:18 UTC, Paul Backus wrote:On Tuesday, 19 January 2021 at 16:22:35 UTC, Vinod K Chandran wrote: b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED); This means, "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false."Hi Paul Backus, Thanks for the detailed reply. After reading your reply, I got the idea. But think there is one silly mistake in your reply. Forgive me if I am wrong. Instead of "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false." This is the meaning of that code. if (b == true) {tbinfo.fsState = true ; } else {tbinfo.fsState = false;} Because, TBSTATE_ENABLED is a manifest constant and I cannot modify it. What about simply writing this -- "tbinfo.fsState = b ; " This also worked.
Jan 20 2021
On Wednesday, 20 January 2021 at 19:05:29 UTC, Vinod K Chandran wrote:On Tuesday, 19 January 2021 at 16:52:18 UTC, Paul Backus wrote:Not quite. If you print out TBSTATE_ENABLED in binary, you will see that it is an integer with exactly one bit set to 1, and all others set to 0. You can do this with the following line of code: writefln("%032b", TBSTATE_ENABLED); By "the TBSTATE_ENABLED flag", I do not mean "the constant TBSTATE_ENABLED". What I mean is "the bit in tbinfo.fsState at the same position as the 1 bit in TBSTATE_ENABLED". To be clearer, I should have said something like "the 'enabled' flag in tbinfo.fsState". If tbinfo.fsState were a struct instead of a bitfield: struct FsState { bool enabled; // other flags... } ...then the meaning of the code would be: if (b == true) { tbinfo.fsState.enabled = true; } else { tbinfo.fsState.enabled = false; } Or more concisely: tbinfo.fsState.enabled = b; Of course, in reality, tbinfo.fsState is a bitfield, not a struct, so we cannot access the individual flags with syntax like `.enabled`. Instead, we have to use bitwise operators. But conceptually, it's the same thing. By contrast, in your proposed version: tbinfo.fsState = b; ...you are overwriting *all* of the flags at once, rather than just one of them. Even if this happens to work by coincidence (because "enabled" is the first flag), it will certainly cause you problems later on.On Tuesday, 19 January 2021 at 16:22:35 UTC, Vinod K Chandran wrote: b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED); This means, "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false."Hi Paul Backus, Thanks for the detailed reply. After reading your reply, I got the idea. But think there is one silly mistake in your reply. Forgive me if I am wrong. Instead of "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false." This is the meaning of that code. if (b == true) {tbinfo.fsState = true ; } else {tbinfo.fsState = false;} Because, TBSTATE_ENABLED is a manifest constant and I cannot modify it. What about simply writing this -- "tbinfo.fsState = b ; " This also worked.
Jan 20 2021