Skip to content

donaldfilimon/gama

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Gama

A comprehensive multi-platform GUI framework for Swift, supporting Windows, macOS, iOS, Linux, and Android.

πŸš€ Features

  • Cross-platform: Unified API across Windows, macOS, iOS, Linux, and Android
  • Native performance: Direct platform API integration (WinSDK, AppKit, UIKit, GTK, Android SDK)
  • Swift-friendly: Modern Swift interfaces with type safety and memory management
  • RAII design: Automatic resource cleanup using Swift's defer and ARC
  • Comprehensive: Windows, graphics, controls, input, dialogs, and system utilities
  • Extensible: Platform abstraction layer allows easy addition of new platforms

πŸ“‹ Platform Support Matrix

Feature Windows macOS iOS/iPadOS Linux Android
Windows βœ… Full βœ… AppKit βœ… UIKit 🚧 GTK 🚧 JNI
Graphics βœ… GDI+ βœ… Core Graphics βœ… Core Graphics 🚧 Cairo 🚧 Canvas
Controls βœ… Win32 βœ… AppKit βœ… UIKit 🚧 GTK 🚧 Views
Input βœ… Win32 βœ… NSEvent βœ… UIEvent 🚧 GDK 🚧 MotionEvent
Dialogs βœ… Win32 βœ… NSAlert βœ… UIAlert 🚧 GTK 🚧 AlertDialog
System βœ… Win32 βœ… NSProcessInfo βœ… UIDevice 🚧 POSIX 🚧 System
Timers βœ… Win32 🚧 Foundation 🚧 Foundation 🚧 GLib 🚧 Handler
Build βœ… MSVC βœ… Xcode βœ… Xcode βœ… GCC/Clang 🚧 NDK

βœ… = Fully implemented | 🚧 = Stub implementation ready for enhancement

πŸ—οΈ Architecture

Gama uses a platform abstraction layer:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Public API    β”‚  ← Window, WindowProtocol, WindowFactory
β”‚   (Unified)     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Platform Layer  β”‚  ← WindowsWindow, AppleWindow, LinuxWindow, AndroidWindow
β”‚ (Platform-specific)|
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Core Types     β”‚  ← Point, Size, Rectangle, Color (cross-platform)
β”‚  (Shared)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Installation

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/yourorg/gama", from: "1.0.0")
]

πŸš€ Quick Start

Basic Window Creation

import Gama

// Works on all platforms!
let window = try Window(
    title: "My App",
    size: Size(width: 800, height: 600)
)

window.show()

Platform-Specific Code

import Gama

// Platform detection
if isWindows {
    // Windows-specific code
} else if isApple {
    // macOS/iOS code
} else if isLinux {
    // Linux code
}

// Safe platform checks
try ensurePlatformSupport(for: "graphics", supported: hasGraphicsSupport)

Event Handling

class MyDelegate: WindowDelegate {
    func windowWillClose(_ window: WindowProtocol) -> Bool {
        // Return false to prevent closing
        return false
    }

    func windowDidResize(_ window: WindowProtocol, size: Size) {
        print("Window resized to: \(size.width) x \(size.height)")
    }
}

let window = try Window(title: "Events Demo")
window.setDelegate(MyDelegate())

🎨 Graphics

// Cross-platform graphics (when implemented)
let graphics = try AppleGraphics(width: 800, height: 600)
graphics.setFillColor(.blue)
graphics.fillRectangle(Rectangle(left: 0, top: 0, right: 400, height: 300))

πŸŽ›οΈ Controls

// Platform-specific controls
#if os(macOS)
let button = AppleButton(title: "Click Me")
button.setAction(self, action: #selector(buttonClicked))
#endif

πŸ”§ Development

Building

# Windows
swift build

# macOS/iOS
swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macos12"

# Linux
swift build

Testing

swift test

Examples

See Examples/ directory for platform-specific demos:

  • MultiPlatformDemo - Basic window and event demonstration

πŸ“š Documentation

🀝 Contributing

  1. Platform Implementation: Add support for new platforms by implementing the platform protocols
  2. Feature Enhancement: Extend existing platform implementations
  3. Testing: Add cross-platform tests
  4. Documentation: Update platform support matrix and guides

Adding a New Platform

  1. Create Platform/NewPlatform/ directory
  2. Implement WindowProtocol with NewPlatformWindow
  3. Add platform detection in Core/Platform.swift
  4. Update WindowFactory to instantiate your implementation
  5. Add to build system and documentation

πŸ“„ License

See LICENSE.md for details.

πŸ™ Acknowledgments

  • Windows implementation based on WinSDK
  • Apple implementation uses AppKit/UIKit and Core Graphics
  • Linux implementation designed for GTK4 and Cairo
  • Android implementation designed for JNI bridge

Releases

No releases published

Packages

 
 
 

Contributors

Languages