Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Add support for popovers
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Feb 10, 2024
1 parent b4e88a4 commit 3048219
Show file tree
Hide file tree
Showing 46 changed files with 557 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Documentation/Reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- [Overlay](structs/Overlay.md)
- [OverlaySplitView](structs/OverlaySplitView.md)
- [PasswordEntryRow](structs/PasswordEntryRow.md)
- [Popover](structs/Popover.md)
- [PreferencesGroup](structs/PreferencesGroup.md)
- [PreferencesPage](structs/PreferencesPage.md)
- [PreferencesRow](structs/PreferencesRow.md)
Expand Down Expand Up @@ -120,6 +121,7 @@
- [OpaquePointer](extensions/OpaquePointer.md)
- [OverlaySplitView](extensions/OverlaySplitView.md)
- [PasswordEntryRow](extensions/PasswordEntryRow.md)
- [Popover](extensions/Popover.md)
- [ProgressBar](extensions/ProgressBar.md)
- [ScrollView](extensions/ScrollView.md)
- [Set](extensions/Set.md)
Expand Down
9 changes: 9 additions & 0 deletions Documentation/Reference/extensions/Popover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**EXTENSION**

# `Popover`

## Methods
### `init(visible:)`

Initialize either a horizontal or vertical clamp.
- Parameter vertical: Whether it is a vertical clamp.
8 changes: 8 additions & 0 deletions Documentation/Reference/extensions/View.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ Set the view's visibility.
Remove all of the content modifiers for the wrapped views.
- Returns: A view.

### `popover(visible:content:)`

Add a popover on top of the view.
- Parameters:
- visible: Whether the popover is displayed.
- content: The popover's content.
- Returns: The view.

### `toast(_:signal:)`

Present a toast when the signal gets activated.
Expand Down
172 changes: 172 additions & 0 deletions Documentation/Reference/structs/Popover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
**STRUCT**

# `Popover`

`GtkPopover` is a bubble-like context popup.

![An example GtkPopover](popover.png)

It is primarily meant to provide context-dependent information
or options. Popovers are attached to a parent widget. By default,
they point to the whole widget area, although this behavior can be
changed with [method@Gtk.Popover.set_pointing_to].

The position of a popover relative to the widget it is attached to
can also be changed with [method@Gtk.Popover.set_position]

By default, `GtkPopover` performs a grab, in order to ensure input
events get redirected to it while it is shown, and also so the popover
is dismissed in the expected situations (clicks outside the popover,
or the Escape key being pressed). If no such modal behavior is desired
on a popover, [method@Gtk.Popover.set_autohide] may be called on it to
tweak its behavior.

## GtkPopover as menu replacement

`GtkPopover` is often used to replace menus. The best was to do this
is to use the [class@Gtk.PopoverMenu] subclass which supports being
populated from a `GMenuModel` with [ctor@Gtk.PopoverMenu.new_from_model].

```xml
<section><attribute name="display-hint">horizontal-buttons</attribute><item><attribute name="label">Cut</attribute><attribute name="action">app.cut</attribute><attribute name="verb-icon">edit-cut-symbolic</attribute></item><item><attribute name="label">Copy</attribute><attribute name="action">app.copy</attribute><attribute name="verb-icon">edit-copy-symbolic</attribute></item><item><attribute name="label">Paste</attribute><attribute name="action">app.paste</attribute><attribute name="verb-icon">edit-paste-symbolic</attribute></item></section>
```

# CSS nodes

```
popover.background[.menu]
├── arrow
╰── contents
╰── <child>
```

`GtkPopover` has a main node with name `popover`, an arrow with name `arrow`,
and another node for the content named `contents`. The `popover` node always
gets the `.background` style class. It also gets the `.menu` style class
if the popover is menu-like, e.g. is a [class@Gtk.PopoverMenu].

Particular uses of `GtkPopover`, such as touch selection popups or
magnifiers in `GtkEntry` or `GtkTextView` get style classes like
`.touch-selection` or `.magnifier` to differentiate from plain popovers.

When styling a popover directly, the `popover` node should usually
not have any background. The visible part of the popover can have
a shadow. To specify it in CSS, set the box-shadow of the `contents` node.

Note that, in order to accomplish appropriate arrow visuals, `GtkPopover`
uses custom drawing for the `arrow` node. This makes it possible for the
arrow to change its shape dynamically, but it also limits the possibilities
of styling it using CSS. In particular, the `arrow` gets drawn over the
`content` node's border and shadow, so they look like one shape, which
means that the border width of the `content` node and the `arrow` node should
be the same. The arrow also does not support any border shape other than
solid, no border-radius, only one border width (border-bottom-width is
used) and no box-shadow.

## Properties
### `updateFunctions`

Additional update functions for type extensions.

### `appearFunctions`

Additional appear functions for type extensions.

### `autohide`

Whether to dismiss the popover on outside clicks.

### `cascadePopdown`

Whether the popover pops down after a child popover.

This is used to implement the expected behavior of submenus.

### `child`

The child widget.

### `defaultWidget`

The default widget inside the popover.

### `hasArrow`

Whether to draw an arrow.

### `mnemonicsVisible`

Whether mnemonics are currently visible in this popover.

### `activateDefault`

Emitted whend the user activates the default widget.

This is a [keybinding signal](class.SignalAction.html).

### `closed`

Emitted when the popover is closed.

### `app`

The application.

### `window`

The window.

## Methods
### `init()`

Initialize `Popover`.

### `container(modifiers:)`

Get the widget's view storage.
- Parameter modifiers: The view modifiers.
- Returns: The view storage.

### `update(_:modifiers:updateProperties:)`

Update the widget's view storage.
- Parameters:
- storage: The view storage.
- modifiers: The view modifiers.
- updateProperties: Whether to update the view's properties.

### `autohide(_:)`

Whether to dismiss the popover on outside clicks.

### `cascadePopdown(_:)`

Whether the popover pops down after a child popover.

This is used to implement the expected behavior of submenus.

### `child(_:)`

The child widget.

### `defaultWidget(_:)`

The default widget inside the popover.

### `hasArrow(_:)`

Whether to draw an arrow.

### `mnemonicsVisible(_:)`

Whether mnemonics are currently visible in this popover.

### `activateDefault(_:)`

Emitted whend the user activates the default widget.

This is a [keybinding signal](class.SignalAction.html).

### `closed(_:)`

Emitted when the popover is closed.
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/ActionRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ActionRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Avatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Avatar.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Banner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Banner.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Bin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Bin.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Box.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Button.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/ButtonContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ButtonContent.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Carousel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Carousel.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/CenterBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CenterBox.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/CheckButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CheckButton.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Clamp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Clamp.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/ComboRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ComboRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/EntryRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// EntryRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/ExpanderRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ExpanderRow.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/HeaderBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// HeaderBar.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Label.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/LevelBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// LevelBar.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/LinkButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// LinkButton.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/ListBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ListBox.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adwaita/View/Generated/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Menu.swift
// Adwaita
//
// Created by auto-generation on 04.02.24.
// Created by auto-generation on 10.02.24.
//

import CAdw
Expand Down
Loading

0 comments on commit 3048219

Please sign in to comment.