Coder Social home page Coder Social logo

iup-go's Introduction

iup-go

Build Status Go Reference

Go bindings for IUP, a multi-platform toolkit for building graphical user interfaces. The toolkit provides system native UI controls for Windows, Linux (GTK+), and macOS.

IUP C source code is included and compiled together with bindings. Note that the first build can take a few minutes.

Requirements

Go 1.18 is minimum required version (cgo.Handle, any, new style build tags).

Windows

On Windows, you need a C compiler, like Mingw-w64 or TDM-GCC. You can also build a binary in MSYS2 shell.

Note that Windows manifest is included in the build by default. IUP controls appearance will follow the system appearance only if the manifest is used. If not using the manifest, it will always look like Windows XP Classic. See below how to disable manifest if you want to include your own.

  • To remove console window, i.e., compile GUI app, build with -ldflags "-H=windowsgui".
  • You can add icon resource to .exe file with the rsrc tool.

windows

Linux

On Linux, you need a C compiler and GTK+ development packages.

  • Debian/Ubuntu: apt-get install libgtk-3-dev
  • RedHat/Fedora: dnf install gtk3-devel

When you are not using gl tag, the library is built with GDK_NULL to completely remove the X11 usage, so it should just work in Wayland.

You may provide explicit compiler and linker flags instead of using the defaults provided by pkg-config, if gtk3 and other dependencies are in a non-standard location:

CGO_CFLAGS="-I<include path> ..." CGO_LDFLAGS="-L<dir> -llib ..." go build -tags nopkconfig

Note that you can also build and link against the GTK2 version, see build tags below.

linux

macOS

On macOS, you need Xcode or Command Line Tools for Xcode.

Note that support for Cocoa is a work in progress. Not everything is implemented. If you can help with Cocoa or GLCanvas, please join the IUP mailing list. Also note that you must use and distribute binary in the .app directory, together with .nib compiled resources, see example.app.

You can also build for GTK+ in macOS, with gtk build tag. It will use Quartz native rendering. See screenshot, .app is not required with GTK+.

Install GTK+ development packages with brew.

  • brew install gtk+3

darwin

Other

Although not tested, the library should work on other Unix-like systems, FreeBSD, NetBSD, OpenBSD, DragonFly, Solaris, Illumos, and AIX.

You can also compile for time-tested Motif library if GTK+ is not available, though not all controls and attributes are possible, check the documentation for details.

  • Debian/Ubuntu: apt-get install libmotif-dev libxmu-dev libxpm-dev
  • RedHat/Fedora: dnf install motif-devel libXpm-devel

motif

Build tags

  • gl - build with support for GLCanvas (Windows and Linux)
  • gtk - use GTK+ in macOS or Windows
  • gtk2 - link with GTK2 version, default is GTK3 (Linux)
  • motif - build for X11/Motif 2.x environment
  • nomanifest - do not include manifest in Windows build
  • nopkgconfig - do not use pkg-config for compile and link flags. User specifies CGO_CFLAGS and CGO_LDFLAGS env vars

Documentation

IUP documentation is nice, every Go function in doc reference there. Also check Go Reference and Examples.

Thread-Safety

User interface (and OpenGL) is usually not thread-safe and IUP is not thread-safe. Some platforms enforce running UI on the main thread. Note that a goroutine can arbitrarily and randomly be scheduled or rescheduled on different running threads.

The secondary threads (goroutine) should not directly update the UI, instead, use PostMessage that is expected to be thread-safe. See example that sends data to an element, that will be received by a callback when the main loop regains control. You can also use the IdleFunc and Timer.

Cross-compile (Linux)

To cross-compile for Windows install MinGW toolchain.

$ CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -ldflags "-s -w"
$ file alarm.exe
alarm.exe: PE32+ executable (console) x86-64, for MS Windows

$ CGO_ENABLED=1 CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 go build -ldflags "-s -w"
$ file alarm.exe
alarm.exe: PE32 executable (console) Intel 80386, for MS Windows

To cross-compile for macOS install OSXCross toolchain.

$ CGO_ENABLED=1 CC=x86_64-apple-darwin21.1-clang GOOS=darwin GOARCH=amd64 go build -ldflags "-linkmode external -s -w '-extldflags=-mmacosx-version-min=10.14'"
$ file alarm
alarm: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK>

$ CGO_ENABLED=1 CC=aarch64-apple-darwin21.1-clang GOOS=darwin GOARCH=arm64 go build -ldflags "-linkmode external -s -w '-extldflags=-mmacosx-version-min=10.14'"
$ file alarm
alarm: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

Credits

License

iup-go is MIT licensed, same as IUP. View LICENSE.

iup-go's People

Contributors

gen2brain avatar hoto-cocoa avatar jupiterrider avatar justinfx avatar trevor403 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iup-go's Issues

Table?

Is there anything in iup-go that does what C# DataTables do? This is an example image of what I'm trying to make:
Example Image
Thanks!

PostMessage example sometimes shows too small window size

Hi! This is a super interesting project. Thank you for pushing the boundaries of what is possible in GUI for Go.

I tried today to build the PostMessage example linked in the readme from master (a3b3bba).

Often it works fine, but sometimes, it only looks like this:

image

Sometimes the 'Random XKCD' button will appear briefly before this too.

It happened on Linux with -tags gtk2, -tags gl, and with no -tags flag. At first i thought it was only affecting one backend, but actually it seems to happen randomly with multiple backends.

Questions With List

Hello there! I'm working with iup.List and have some questions:

  1. How do you append an item to a list? I've tried setting the APPENDITEM attribute, or using iup.Append(), but so far, only numbered (1, 2, 3, ...) attributes have worked so far.
  2. How do I prevent the height of a list inside a iup.Split from exceeding the height it reaches when there's no item inside the list (It just fills the remaining space in the window)? I don't wanna set a MAXSIZE.

Thanks!

iup.MultiLine cannot insert longer text than 255 chars

I wrote a program which should insert a long text into iup.Multiline (Value=). But it only inserts the first 255 chars. I think it has something to do with the buffer size? Could you please fix this or maybe add an option where you can change the size when needed?

Compatibility with MSYS2

Hello!

Many thanks for putting together such a fantastic package.
I'm happy to say that I'm using iup-go, thanks to your efforts.

I just wanted to share something I recently discovered with everyone.
If you want to use iup-go on Windows, just make sure you're using MSYS2 20240507 or a lower version.

Just a heads-up: If you use a MSYS2 version after July 27, 2024, it won't build because of a type issue with the functions declared in the windows.h file.

You can manually modify the file and use it, but unless you really need the latest MSYS2, you should use the 20240507 version.

Thanks again to @gen2brain and all the other contributors for another great IUP-GO.

Global TXTHLCOLOR returns TXTBGCOLOR on Linux/GTK

I'm drawing a custom control in a canvas, and there seems to be no way to obtain the correct highlight color (for filled highlight rectangles) on Linux in GTK. Observations:

  1. iup.DrawSelectRect draws a rectangle in the wrong color - some custom dark blue on my machine, not the lighter blue used with by the GTK themes I'm running and testing with. This color doesn't seem to be part of the GTK theme, it appears to be hard-coded.
  2. iup.GetGlobal("TXTHLCOLOR") returns the background color of text fields, i.e., white on a standard light theme, dark grey on a test GTK theme I'm using. It's exactly the color of text entry fields.
  3. Selections in flat controls like FlatList also use the wrong selection colors, some white or grey text background color.

Neither of these colors are the same as what an iup.List() uses for selections. I cannot find a way to get the theme-provided highlight color. I can also not get the DrawSelectRect color.

I'm not sure whether this is an IUP problem or has to do with the Go wrapper. I can provide screenshots if needed.

What type does the iup.Tree USERDATAid attribute expect?

In the C docs, it seems to expect a pointer to a custom struct, but I cannot figure out how to store userdata in the Go port. I've tried int and string, and it returns garbage after I've set the attribute. I've also tried a pointer to a Go struct, as well as an instance of iup.User without success. (The hope was that I could use int value corresponding to the iup.Ihandle as a unique key.)

How do you use this attribute in the Go port?

If it's not possible, is there any other way to get a unique value (of any kind) for each visible node in the tree and obtain it from the current ID of a node as it is e.g. delivered in a callback? The problem is that LASTADDNODE does not return such a value when I build the tree because I'm adding items recursively in reverse order. Later in callbacks the ID is completely different because the order of items has changed.

Frequent segmentation violations on Linux/Gtk3, cause unknown (event processing?)

I get seemingly random crashes to desktop when clicking on interface elements and interacting with them in other ways. They might be related to iup.List , I have't noticed them before I started using iup.List with many entries. Here is a typical crash:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x7fb88ca19678]

runtime stack:
runtime.throw({0x8d8448?, 0x7fb84c5fe7e0?})
	/usr/local/go/src/runtime/panic.go:992 +0x71
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:802 +0x3a9

goroutine 6 [syscall]:
runtime.cgocall(0x67f2e0, 0xc0003adf30)
	/usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc0003adf08 sp=0xc0003aded0 pc=0x4393fc
github.com/gen2brain/iup-go/iup._Cfunc_IupMainLoop()
	_cgo_gotypes.go:2234 +0x48 fp=0xc0003adf30 sp=0xc0003adf08 pc=0x57d808
github.com/gen2brain/iup-go/iup.MainLoop(...)
	/home/nemo/go/pkg/mod/github.com/gen2brain/iup-go/[email protected]/bind_events.go:20
main.(*Application).Run(0xc000200000)
	/home/nemo/go/src/github.com/rasteric/giuprj/application.go:281 +0x8b fp=0xc0003adf68 sp=0xc0003adf30 pc=0x67410b
main.run()
	/home/nemo/go/src/github.com/rasteric/giuprj/main.go:40 +0x7e fp=0xc0003adfb0 sp=0xc0003adf68 pc=0x6761de
golang.design/x/mainthread.Init.func1()
	/home/nemo/go/pkg/mod/golang.design/x/[email protected]/mainthread.go:96 +0x5b fp=0xc0003adfe0 sp=0xc0003adfb0 pc=0x619b7b
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc0003adfe8 sp=0xc0003adfe0 pc=0x498241
created by golang.design/x/mainthread.Init
	/home/nemo/go/pkg/mod/golang.design/x/[email protected]/mainthread.go:92 +0x10a

goroutine 1 [runnable, locked to thread]:
golang.design/x/mainthread.Init(0x8df020)
	/home/nemo/go/pkg/mod/golang.design/x/[email protected]/mainthread.go:100 +0x16b
main.main()
	/home/nemo/go/src/github.com/rasteric/giuprj/main.go:29 +0x25

goroutine 18 [select]:
database/sql.(*DB).connectionOpener(0xc0002041a0, {0x922600, 0xc00021c0c0})
	/usr/local/go/src/database/sql/sql.go:1226 +0x8d
created by database/sql.OpenDB
	/usr/local/go/src/database/sql/sql.go:794 +0x18d

goroutine 60 [runnable]:
golang.design/x/mainthread.Call(0xc000741070)
	/home/nemo/go/pkg/mod/golang.design/x/[email protected]/mainthread.go:135 +0xc7
main.(*Application).makeAssetList(0xc000200000, {0x922600, 0xc000080a80}, {0x0, 0x0})
	/home/nemo/go/src/github.com/rasteric/giuprj/window.go:286 +0x11c
main.(*Application).initPubSub.func5.4({0x922600, 0xc000080a80})
	/home/nemo/go/src/github.com/rasteric/giuprj/application.go:233 +0xb8
created by main.(*Scheduler).GoWithCancel
	/home/nemo/go/src/github.com/rasteric/giuprj/scheduler.go:49 +0xaa

I thought it had something to do with goroutines so I've wrapped every call to iup into mainthread.Call from https://github.com/golang-design/mainthread, even when I'm just reading attributes.

OS: Linux Mint 20.3 Cinnamon
Compiled with gtk3 option.

Hide Handle in CLOSE_CB

I've implemented a traybar item, now I want the window to not close when the close button on the titlebar gets clicked. This is what I've tried:

func closeHandler(_ iup.Ihandle) int {
	iup.Hide(iup.GetHandle("window"))

	return iup.IGNORE
}

window.SetCallback("CLOSE_CB", iup.CloseFunc(closeHandler))

However, calling Hide() seems to close the window, if I remove that line, it works fine. I've tried setting the handle's VISIBLE attribute as well and it doesn't give a different result.

Any ideas? Thanks in advance!

Multiple includes of iup_datepick.c

Hello,
i'm trying to compile the menu example from the example directory but i get this error message:

go run -a .
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/Users/herib/AppData/Local/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\herib\AppData\Local\Temp\go-link-2596143189\000124.o: in function `iupDatePickNewClass':
/tmp/go-build/windows_iupwin_datepick.cgo2.c:248: multiple definition of `iupDatePickNewClass'; C:\Users\herib\AppData\Local\Temp\go-link-2596143189\000037.o:/tmp/go-build/core_iup_datepick.cgo2.c:451: first defined here
C:/Users/herib/AppData/Local/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\herib\AppData\Local\Temp\go-link-2596143189\000124.o: in function `IupDatePick':
/tmp/go-build/windows_iupwin_datepick.cgo2.c:302: multiple definition of `IupDatePick'; C:\Users\herib\AppData\Local\Temp\go-link-2596143189\000037.o:C:/Users/herib/go/pkg/mod/github.com/gen2brain/iup-go/[email protected]/external/src/iup_datepick.c:484: first defined here
collect2.exe: error: ld returned 1 exit status

Im working on Windows 10 with
go version: 'go1.21.3 windows/amd64' and
gcc version: 'gcc.exe (MinGW-W64 x86_64-ucrt-mcf-seh, built by Brecht Sanders) 13.2.0'

It seems as if both files .\win\iupwin_datepick.c and .\iup_datepick.c are included in the compilation.

Proper FLAT_ACTION callback for FlatList? Segfault using ListActionFunc

I'm getting a segfault when I try to wire up a FlatList with the "FLAT_ACTION" and ListActionFunc. But if I switch to a regular List and use ACTION, it works correctly. The iup docs seems to indicate that the only difference is the callback name. What would be the correct way to apply this callback to FlatList?

Webview support?

I read in the IUP docs that there is a WebBrowser control, but it states that it's Linux and Windows only.
Is it possible to implement a control that is able to embed something like this?

iup.Open() fails with error after package installation on Linux Mint 20.3 Cinnamon

The error might be GTK-related: Pango-ERROR **: 10:17:40.740: Harfbuzz version too old (1.3.2)

I tried to follow the (vaguely) related instructions here:

https://unix.stackexchange.com/questions/589993/pango-error-harfbuzz-version-too-old

and here:

GGBRW/BOOLR#45

Unfortunately, so far I didn't get it to work. Is there a way to force recompilation of IUP with these libraries or any other way to fix this except for system-wide downgrading of Pango libraries?

[feature] Include support for IupScintilla

Support for the IUP embedding of Scintilla would be extremely helpful for some use cases. It cannot be emulated with existing controls and allows for fast syntax coloring and advanced text editing functionality.

Example "thread": SIGABRT crash on Close

When testing the "thread" example, on an Ubuntu linux distro, I have found that closing the dialog results in a SIGABRT when iup.Close is called.

double free or corruption (out)
SIGABRT: abort
PC=0x7f885e56ee87 m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall]:
runtime.cgocall(0x4d8160, 0xc000075da8)
    /.../go/1.18.0/src/runtime/cgocall.go:157 +0x5c fp=0xc000075d80 sp=0xc000075d48 pc=0x42945c
github.com/gen2brain/iup-go/iup._Cfunc_IupClose()
    _cgo_gotypes.go:253 +0x45 fp=0xc000075da8 sp=0xc000075d80 pc=0x4ba705
github.com/gen2brain/iup-go/iup.Close()
    /.../src/ext/iup-go/iup/bind_iup.go:26 +0x17 fp=0xc000075db8 sp=0xc000075da8 pc=0x4d09d7
main.main()
    /.../src/ext/iup-go/examples/thread/thread.go:33 +0x311 fp=0xc000075f80 sp=0xc000075db8 pc=0x4d2e11
runtime.main()
    /.../go/1.18.0/src/runtime/proc.go:250 +0x212 fp=0xc000075fe0 sp=0xc000075f80 pc=0x45a132
runtime.goexit()
    /.../go/1.18.0/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc000075fe8 sp=0xc000075fe0 pc=0x482d61

rax    0x0
rbx    0x7ffe8b025440
rcx    0x7f885e56ee87
rdx    0x0
rdi    0x2
rsi    0x7ffe8b0251d0
rbp    0x7ffe8b025540
rsp    0x7ffe8b0251d0
r8     0x0
r9     0x7ffe8b0251d0
r10    0x8
r11    0x246
r12    0x7ffe8b025440
r13    0x1000
r14    0x0
r15    0x30
rip    0x7f885e56ee87
rflags 0x246
cs     0x33
fs     0x0
gs     0x0

I've found that commenting out the following line prevents the crash:

	thread := iup.Thread()
	thread.SetCallback("THREAD_CB", iup.ThreadFunc(threadCb))
	//thread.SetHandle("thread")

Compile fails with "gl" tag: undefined: pih

I was trying to build some of the examples on an Ubuntu linux distro, using -tags gl, and the compile failed with missing references:

# github.com/gen2brain/iup-go/iup
../iup/bind_gl.go:38:21: undefined: pih
../iup/bind_gl.go:45:30: undefined: pih
../iup/bind_gl.go:52:21: undefined: pih
../iup/bind_gl.go:59:17: undefined: pih
../iup/bind_gl.go:67:17: undefined: pih
../iup/bind_gl.go:83:33: undefined: pih

Are these refs supposed to be C.pih?
https://github.com/gen2brain/iup-go/blob/iup/v3.30.3/iup/bind_gl.go#L38

IupGetParam() ?

Hello,

Is it planned to integrate support for IupGetParam() or is it too complicated ?

Thanks

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.