Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ttytm/osdialog-odin

Cross-platform utility module for Odin to open native dialogs for the filesystem, message boxes, color-picking.
https://github.com/ttytm/osdialog-odin

bindings cross-platform dialog filesys linux macos native osx windows wrapper-library

Last synced: 28 days ago
JSON representation

Cross-platform utility module for Odin to open native dialogs for the filesystem, message boxes, color-picking.

Awesome Lists containing this project

README

        

# osdialog-odin

[badge__build-status]: https://img.shields.io/github/actions/workflow/status/ttytm/osdialog-odin/ci.yml?branch=main&logo=github&logoColor=C0CAF5&labelColor=333
[badge__version-lib]: https://img.shields.io/github/v/tag/ttytm/osdialog-odin?logo=task&logoColor=C0CAF5&labelColor=333&color=

[![][badge__build-status]](https://github.com/ttytm/osdialog-odin/actions?query=branch%3Amain)
[![][badge__version-lib]](https://github.com/ttytm/osdialog-odin/releases/latest)

Cross-platform utility library for Odin to open native dialogs for the filesystem, message boxes, color-picking.

## Quickstart

- [Installation](#installation)
- [Usage](#usage)
- [Example](#example)
- [Credits](#credits)

## Showcase


Linux
Windows
macOS



Linux File Dialog


Windows File Dialog


macOS File Dialog

More Examples Toggle visibility...


Linux
Windows
macOS



Linux Color Picker GTK3
Linux Message
Linux Message with Yes and No Buttons
Linux Input Prompt
Linux Color Picker GTK2


Windows Color Picker
Windows Message
Windows Message with Yes and No Buttons
Windows Input Prompt


macOS Color Picker

macOS Message with Yes and No Buttons
macOS Input Prompt

## Installation

1. Add it as a submodule to your Odin Git project

```sh
# /your-awesome-odin-project
git submodule add https://github.com/ttytm/osdialog-odin.git osdialog
```

2. Prepare the C Binding

_Unix-like_

```sh
cd osdialog && make && cd -
```

_Windows_

```sh
cd osdialog
nmake
cd ..
```

## Usage

Ref.: [`osdialog-odin/osdialog.odin`](https://github.com/ttytm/osdialog-odin/blob/main/osdialog.odin)

```odin
// Opens a message box and returns `true` if `OK` or `Yes` was pressed.
message :: proc(message: string, level: MessageLevel = .Info, buttons: MessageButtons = .Ok) -> bool

// Opens an input prompt with an "OK" and "Cancel" button.
// Returns the entered text and `true`, or `false` if the dialog was cancelled.
// `text` optionally sets initial content of the input box.
prompt :: proc(message: string, text: string = "", level: MessageLevel = .Info) -> (string, bool) #optional_ok

// Opens a file dialog and returns the selected path and `true` or `false` if the selection was canceled.
path :: proc(action: PathAction, path: string = "", filename: string = "") -> (string, bool) #optional_ok

// Opens an RGBA color picker and returns the selected `Color` and `true`, or `false` if the selection was canceled.
// Optionally, it takes a `color` and `opacity` argument. `color` sets the dialogs initial color. `opacity` can be
// set to `false` to disable the opacity slider on unix-like systems. It has no effect on Windows.
color :: proc(color: Color = {255, 255, 255, 255}, opacity: bool = true) -> (Color, bool) #optional_ok
```

### Example

Ref.: [`osdialog-odin/examples/main.odin`](https://github.com/ttytm/osdialog-odin/blob/main/examples/main.odin)

```odin
package main

import osd "osdialog"
import "core:fmt"

main :: proc() {
osd.message("Hello, World!")

input := osd.prompt("Give me some input")
fmt.println("Input:", input)

if color, ok := osd.color(); ok {
fmt.println("Selected color", color)
}

if path, ok := osd.path(.Open); ok {
fmt.println("Selected file:", path)
}

if path, ok := osd.path(.Open_Dir); ok {
fmt.println("Selected dir", path)
}

if path, ok := osd.path(.Save); ok {
fmt.println("Selected save path", path)
}
}
```

For a simple local run:

_Unix-like_

One-shot copy pasta to perform a lighter, filtered development clone and build the C binding target.

```sh
git clone --recursive --filter=blob:none --also-filter-submodules \
https://github.com/ttytm/osdialog-odin \
&& cd osdialog-odin && make
```

_Windows_

```sh
git clone --recursive --filter=blob:none --also-filter-submodules https://github.com/ttytm/osdialog-odin
```

```sh
cd osdialog-odin
nmake
```

Run the example

```sh
odin run examples/main.odin -file
```

## Credits

- [AndrewBelt/osdialog](https://github.com/AndrewBelt/osdialog) - The C project this library is leveraging