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

Commit

Permalink
Add support for GtkOverlay and GtkProgressBar
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 2, 2024
1 parent fb5005f commit 0095086
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Documentation/Reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
- [NativeWidgetPeer](classes/NativeWidgetPeer.md)
- [NavigationSplitView](classes/NavigationSplitView.md)
- [NavigationView](classes/NavigationView.md)
- [Overlay](classes/Overlay.md)
- [OverlaySplitView](classes/OverlaySplitView.md)
- [PasswordEntryRow](classes/PasswordEntryRow.md)
- [PreferencesGroup](classes/PreferencesGroup.md)
- [PreferencesPage](classes/PreferencesPage.md)
- [PreferencesRow](classes/PreferencesRow.md)
- [PreferencesWindow](classes/PreferencesWindow.md)
- [ProgressBar](classes/ProgressBar.md)
- [Scrolled](classes/Scrolled.md)
- [SpinRow](classes/SpinRow.md)
- [Stack](classes/Stack.md)
Expand Down
22 changes: 22 additions & 0 deletions Documentation/Reference/classes/Overlay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
**CLASS**

# `Overlay`

Gtk.Overlay

## Methods
### `init()`

Initialize an overlay.

### `child(_:)`

Set the child view.
- Parameter widget: The child view.
- Returns: The overlay.

### `addOverlay(_:)`

Add an overlay to the view.
- Parameter widget: The new overlay view.
- Returns: The overlay.
16 changes: 16 additions & 0 deletions Documentation/Reference/classes/ProgressBar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**CLASS**

# `ProgressBar`

Gtk.ProgressBar

## Methods
### `init()`

Initialize a progress bar.

### `fraction(_:)`

Set the child view.
- Parameter widget: The child view.
- Returns: The overlay.
40 changes: 40 additions & 0 deletions Sources/CGTUI/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,46 @@ gtui_textview_contents (uint64_t textview)
return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
}

static uint64_t
gtui_create_overlay ()
{
return (uint64_t)gtk_overlay_new ();
}

static void
gtui_overlay_add_overlay (uint64_t overlay, uint64_t widget)
{
g_assert_nonnull (overlay);
g_assert_nonnull (widget);
g_assert (GTK_IS_OVERLAY (overlay));
g_assert (GTK_IS_WIDGET (widget));
gtk_overlay_add_overlay (overlay, widget);
}

static void
gtui_overlay_set_child (uint64_t overlay, uint64_t widget)
{
g_assert_nonnull (overlay);
g_assert_nonnull (widget);
g_assert (GTK_IS_OVERLAY (overlay));
g_assert (GTK_IS_WIDGET (widget));
gtk_overlay_set_child (overlay, widget);
}

static uint64_t
gtui_create_progressbar ()
{
return (uint64_t)gtk_progress_bar_new ();
}

static void
gtui_progressbar_set_fraction (uint64_t progressbar, double fraction)
{
g_assert_nonnull (progressbar);
g_assert (GTK_IS_PROGRESS_BAR (progressbar));
gtk_progress_bar_set_fraction (progressbar, fraction);
}

static uint64_t
gtui_create_filedialog ()
{
Expand Down
35 changes: 35 additions & 0 deletions Sources/Libadwaita/GTK/Overlay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Overlay.swift
// Libadwaita
//
// Created by david-swift on 02.01.24.
//

import CGTUI

/// Gtk.Overlay
public class Overlay: NativeWidgetPeer {

/// Initialize an overlay.
override public init() {
super.init()
self.nativePtr = gtui_create_overlay()
}

/// Set the child view.
/// - Parameter widget: The child view.
/// - Returns: The overlay.
public func child(_ widget: NativeWidgetPeer) -> Overlay {
gtui_overlay_set_child(self.nativePtr, widget.nativePtr)
return self
}

/// Add an overlay to the view.
/// - Parameter widget: The new overlay view.
/// - Returns: The overlay.
public func addOverlay(_ widget: NativeWidgetPeer) -> Overlay {
gtui_overlay_add_overlay(self.nativePtr, widget.nativePtr)
return self
}

}
27 changes: 27 additions & 0 deletions Sources/Libadwaita/GTK/ProgressBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ProgressBar.swift
// Libadwaita
//
// Created by david-swift on 02.01.24.
//

import CGTUI

/// Gtk.ProgressBar
public class ProgressBar: NativeWidgetPeer {

/// Initialize a progress bar.
override public init() {
super.init()
self.nativePtr = gtui_create_progressbar()
}

/// Set the child view.
/// - Parameter widget: The child view.
/// - Returns: The overlay.
public func fraction(_ fraction: Double) -> ProgressBar {
gtui_progressbar_set_fraction(self.nativePtr, fraction)
return self
}

}
10 changes: 9 additions & 1 deletion Tests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ public class MyApplication: Application {
NavigationView()
.add(contentView, title: "Test")
.add(
ToolbarView(StatusPage().title("Navigation View")).addTopBar(HeaderBar()),
ToolbarView(
Overlay()
.child(StatusPage().title("Navigation View"))
.addOverlay(
ProgressBar()
.fraction(0.5)
.addStyle("osd")
)
).addTopBar(HeaderBar()).topBarStyle(.raised),
title: "Navigation Page"
)
)
Expand Down

0 comments on commit 0095086

Please sign in to comment.