AaronErhardt / AaronErhardt.github.io

My personal blog

Home Page:https://aaronerhardt.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Explain postition function in FactoryPrototype trait

tronta opened this issue · comments

imho this chapter could be improved:
https://aaronerhardt.github.io/relm4-book/book/factory.html#the-position-function

When I read it, I still feel, like I don't have grasped what the index it.
Would it make sense to beef up the example a little bit?
What about having for the widget a box with a label (eg initial value) and then the button with the current value? Not sure if this helps, 😄
Or a link to a more complex example.

The factory_grid example is more complex in this manner. A gtk::Grid uses positions for row, column, width and height. But a gtk::Box doesn't have any position values. The position has nothing yo do with the index. It just tells the factory where to place widgets if the view is a gtk::Grid for example. Otherwise the position is basically useless.

Was that explanation helpful? I now see that the explanation is pretty short in the book so this issue should definitely be kept open.

I already guessed something like this.
One problem I seem to have iin general is I'd like to understand how those automagic functions work.

If you write something like this, I seems to be for me a little bit like you performing a magic trick and at the end not explaining how the trick worked. 😀

Not sure how much text/effort it is to describe it, but I think it could be worth doing it, as people might gain more trust in using Relm.
What do you think?

Sounds good. I will improve the text when I come back.
Btw. the position is used here: https://github.com/AaronErhardt/relm4/blob/main/src/factory/mod.rs#L72

I hope the new text explains it better. I also added a small image: https://aaronerhardt.github.io/relm4-book/book/factory.html#the-position-function

Cool. I'm a big fan of visualization. However for it is a little bit confusing. For me it's not clear when which of the examples apply. Maybe it would help to add the used widget definition to the example.

I don't know what exactly you mean. You can use any layout you want if this is what you mean. The picture just shows two examples. But maybe I should add a link to the grid_factory example where the position property is actually used.

You need to know, that I have not much pre-knowledge (which is good for giving feedback) and I'm a simple person 😄.
For me it this

Because the factory can't guess where you want to add new widgets, you need to specify the widget placement in the position function. For example, you could have three elements per row or per column or any other layout you want.

with the pictures, does not explain enough how I can specify, the positions.

And here you write nothing about grid: https://aaronerhardt.github.io/docs/relm4/relm4/factory/collections/index.html
Because I would assume that one would need also a two dimensional data type
Probably I'm just confused…

In this case you don't need a two dimensional data type. You just map the index to 2D grid space. See the grid_factory example that generates a chess grid pattern: https://github.com/AaronErhardt/relm4/blob/main/relm4-examples/examples/grid_factory.rs#L133

I think, I'll link the example in the book to show how the position function can be used. gtk::Grid is so far the only widget where this is really useful, anyway.

Is the chess grid too complex or can you understand how the widgets are placed in the example?

I would remove the grid example and point to a explanation somewhere else (as you proposed)

great