Skip to content

Commit

Permalink
feat: add revealer widget
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborzek committed Dec 30, 2023
1 parent c9abafa commit 0bd781b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,34 @@ label = Label(
)
```

## Revealer

A widget that can reveal its child.

**Properties**

| Property | Type | Description |
| --------------------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| `reveal_child` | `bool` | Whether the child is revealed or not. |
| `transition_duration` | `int` | The duration of the transition in milliseconds. |
| `transition_type` | [`Gtk.RevealerTransitionType`](https://lazka.github.io/pgi-docs/Gtk-3.0/enums.html#Gtk.RevealerTransitionType) | The type of the transition. |
| `child` | [`Gtk.Widget`](https://lazka.github.io/pgi-docs/index.html#Gtk-3.0/classes/Widget.html#Gtk.Widget) | The child of the revealer. |

**Example**

```python
from sora.widgets.revealer import Revealer, RevealerProps

revealer = Revealer(
RevealerProps(
reveal_child=True,
transition_duration=500,
transition_type=Gtk.RevealerTransitionType.CROSSFADE,
child=Label(LabelProps(label="Hello, world!")),
),
)
```

## Slider

A slider widget.
Expand Down
35 changes: 35 additions & 0 deletions sora/widgets/revealer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from dataclasses import dataclass

from sora.widgets.base import BaseWidget, BaseWidgetProps
from sora.widgets.bind import Bindable

from gi.repository import Gtk


@dataclass(kw_only=True)
class RevealerProps(BaseWidgetProps):
"""
Properties for the Revealer widget.
:param reveal_child: Whether the child is revealed.
:param transition_duration: The duration of the transition in milliseconds.
:param transition_type: The type of the transition animation.
:param child: The child widget.
"""

reveal_child: Bindable[bool] = False
transition_duration: Bindable[int] = 1000
transition_type: Bindable[
Gtk.RevealerTransitionType
] = Gtk.RevealerTransitionType.NONE
child: Bindable[Gtk.Widget] | None = None


class Revealer(BaseWidget(Gtk.Revealer), Gtk.Revealer):
def __init__(self, props: RevealerProps):
super().__init__(props)

self._bind_property("reveal_child", props.reveal_child)
self._bind_property("transition_duration", props.transition_duration)
self._bind_property("transition_type", props.transition_type)
self._bind_property("child", props.child)

0 comments on commit 0bd781b

Please sign in to comment.