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

Commit

Permalink
Update components to only accept one handler
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Dec 28, 2023
1 parent 11d0bf5 commit 3413d40
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 61 deletions.
6 changes: 1 addition & 5 deletions Documentation/Reference/classes/Banner.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Adw.Banner

## Properties
### `handlers`
### `handler`

The handlers for when the button gets clicked.

Expand All @@ -31,10 +31,6 @@ Add a handler for the banner's button.
- Parameter action: The handler.
- Returns: The banner.

### `onClick()`

Run when the button gets clicked.

### `show()`

Show the banner.
Expand Down
6 changes: 1 addition & 5 deletions Documentation/Reference/classes/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Gtk.Button

## Properties
### `handlers`
### `handler`

The action handlers.

Expand Down Expand Up @@ -49,7 +49,3 @@ Set the label for the button.

Get the button content.
- Returns: The button content.

### `onClick()`

Run when the button gets clicked.
6 changes: 1 addition & 5 deletions Documentation/Reference/classes/CheckButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Gtk.CheckButton

## Properties
### `handlers`
### `handler`

The handlers for a check button.

Expand Down Expand Up @@ -35,7 +35,3 @@ Set whether the check button is active.

Set whether the check button is in the inconsistent state.
- Parameter inconsistent: Whether the check button is in the inconsistent state.

### `onClick()`

Run this when the check button gets clicked.
6 changes: 1 addition & 5 deletions Documentation/Reference/classes/EntryRow.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Adw.EntryRow

## Properties
### `handlers`
### `handler`

The handlers for when the entry row gets submitted.

Expand Down Expand Up @@ -46,7 +46,3 @@ Get the content of the entry row.

Set the content of the entry row.
- Parameter text: The new content.

### `onSubmit()`

Execute when the text gets submitted.
6 changes: 1 addition & 5 deletions Documentation/Reference/classes/ListBox.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gtk.ListBox

The child widgets.

### `handlers`
### `handler`

Handlers for selecting rows.

Expand Down Expand Up @@ -78,7 +78,3 @@ Set the style of the list box to the sidebar style.
Add a handler for when the selection changes.
- Parameter handler: The handler.
- Returns: The list box.

### `onSelectRow()`

Run this function when a row gets selected.
6 changes: 1 addition & 5 deletions Documentation/Reference/classes/TabButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Adw.TabButton

## Properties
### `handlers`
### `handler`

The handlers of the button.

Expand All @@ -20,7 +20,3 @@ Initialize a tab button with a tab view.
Set the action handler of the tab button.
- Parameter handler: The action handler.
- Returns: The tab button.

### `onClick()`

Run when the button gets clicked.
9 changes: 3 additions & 6 deletions Sources/Libadwaita/Adwaita/Banner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CGTUI
public class Banner: NativeWidgetPeer {

/// The handlers for when the button gets clicked.
var handlers: [() -> Void] = []
var handler: () -> Void = { }
/// Whether the banner is revealed.
public var isRevealed: Bool { gtui_banner_is_revealed(self.nativePtr) != 0 }

Expand All @@ -36,13 +36,10 @@ public class Banner: NativeWidgetPeer {
/// - Parameter action: The handler.
/// - Returns: The banner.
public func buttonHandler(_ action: @escaping () -> Void) -> Banner {
handlers.append(action)
handler = action
return self
}

/// Run when the button gets clicked.
public func onClick() { for handler in handlers { handler() } }

/// Show the banner.
public func show() { gtui_banner_set_revealed(self.nativePtr, true.cBool) }

Expand All @@ -60,5 +57,5 @@ func banner_on_click_cb(
userData: UnsafeMutableRawPointer
) {
let banner = Unmanaged<Banner>.fromOpaque(userData).takeUnretainedValue()
banner.onClick()
banner.handler()
}
8 changes: 3 additions & 5 deletions Sources/Libadwaita/Adwaita/EntryRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CGTUI
public class EntryRow: PreferencesRow {

/// The handlers for when the entry row gets submitted.
var handlers: [() -> Void] = []
var handler: () -> Void = { }

/// Initialize an entry row.
/// - Parameter title: The row's title.
Expand Down Expand Up @@ -46,7 +46,7 @@ public class EntryRow: PreferencesRow {
/// - Parameter handler: The handler.
/// - Returns: The entry row.
public func submitHandler(_ handler: @escaping () -> Void) -> EntryRow {
self.handlers.append(handler)
self.handler = handler
gtui_entryrow_set_show_apply_button(self.nativePtr, true.cBool)
return self
}
Expand All @@ -68,8 +68,6 @@ public class EntryRow: PreferencesRow {
gtui_editable_set_contents(self.nativePtr, text.cString)
}

/// Execute when the text gets submitted.
public func onSubmit() { for handler in handlers { handler() } }
}

/// Handle when the entry row gets submitted.
Expand All @@ -82,5 +80,5 @@ func entryrow_on_submit_cb(
userData: UnsafeMutableRawPointer
) {
let entryrow = Unmanaged<EntryRow>.fromOpaque(userData).takeUnretainedValue()
entryrow.onSubmit()
entryrow.handler()
}
8 changes: 3 additions & 5 deletions Sources/Libadwaita/Adwaita/TabButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CGTUI
public class TabButton: NativeWidgetPeer {

/// The handlers of the button.
var handlers: [() -> Void] = []
var handler: () -> Void = { }

/// Initialize a tab button with a tab view.
/// - Parameter view: The tab view.
Expand All @@ -26,12 +26,10 @@ public class TabButton: NativeWidgetPeer {
/// - Parameter handler: The action handler.
/// - Returns: The tab button.
public func handler(_ handler: @escaping () -> Void) -> TabButton {
self.handlers.append(handler)
self.handler = handler
return self
}

/// Run when the button gets clicked.
public func onClick() { for handler in self.handlers { handler() } }
}

/// Observe when the tab button gets clicked.
Expand All @@ -44,5 +42,5 @@ func tabbutton_on_click_cb(
userData: UnsafeMutableRawPointer
) {
let button = Unmanaged<TabButton>.fromOpaque(userData).takeUnretainedValue()
button.onClick()
button.handler()
}
8 changes: 3 additions & 5 deletions Sources/Libadwaita/GTK/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
public class Button: NativeWidgetPeer {

/// The action handlers.
var handlers: [() -> Void] = []
var handler: () -> Void = { }
/// The button content, if there is no label set directly.
var content: ButtonContent?

Expand Down Expand Up @@ -49,7 +49,7 @@ public class Button: NativeWidgetPeer {
/// - Parameter handler: The button's handler.
/// - Returns: The button.
public func handler(_ handler: @escaping () -> Void) -> Button {
self.handlers.append(handler)
self.handler = handler
return self
}

Expand All @@ -61,8 +61,6 @@ public class Button: NativeWidgetPeer {
/// - Returns: The button content.
public func getContent() -> ButtonContent? { content }

/// Run when the button gets clicked.
public func onClick() { for handler in self.handlers { handler() } }
}

/// Run when the button gets clicked.
Expand All @@ -75,5 +73,5 @@ func button_on_click_cb(
userData: UnsafeMutableRawPointer
) {
let button = Unmanaged<Button>.fromOpaque(userData).takeUnretainedValue()
button.onClick()
button.handler()
}
8 changes: 3 additions & 5 deletions Sources/Libadwaita/GTK/CheckButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CGTUI
public class CheckButton: NativeWidgetPeer {

/// The handlers for a check button.
var handlers: [() -> Void] = []
var handler: () -> Void = { }

/// Initialize a check button.
/// - Parameter label: The check button's label.
Expand All @@ -26,7 +26,7 @@ public class CheckButton: NativeWidgetPeer {
/// - Parameter handler: The handler.
/// - Returns: The check button.
public func handler(_ handler: @escaping () -> Void) -> CheckButton {
self.handlers.append(handler)
self.handler = handler
return self
}

Expand All @@ -46,8 +46,6 @@ public class CheckButton: NativeWidgetPeer {
gtui_checkbutton_set_inconsistent(self.nativePtr, inconsistent.cBool)
}

/// Run this when the check button gets clicked.
public func onClick() { for handler in self.handlers { handler() } }
}

/// Run this when the check button gets clicked.
Expand All @@ -60,5 +58,5 @@ func checkbutton_on_toggle_cb(
userData: UnsafeMutableRawPointer
) {
let button = Unmanaged<CheckButton>.fromOpaque(userData).takeUnretainedValue()
button.onClick()
button.handler()
}
8 changes: 3 additions & 5 deletions Sources/Libadwaita/GTK/ListBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ListBox: NativeWidgetPeer, InsertableContainer {
/// The child widgets.
private var peers: [NativeWidgetPeer] = []
/// Handlers for selecting rows.
var handlers: [() -> Void] = []
var handler: () -> Void = { }

override public init() {
super.init()
Expand Down Expand Up @@ -124,12 +124,10 @@ public class ListBox: NativeWidgetPeer, InsertableContainer {
/// - Parameter handler: The handler.
/// - Returns: The list box.
public func handler(_ handler: @escaping () -> Void) -> Self {
self.handlers.append(handler)
self.handler = handler
return self
}

/// Run this function when a row gets selected.
func onSelectRow() { for handler in handlers { handler() } }
}

/// Run this function when a row gets selected.
Expand All @@ -144,5 +142,5 @@ func listbox_on_select_row_cb(
userData: UnsafeMutableRawPointer
) {
let box = Unmanaged<ListBox>.fromOpaque(userData).takeUnretainedValue()
box.onSelectRow()
box.handler()
}

0 comments on commit 3413d40

Please sign in to comment.