# Breadcrumbs

> `src › main.rs › fn main`, optionally clickable. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/breadcrumbs/

:::tip[In plain words]
Shows where you are, step by step: Folder › Subfolder › File.
:::

The path to the current location. Parts are strings or `(icon, text)` tuples; `on_press` receives the index of the clicked part.

`ui.breadcrumbs` · Category: [Navigation](https://albakore.github.io/pyzed/library/#navigation) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#breadcrumbs)

**Code:**

```python
pz.column([
    ui.breadcrumbs(["src", "ui", "button.rs"]),
    ui.breadcrumbs([("folder", "src"), ("file-code", "main.rs"), "fn main"], on_press=on_press),
    ui.breadcrumbs(["Settings", "Editor", "Font"], separator="/"),
], spacing=14)
```

## When to use

- Above an editor or a nested view, to show where you are and jump to a parent.

## Usage

```python
import pyzed as pz
from pyzed import ui

pz.column([
    ui.breadcrumbs(["src", "ui", "button.rs"]),
    ui.breadcrumbs([("folder", "src"), ("file-code", "main.rs"), "fn main"], on_press=on_press),
    ui.breadcrumbs(["Settings", "Editor", "Font"], separator="/"),
], spacing=14)
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in One Dark or One Light to match this site's theme, and cropped to the component so it shows at its real size. The pointer hovers, presses or types into it; a component that does not react to the pointer cycles through a few themes. With reduced motion you see the first frame. Open **Code** under a capture to see the snippet that draws it; free names such as `on_save` stand for your own callbacks.
:::

### Options

```python
ui.breadcrumbs(["src", "ui", "button.rs"])
```

```python
ui.breadcrumbs([("folder", "src"), ("file-code", "main.rs"), "fn main"])
```

```python
ui.breadcrumbs(["Settings", "Editor", "Font"], separator="/")
```

```python
ui.breadcrumbs(["Home", "Projects", "pyzed"], on_press=on_press)
```

### States and events

```python
ui.breadcrumbs(["pyzed", "python", "pyzed", "ui", "lists.py"], max_items=3, on_press=on_press, on_more=on_more)
```

## Events

Breadcrumbs has **2 events of its own**, listed below. Like every widget it also has the **18 common events** (`click`, `double_click`, `right_click`, `mouse_enter`, `drag`, `key_down`, `resize`…), attached with `.on(...)`: see [Events](https://albakore.github.io/pyzed/guides/events/) and [Events of every component](https://albakore.github.io/pyzed/library/events/).

| Event | Handler gets | When |
| --- | --- | --- |
| `on_press` | `(index)` | Called with the index of the clicked part. |
| `on_more` | `()` | Makes the `…` clickable. |

**Handler gets** is what Pyzed passes to your callable: `()` means nothing. Any handler can also be a message (a value that is not callable), which goes to `update()`.

### Handling the events

The same events written three ways. **Imperative**: methods of the app change `self`. **Declarative**: the handlers produce messages and one `update()` decides. **Functional**: a pure function draws an immutable state and asks for changes with `set_state(...)`. See [Imperative, declarative and functional](https://albakore.github.io/pyzed/guides/code-styles/).

**Imperative:**

```python
class Browser(pz.App):
    def __init__(self):
        self.path = ["home", "ada", "projects", "pyzed"]

    def go(self, index):                 # on_press: the index of the clicked part
        self.path = self.path[:index + 1]

    def view(self):
        return ui.breadcrumbs(self.path, on_press=self.go, max_items=3,
                              on_more=lambda: self.go(0))   # the … of the hidden parts
```

**Declarative:**

```python
from dataclasses import dataclass

@dataclass
class GoTo:
    index: int

class Browser(pz.App):
    path = ["home", "ada", "projects", "pyzed"]

    def update(self, message):
        match message:
            case GoTo(index):
                self.path = self.path[:index + 1]

    def view(self):
        return ui.breadcrumbs(self.path, on_press=GoTo)
```

**Functional:**

```python
from dataclasses import dataclass

@dataclass(frozen=True)
class State:
    path: tuple = ("home", "ada", "projects", "pyzed")

def view(state, set_state):
    return ui.breadcrumbs(list(state.path), on_press=lambda i: set_state(path=state.path[:i + 1]))
```

## Properties and API

### `ui.breadcrumbs`

```python
breadcrumbs(
    parts,
    *,
    separator='›',
    on_press=None,
    max_items=None,
    on_more=None,
    theme=None,
)
```

`src › main.rs › fn main`. Parts can be strings or `(icon, text)` tuples.

| Property | Default | Description |
| --- | --- | --- |
| `parts` | *required* | The parts. |
| `separator` | `"›"` | Separator. |
| `max_items` | `None` | Keeps the first part and the last ones and shows `…` for the rest. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

Events: `on_press`, `on_more` ([events](#events)).

[Full reference →](https://albakore.github.io/pyzed/reference/ui/#breadcrumbs)

## Related

- [Toolbar](https://albakore.github.io/pyzed/library/toolbar/): The bar under the tabs: breadcrumbs and buffer actions.
- [Tab bar](https://albakore.github.io/pyzed/library/tab-bar/): Editor tabs with icons, dirty dots and close buttons.
