Skip to content

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

License

Notifications You must be signed in to change notification settings

ttytm/osdialog-odin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

osdialog-odin

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

Quickstart

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

    # <projects-path>/your-awesome-odin-project
    git submodule add https://github.com/ttytm/osdialog-odin.git osdialog
  2. Prepare the C Binding

    Unix-like

    cd osdialog && make && cd -

    Windows

    cd osdialog
    nmake
    cd ..

Usage

Ref.: osdialog-odin/osdialog.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 and returns the entered text and `true`,
// or `false` if the dialog was cancelled. `text` optionally sets the 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

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.

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

Windows

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

Run the example

odin run examples/main.odin -file

Credits

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published