# Resizable

> A panel whose edge can be dragged to resize it. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

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

:::tip[In plain words]
A panel with an edge you can drag to make it bigger or smaller.
:::

A panel whose `edge` (`"left"`, `"right"`, `"top"` or `"bottom"`) can be dragged to resize it, between `min_size` and `max_size`. It keeps the size the user drags it to; `on_resize(size)` is called when the drag ends so you can save it.

`pz.resizable` · Category: [Layout](https://albakore.github.io/pyzed/library/#layout) · [Full reference →](https://albakore.github.io/pyzed/reference/widgets/#resizable)

**Code:**

```python
t = pz.theme.current()
pz.row([
    pz.resizable(pz.container(ui.label("Drag my right edge"), padding=12, width="fill", height="fill", bg=t.panel),
                 edge="right", size=260, min_size=160, color=t.border, hover_color=t.accent),
    pz.container(ui.muted("Content"), center=True, width="fill", height="fill"),
], height="fill")
```

:::note[New]
This component was added recently. Tell us how it works for you in the [issue tracker](https://github.com/albakore/pyzed/issues).
:::

## When to use

- For one resizable sidebar or bottom panel next to fixed content.

## Usage

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

t = pz.theme.current()
pz.row([
    pz.resizable(pz.container(ui.label("Drag my right edge"), padding=12, width="fill", height="fill", bg=t.panel),
                 edge="right", size=260, min_size=160, color=t.border, hover_color=t.accent),
    pz.container(ui.muted("Content"), center=True, width="fill", height="fill"),
], height="fill")
```

## 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.
:::

### Edge

```python
t = pz.theme.current()
pz.row([pz.resizable(pz.container(ui.label("Sidebar"), padding=10, width="fill", height="fill", bg=t.panel),
                     edge="right", size=150, color=t.border), pz.container(width="fill")], height="fill")
```

```python
t = pz.theme.current()
pz.row([pz.container(width="fill"), pz.resizable(pz.container(ui.label("Inspector"), padding=10, width="fill",
        height="fill", bg=t.panel), edge="left", size=150, color=t.border)], height="fill")
```

```python
t = pz.theme.current()
pz.column([pz.container(height="fill"), pz.resizable(pz.container(ui.label("Console"), padding=10, width="fill",
           height="fill", bg=t.panel), edge="top", size=80, color=t.border)], width="fill")
```

## Events

Resizable has **1 event 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_resize` | `(size)` | Called with the new size when a drag ends. |

**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 Mail(pz.App):
    def __init__(self):
        self.width = 260

    def view(self):
        return pz.row([
            pz.resizable(ui.muted(f"{self.width:.0f} px"), edge="right", size=self.width, min_size=160,
                         on_resize=lambda size: setattr(self, "width", size)),   # when the drag ends
            main_view(),
        ], height="fill")
```

**Declarative:**

```python
from dataclasses import dataclass

@dataclass
class Width:
    size: float

class Mail(pz.App):
    width = 260

    def update(self, message):
        match message:
            case Width(size):
                self.width = size

    def view(self):
        return pz.row([pz.resizable(ui.muted("Folders"), size=self.width, on_resize=Width), main_view()],
                      height="fill")
```

**Functional:**

```python
from dataclasses import dataclass

@dataclass(frozen=True)
class State:
    width: float = 260

def view(state, set_state):
    return pz.row([pz.resizable(ui.muted("Folders"), size=state.width,
                                on_resize=lambda size: set_state(width=size)), main_view()], height="fill")
```

## Properties and API

### `pz.resizable`

```python
resizable(
    content,
    *,
    edge='right',
    size=240.0,
    min_size=80.0,
    max_size=None,
    on_resize=None,
    color=None,
    hover_color=None,
    thickness=1.0,
    handle=8.0,
    width=None,
    height=None,
)
```

A panel whose `edge` can be dragged to resize it. It keeps the size the user drags it to; `on_resize(size)` is called when a drag ends so you can save it. Changing `size` later resets it.

| Property | Default | Description |
| --- | --- | --- |
| `content` | *required* | The panel's content. |
| `edge` | `"right"` | The edge with the handle: `"right"` (a left sidebar), `"left"`, `"top"` (a bottom panel) or `"bottom"`. |
| `size` | `240.0` | Starting width (height for top/bottom edges). |
| `min_size` | `80.0` | Smallest size. |
| `max_size` | `None` | Largest size. |
| `color` | `None` | Line color. |
| `hover_color` | `None` | Line color while hovered or dragged. |
| `thickness` | `1.0` | Line thickness. |
| `handle` | `8.0` | Width of the area that can be grabbed. |
| `width` | `None` | Width for top/bottom edges. |
| `height` | `None` | Height for left/right edges. |

Events: `on_resize` ([events](#events)).

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

## Related

- [Split](https://albakore.github.io/pyzed/library/split/): Two panes with a draggable divider.
- [Panel](https://albakore.github.io/pyzed/library/panel/): A dockable, resizable side panel.
