Set a scroll view's scroll bar policies
All checks were successful
Deploy Docs / publish (push) Successful in 20m49s
SwiftLint / SwiftLint (push) Successful in 4s

This commit is contained in:
david-swift 2024-10-26 18:44:31 +02:00
parent 356eec00a9
commit 2d12c57236
53 changed files with 143 additions and 5 deletions

View File

@ -0,0 +1,27 @@
//
// ContentFit.swift
// Adwaita
//
// Created by david-swift on 19.07.24.
//
import CAdw
/// The visibility of a scroll bar.
public enum ScrollbarVisibility: UInt32 {
/// The scrollbar is always visible. The view size is independent of the content.
case alwaysVisible
/// The scrollbar will appear and disappear as necessary.
case automatic
/// The scrollbar should never appear. In this mode the content determines the size.
case never
/// Dont show a scrollbar, but dont force the size to follow the content.
case external
/// The ScrollbarVisibility value as a GtkPolicyType value.
var gtkValue: GtkPolicyType {
.init(rawValue)
}
}

View File

@ -211,6 +211,7 @@ public struct ActionRow: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -97,6 +97,7 @@ public struct AspectFrame: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -95,6 +95,7 @@ public struct Avatar: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -104,6 +104,7 @@ public struct Banner: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -64,6 +64,7 @@ public struct Bin: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -140,6 +140,7 @@ public struct Box: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -152,6 +152,7 @@ public struct Button: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -112,6 +112,7 @@ public struct ButtonContent: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -144,6 +144,7 @@ public struct Carousel<Element>: AdwaitaWidget where Element: Identifiable {
for (index, element) in elements.enumerated() { for (index, element) in elements.enumerated() {
content(element).updateStorage(contentStorage[index], data: data, updateProperties: updateProperties, type: type) content(element).updateStorage(contentStorage[index], data: data, updateProperties: updateProperties, type: type)
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -131,6 +131,7 @@ public struct CenterBox: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -184,6 +184,7 @@ if let active, newValue != active.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -100,6 +100,7 @@ public struct Clamp: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -215,6 +215,7 @@ if let selected, newValue != selected.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -194,6 +194,7 @@ public struct EntryRow: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -219,6 +219,7 @@ if let expanded, newValue != expanded.wrappedValue {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -87,6 +87,7 @@ public struct Fixed: AdwaitaWidget {
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -256,6 +256,7 @@ public struct FlowBox<Element>: AdwaitaWidget where Element: Identifiable {
for (index, element) in elements.enumerated() { for (index, element) in elements.enumerated() {
content(element).updateStorage(contentStorage[index], data: data, updateProperties: updateProperties, type: type) content(element).updateStorage(contentStorage[index], data: data, updateProperties: updateProperties, type: type)
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -248,6 +248,7 @@ public struct HeaderBar: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -379,6 +379,7 @@ public struct Label: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -184,6 +184,7 @@ public struct LevelBar: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -168,6 +168,7 @@ public struct LinkButton: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -238,6 +238,7 @@ public struct ListBox<Element>: AdwaitaWidget where Element: Identifiable {
for (index, element) in elements.enumerated() { for (index, element) in elements.enumerated() {
content(element).updateStorage(contentStorage[index], data: data, updateProperties: updateProperties, type: type) content(element).updateStorage(contentStorage[index], data: data, updateProperties: updateProperties, type: type)
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -193,6 +193,7 @@ if let active, newValue != active.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -219,6 +219,7 @@ public struct NavigationView: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -131,6 +131,7 @@ public struct Overlay: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -245,6 +245,7 @@ if let showSidebar, newValue != showSidebar.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -155,6 +155,7 @@ public struct PasswordEntryRow: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -111,6 +111,7 @@ public struct Picture: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -179,6 +179,7 @@ public struct Popover: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -132,6 +132,7 @@ public struct PreferencesGroup: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -110,6 +110,7 @@ public struct PreferencesPage: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -84,6 +84,7 @@ public struct PreferencesRow: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -130,6 +130,7 @@ public struct ProgressBar: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -101,6 +101,11 @@ public struct ScrolledWindow: AdwaitaWidget {
var child: (() -> Body)? var child: (() -> Body)?
/// Whether to draw a frame around the contents. /// Whether to draw a frame around the contents.
var hasFrame: Bool? var hasFrame: Bool?
/// When the horizontal scrollbar is displayed.
///
/// Use [method@Gtk.ScrolledWindow.set_policy] to set
/// this property.
var hscrollbarPolicy: ScrollbarVisibility?
/// Whether kinetic scrolling is enabled or not. /// Whether kinetic scrolling is enabled or not.
/// ///
/// Kinetic scrolling only applies to devices with source %GDK_SOURCE_TOUCHSCREEN. /// Kinetic scrolling only applies to devices with source %GDK_SOURCE_TOUCHSCREEN.
@ -134,6 +139,11 @@ public struct ScrolledWindow: AdwaitaWidget {
/// This is useful in cases where an attempt should be made to allocate exactly /// This is useful in cases where an attempt should be made to allocate exactly
/// enough space for the natural size of the child. /// enough space for the natural size of the child.
var propagateNaturalWidth: Bool? var propagateNaturalWidth: Bool?
/// When the vertical scrollbar is displayed.
///
/// Use [method@Gtk.ScrolledWindow.set_policy] to set
/// this property.
var vscrollbarPolicy: ScrollbarVisibility?
/// Emitted whenever user initiated scrolling makes the scrolled /// Emitted whenever user initiated scrolling makes the scrolled
/// window firmly surpass the limits defined by the adjustment /// window firmly surpass the limits defined by the adjustment
/// in that orientation. /// in that orientation.
@ -255,6 +265,16 @@ public struct ScrolledWindow: AdwaitaWidget {
} }
if hscrollbarPolicy != (storage.previousState as? Self)?.hscrollbarPolicy
|| vscrollbarPolicy != (storage.previousState as? Self)?.vscrollbarPolicy {
gtk_scrolled_window_set_policy(
widget,
(hscrollbarPolicy ?? .automatic).gtkValue,
(vscrollbarPolicy ?? .automatic).gtkValue
)
}
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)
@ -291,6 +311,16 @@ public struct ScrolledWindow: AdwaitaWidget {
return newSelf return newSelf
} }
/// When the horizontal scrollbar is displayed.
///
/// Use [method@Gtk.ScrolledWindow.set_policy] to set
/// this property.
public func hscrollbarPolicy(_ hscrollbarPolicy: ScrollbarVisibility?) -> Self {
var newSelf = self
newSelf.hscrollbarPolicy = hscrollbarPolicy
return newSelf
}
/// Whether kinetic scrolling is enabled or not. /// Whether kinetic scrolling is enabled or not.
/// ///
/// Kinetic scrolling only applies to devices with source %GDK_SOURCE_TOUCHSCREEN. /// Kinetic scrolling only applies to devices with source %GDK_SOURCE_TOUCHSCREEN.
@ -364,6 +394,16 @@ public struct ScrolledWindow: AdwaitaWidget {
return newSelf return newSelf
} }
/// When the vertical scrollbar is displayed.
///
/// Use [method@Gtk.ScrolledWindow.set_policy] to set
/// this property.
public func vscrollbarPolicy(_ vscrollbarPolicy: ScrollbarVisibility?) -> Self {
var newSelf = self
newSelf.vscrollbarPolicy = vscrollbarPolicy
return newSelf
}
/// Emitted whenever user initiated scrolling makes the scrolled /// Emitted whenever user initiated scrolling makes the scrolled
/// window firmly surpass the limits defined by the adjustment /// window firmly surpass the limits defined by the adjustment
/// in that orientation. /// in that orientation.

View File

@ -128,6 +128,7 @@ public struct SearchBar: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -273,6 +273,7 @@ if let text, newValue != text.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -66,6 +66,7 @@ public struct Separator: AdwaitaWidget {
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -236,6 +236,7 @@ if let value, newValue != value.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -70,6 +70,7 @@ public struct Spinner: AdwaitaWidget {
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -178,6 +178,7 @@ public struct SplitButton: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -97,6 +97,7 @@ public struct StatusPage: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -180,6 +180,7 @@ if let active, newValue != active.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -91,6 +91,7 @@ public struct ToastOverlay: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -209,6 +209,7 @@ if let active, newValue != active.wrappedValue {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -224,6 +224,7 @@ public struct ToolbarView: AdwaitaWidget {
} }
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -73,6 +73,7 @@ public struct WindowTitle: AdwaitaWidget {
} }
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -85,11 +85,13 @@ struct Demo: App {
ScrollView { ScrollView {
List(Page.allCases, selection: $selection) { element in List(Page.allCases, selection: $selection) { element in
Text(element.label) Text(element.label)
.ellipsize()
.halign(.start) .halign(.start)
.padding() .padding()
} }
.sidebarStyle() .sidebarStyle()
} }
.hscrollbarPolicy(.never)
.topToolbar { .topToolbar {
HeaderBar.end { HeaderBar.end {
menu menu

View File

@ -48,7 +48,7 @@ enum Page: String, Identifiable, CaseIterable, Codable, CustomStringConvertible
case .alertDialog: case .alertDialog:
return "Alert Dialog" return "Alert Dialog"
case .passwordChecker: case .passwordChecker:
return "Password Checker" return "Password Checker is such a long name..."
default: default:
return rawValue.capitalized return rawValue.capitalized
} }

View File

@ -77,6 +77,15 @@ extension Class {
// swiftlint:enable fatal_error // swiftlint:enable fatal_error
} }
/// Generate the custom setters.
/// - Parameter config: The widget configuration.
/// - Returns: The code.
func generateManualSetters(
config: WidgetConfiguration
) -> String {
config.setters.map { "\n\($0)\n" }.joined()
}
/// Generate the assignments for the widgets and menus. /// Generate the assignments for the widgets and menus.
/// - Parameters: /// - Parameters:
/// - config: The widget configuration. /// - config: The widget configuration.

View File

@ -118,6 +118,7 @@ struct Class: ClassLike, Decodable {
\(generateBindingAssignments(config: config, genConfig: genConfig, namespace: namespace, configs: configs)) \(generateBindingAssignments(config: config, genConfig: genConfig, namespace: namespace, configs: configs))
\(generateModifications(config: config, genConfig: genConfig, namespace: namespace, configs: configs)) \(generateModifications(config: config, genConfig: genConfig, namespace: namespace, configs: configs))
\(generateDynamicWidgetUpdate(config: config, genConfig: genConfig)) \(generateDynamicWidgetUpdate(config: config, genConfig: genConfig))
\(generateManualSetters(config: config))
} }
for function in updateFunctions { for function in updateFunctions {
function(storage, data, updateProperties) function(storage, data, updateProperties)

View File

@ -240,10 +240,20 @@ struct GenerationConfiguration {
class: "ScrolledWindow", class: "ScrolledWindow",
excludeProperties: [ excludeProperties: [
"hadjustment", "hadjustment",
"hscrollbar-policy",
"vadjustment", "vadjustment",
"vscrollbar-policy",
"window-placement" "window-placement"
],
setters: [
"""
if hscrollbarPolicy != (storage.previousState as? Self)?.hscrollbarPolicy
|| vscrollbarPolicy != (storage.previousState as? Self)?.vscrollbarPolicy {
gtk_scrolled_window_set_policy(
widget,
(hscrollbarPolicy ?? .automatic).gtkValue,
(vscrollbarPolicy ?? .automatic).gtkValue
)
}
"""
] ]
), ),
.init(class: "Overlay", staticWidgets: [.init(name: "overlay", add: "gtk_overlay_add_overlay")]), .init(class: "Overlay", staticWidgets: [.init(name: "overlay", add: "gtk_overlay_add_overlay")]),
@ -298,7 +308,8 @@ struct GenerationConfiguration {
"GdkPixbuf*": "OpaquePointer", "GdkPixbuf*": "OpaquePointer",
"GdkPaintable*": "OpaquePointer", "GdkPaintable*": "OpaquePointer",
"NavigationPage": "NavigationPage", "NavigationPage": "NavigationPage",
"ContentFit": "ContentFit" "ContentFit": "ContentFit",
"PolicyType": "ScrollbarVisibility"
] ]
/// Modifications for converting a Swift into a C type. /// Modifications for converting a Swift into a C type.
@ -306,7 +317,8 @@ struct GenerationConfiguration {
"Bool": "cBool", "Bool": "cBool",
"Int": "cInt", "Int": "cInt",
"UInt": "cInt", "UInt": "cInt",
"ContentFit": "gtkValue" "ContentFit": "gtkValue",
"ScrollbarVisibility": "gtkValue"
] ]
/// Default values for modifiers with a certain type. /// Default values for modifiers with a certain type.

View File

@ -34,6 +34,8 @@ struct WidgetConfiguration {
var setConditions: [String: String] = [:] var setConditions: [String: String] = [:]
/// Properties that are set in the end of an update. /// Properties that are set in the end of an update.
var lastProperties: [String] = [] var lastProperties: [String] = []
/// Manually add setters which do not follow common practices.
var setters: [String] = []
/// The configuration for a binding. /// The configuration for a binding.
struct BindingConfiguration { struct BindingConfiguration {