vlang / ui

A cross-platform UI library written in V
MIT License
2.32k stars 154 forks source link

debug refactor #419

Closed ghost closed 2 years ago

ghost commented 2 years ago

In ui_extra_debug.v, there are methods for Stack and Widget, but if you use these structs as receivers in this file, you will get a compilation error if the Stack file and this file are not in the same module. On the other hand, if you move the receiver as an argument, you can just import the Stack. In this way, it is loosely coupled and allows for more flexibility in module differentiation.

Consequently, the function names have also been adjusted.

Added examples/simple.v for temporal quick check.

spytheman commented 2 years ago

I do not understand the problem that this solves. Can you add an example that does not compile at master, but does with your PR?

spytheman commented 2 years ago

This compiles on both master, and in your PR, so it is not a good example imho:

import ui

fn main() {
        lbl := ui.label(text: 'Label')
        window := ui.window(
                width: 300
                height: 200
                children: [ui.row(children: [lbl])]
        )
        ui.run(window)
}
ghost commented 2 years ago

In conclusion, this is the kind of error I get.

/home/tsukasa/.vmodules/ui/debug/ui_extra_debug.v:7:7: error: cannot define new methods on non-local type ui.Stack
    5 | 
    6 | // Draw bounding box for Stack
    7 | fn (s &ui.Stack) draw_bb() {
      |       ~~~~~~~~~
    8 |     mut col := gx.red
    9 |     if s.direction == .row {

範囲を選択_038

> v -d bb run simple.v

Then you listen to the compiler and adjust it, and finally you get that error.

I don't know non-local type exactly. In any case, having fn (mut s Stack) in ui_extra_debug.v is not a good prospect, so the choice is whether to bring this method to stack.v or make it an argument in this file. In this case, I decided that the latter would be better.

ghost commented 2 years ago

This compiles on both master, and in your PR, so it is not a good example imho:

import ui

fn main() {
        lbl := ui.label(text: 'Label')
        window := ui.window(
                width: 300
                height: 200
                children: [ui.row(children: [lbl])]
        )
        ui.run(window)
}

The build_examples.vsh is too heavy for my computer, so this sample was more desirable to inspect several times during development. That sample is not absolutely necessary for this PR. I thought about deleting it before I did the PR, but I thought it would be a good sample of how ui works even if it is minimal and doesn't use Layout, so I didn't delete it. And I can use it next time too. It's not absolutely necessary, so should I delete it?

spytheman commented 2 years ago

For some reason, this could not be merged through the web UI. I merged it through following the instructions from here: image

This is the second time, that it happens with one of your PRs @kahsa, can you please check the settings of your github repository, and/or delete it, then fork https://github.com/vlang/ui again?