Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set Window Flags #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions examples/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"github.com/raff/ultralight-go"
)

func main() {
app := ultralight.NewApp()
defer app.Destroy()

window := app.NewWindow(800, 600, false, "Window", ultralight.WindowFlagBorderless|ultralight.WindowFlagResizable)
defer window.Destroy()

window.View().LoadHTML(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<p>This window has no border!</p>
<p onclick="close()">click me to close the window!</p>
</div>
</body>
</html>`)

window.View().JSContext().GlobalObject().SetPropertyValue("close", func(f, this *ultralight.JSObject, args ...*ultralight.JSValue) *ultralight.JSValue {
app.Quit()
return nil
})

window.Focus()
app.Run()
}
39 changes: 32 additions & 7 deletions ultralight.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ static inline JSObjectRef make_function_callback(JSContextRef ctx, JSStringRef n
}
*/
import "C"
import "unsafe"
import "unicode/utf16"
import "unicode/utf8"
import "reflect"
import "bytes"

import "log"
import (
"bytes"
"log"
"reflect"
"unicode/utf16"
"unicode/utf8"
"unsafe"
)

type JSType int

Expand Down Expand Up @@ -212,6 +213,15 @@ const (
CursorCustom = Cursor(C.kCursor_Custom)
)

type WindowFlag uint

const (
WindowFlagBorderless = WindowFlag(C.kWindowFlags_Borderless)
WindowFlagTitled = WindowFlag(C.kWindowFlags_Titled)
WindowFlagResizable = WindowFlag(C.kWindowFlags_Resizable)
WindowFlagMaximizable = WindowFlag(C.kWindowFlags_Maximizable)
)

// App is the main application object
type App struct {
app C.ULApp
Expand Down Expand Up @@ -385,6 +395,21 @@ func (app *App) NewWindow(width, height uint, fullscreen bool, title string) *Wi
return win
}

//NewWindowUsingFlags creates a new window and allows you to set your own window flags.
func (app *App) NewWindowUsingFlags(width, height uint, fullscreen bool, title string, flags WindowFlag) *Window {
win := &Window{win: C.ulCreateWindow(C.ulAppGetMainMonitor(app.app),
C.uint(width), C.uint(height),
C.bool(fullscreen),
C.uint(flags)),
app: app}

C.ulAppSetWindow(app.app, win.win)

win.SetTitle(title)
win.NewOverlay(width, height, 0, 0)
return win
}

// Destroy destroys the window.
func (win *Window) Destroy() {
delete(win.app.windows, win.win)
Expand Down