GithubHelp home page GithubHelp logo

spytheman / dialog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ttytm/dialog

0.0 1.0 0.0 50 KB

A cross-platform utility library for V to open system dialogs - open files, message boxes, color-pickers etc.

Home Page: https://ttytm.github.io/dialog/

License: MIT License

V 100.00%

dialog's Introduction

dialog

A cross-platform utility library for V to open system dialogs - open files, message boxes, color-pickers etc.

Showcase

Linux Windows macOS
Linux File Dialog Windows File Dialog macOS File Dialog
Toggle More
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 Message macOS Message with Yes and No Buttons macOS Input Prompt

Installation

v install --git https://github.com/ttytm/dialog

On macOS, dialog currently uses V webview to ensure it can interop with system windows.

# macOS only dependency
v install --git https://github.com/ttytm/webview
~/.vmodules/webview/build.vsh

Usage

// message launches a message box and returns `true` if `OK` or `Yes` was pressed.
pub fn message(message string, opts MessageOptions) bool

// prompt launches an input prompt with an "OK" and "Cancel" button.
pub fn prompt(message string, opts PromptOptions) ?string

// file_dialog opens a file dialog and returns the selected path or `none` if the selection was canceled.
pub fn file_dialog(opts FileDialogOptions) ?string

// open_file opens a file dialog and returns the `os.File` of the selected file.
// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.
// It returns an error if the selection was cancelled or if reading the file fails.
pub fn open_file(opts FileOpenOptions) !os.File

// read_file opens a file dialog and reads the file contents of the selected file.
// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.
// It returns an error if the selection was cancelled or if reading the file fails.
pub fn read_file(opts FileOpenOptions) !string

// open_dir opens a file dialog and returns the path of the selected directory and a list of its contents.
// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.
// It returns an error if the selection was cancelled or if reading the directory contents fails.
pub fn open_dir(opts FileOpenOptions) !(string, []string)

// save_file opens a file dialog and saves the given content to the selected path.
// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.
// `filename` can be provided to set the default text that will appear in the filename input.
// It returns an error if the selection was canceled or if writing the file fails.
pub fn save_file(opts FileSaveOptions) !

// color_picker opens an RGBA color picker dialog and returns the selected color or `none` 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 Linux.
pub fn color_picker(opts ColorPickerOptions) ?Color

Note v doc provides an overview of all public definitions.
Use v doc -comments dialog.src in the terminal, or refer to the module's doc pages in the browser.

Example

module main

import dialog

dialog.message('Thanks for using dialog!')

if !dialog.message('Do you want to continue?', buttons: .yes_no) {
	dump('Canceled!')
}

input := dialog.prompt('What is your pets name?')
dump(input)

selected_file := dialog.file_dialog()
dump(selected_file)

selected_color := dialog.color_picker()
dump(selected_color)
v run examples/minimal.v

Note When running and building on Windows, it is recommended to use gcc for compilation. E.g.:

v -cc gcc run examples/minimal.v

Disclaimer

The project is made public in an early stage. Best practices and quality will be paramount throughout development, but it may undergo drastic changes while maturing.

If the library could already achieve it's goal of also helping your project, or just to share some love, filling the โ˜† of this repo with color will warm the heart of your fellow developer.

Credits

  • AndrewBelt/osdialog - C project that dialog binds to.
  • vlang/v - Simple-to-use, developer-friendly system programming with high interoperability.

dialog's People

Contributors

ttytm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.