Skip to content

Commit 4b100fd

Browse files
committed
Module documentation for components
1 parent 1b81acf commit 4b100fd

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/components/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
/*!
2+
Components are the visible building blocks in gitui.
3+
4+
They have a state, handle events, and render to the terminal:
5+
6+
* Some are full screen. That would be all the [`tabs`](super::tabs).
7+
* Some look like panels, eg [`CommitDetailsComponent`]
8+
* Some overlap others. They are collected in module [`popups`](super::popups)
9+
* Some are decorations, eg [`HorizontalScroll`](utils::scroll_horizontal::HorizontalScroll).
10+
11+
Components can be reused.
12+
For example, [`CommitList`] is used in both tab "revlog" and tab "stashlist".
13+
14+
15+
## Composition
16+
17+
In gitui, composition is driven by code. This means each component must
18+
have code that explicitly forwards component function calls like draw,
19+
commands and event to the components it is composed of.
20+
21+
Other systems use composition by data: They provide a generic data structure
22+
that reflects the visual hierarchy, and uses it at runtime to
23+
determine which code should be executed. This is not how gitui works.
24+
25+
## Traits
26+
27+
There are two traits defined here:
28+
* [`Component`] handles events from the user,
29+
* [`DrawableComponent`] renders to the terminal.
30+
31+
In the current codebase these are always implemented together, and it probably
32+
makes more sense to merge them some time in the future.
33+
It is a little strange that you implement `draw()` on a `DrawableComponent`,
34+
but have function `hide()` from trait Component which does not know how
35+
to `draw()`.
36+
*/
37+
138
mod changes;
239
mod command;
340
mod commit_details;

0 commit comments

Comments
 (0)