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

Fix compilation with latest V #38

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
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ all: fmt test examples
fmt:
$(V) run ./fmt.vsh

clean:
git clean -xf -- examples

test:
$(V) test .

Expand All @@ -20,4 +23,3 @@ examples:
$(V) ./examples/entry.v
$(V) ./examples/grid.v
$(V) ./examples/label.v

42 changes: 21 additions & 21 deletions examples/basic.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn run_quit(mi gtk.Button, data voidptr) {
fn run_code(mi gtk.Button, data voidptr) {
source := 'runme.v'
app := &AppState(data)
input := app.code.get_text()
input := app.code.get_text()

os.rm(source) or {}
mut f := os.open_file(source, 'w+') or { panic(err) }
Expand All @@ -43,7 +43,7 @@ fn menu_exit(mi gtk.MenuItem, data voidptr) {
}

fn menu_about(mi gtk.MenuItem, data voidptr) {
os.system("ls /")
os.system('ls /')
}

fn alert_clicked(btn gtk.Button, data voidptr) {
Expand All @@ -56,11 +56,11 @@ fn win_destroy(win gtk.Window, data voidptr) {

struct AppState {
mut:
window gtk.Window
menubar gtk.MenuBar
window gtk.Window
menubar gtk.MenuBar
have_menubar bool
code gtk.TextView
result gtk.TextView
code gtk.TextView
result gtk.TextView
}

fn new_appstate() AppState {
Expand All @@ -73,18 +73,18 @@ fn (mut app AppState) ready() {
w := app.window
w.set_position(.center)
w.set_title('Im made with V')
w.on('destroy', win_destroy, voidptr(0))
w.on('destroy', win_destroy, unsafe { nil })
w.show_all()
}

fn (mut app AppState)get_bbox() gtk.ButtonBox {
fn (mut app AppState) get_bbox() gtk.ButtonBox {
bbox := gtk.new_hbutton_box()
bbox.set_layout(.end)

gtk.Box(bbox).set_spacing(10)
gtk.to_box(bbox).set_spacing(10)
app.window.set_border_width(10)
// c := &gtk.Container(vbox.c)
//c.set_border_width(10)
// c := &gtk.Container(vbox.c)
// c.set_border_width(10)

a := gtk.new_button_with_label('Run')
a.on('activate', run_code, app)
Expand All @@ -97,7 +97,7 @@ fn (mut app AppState)get_bbox() gtk.ButtonBox {
return bbox
}

fn (mut app AppState)get_paned() gtk.Paned {
fn (mut app AppState) get_paned() gtk.Paned {
p := gtk.new_paned(.horizontal)
p.set_position(200)
p.set_wide_handle(true)
Expand All @@ -122,21 +122,21 @@ fn (mut app AppState)get_paned() gtk.Paned {
return p
}

fn (mut app AppState)get_menubar() gtk.MenuBar {
fn (mut app AppState) get_menubar() gtk.MenuBar {
if app.have_menubar {
return app.menubar
}
/*
/*
if mb := app.menubar {
return mb
}
*/
*/
bar := gtk.new_menu_bar()
app.menubar = bar

menu := gtk.new_menu()
file_me := gtk.new_menu_item_with_label("File")
quit := gtk.new_menu_item_with_label("Quit")
file_me := gtk.new_menu_item_with_label('File')
quit := gtk.new_menu_item_with_label('Quit')
quit.set_accel_path('GTKTest/File/Quit')
quit.set_use_underline(true)
quit.on('activate', menu_exit, &app)
Expand All @@ -146,7 +146,7 @@ fn (mut app AppState)get_menubar() gtk.MenuBar {
edit_me.set_submenu(menu)

about := gtk.new_menu_item_with_label('About')
about.on('activate', menu_about, voidptr(0))
about.on('activate', menu_about, unsafe { nil })
menu.append(gtk.new_menu_item_with_label('Open'))
menu.append(about)
// menu.append(gtk.new_separator_menu_item())
Expand All @@ -173,7 +173,7 @@ fn main() {
btn.set_size(200, 100)
btn2.set_size(100, 50)
alert.set_size(80, 20)
/*
/*
entry.set_text("Good Night!")
btn.on("clicked", btn_clicked, &window)

Expand All @@ -183,11 +183,11 @@ fn main() {
quit.on('activate', menu_exit, &window)

alert.on("clicked", alert_clicked, &window)
*/
*/
entry.set_text('Good Night!')
btn.on('clicked', btn_clicked, &app.window)

gtk.accel_map_add_entry('GTK-Test/File/Quit', 65, 0)
gtk.accel_map_add_entry('GTK-Test/File/Quit', 65, .shift_mask)

alert.on('clicked', alert_clicked, &app.window)

Expand Down
6 changes: 3 additions & 3 deletions examples/box.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ fn main() {
window.add(box)

button1 := gtk.new_button_with_label('Hello')
button1.on('clicked', on_button1_clicked, voidptr(0))
button1.on('clicked', on_button1_clicked, unsafe { nil })
box.pack_start(button1, true, true, 0)

button2 := gtk.new_button_with_label('Goodbye')
button2.on('clicked', on_button2_clicked, voidptr(0))
button2.on('clicked', on_button2_clicked, unsafe { nil })
box.pack_start(button2, false, false, 0)

window.on('destroy', on_window_destroy, voidptr(0))
window.on('destroy', on_window_destroy, unsafe { nil })
window.show_all()
gtk.main()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dialog.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
window := gtk.new_window()
window.set_title('Main window')
window.set_default_size(500, 250)
window.on('destroy', on_window_destroy, voidptr(0))
window.on('destroy', on_window_destroy, unsafe { nil })

dialog := gtk.new_dialog_from_parent('Dialog', window, .modal)
dialog.set_default_size(150, 150)
Expand Down
4 changes: 2 additions & 2 deletions examples/entry.v
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ fn on_entry_text_changed(entry gtk.Entry, data voidptr) {

fn on_btn_icon_clicked(button gtk.CheckButton, data voidptr) {
this := &EntryDemo(data)
icon_name := if button.get_active() {'system-search-symbolic' } else { '' }
icon_name := if button.get_active() { 'system-search-symbolic' } else { '' }
this.entry.set_icon_from_icon_name(.primary, icon_name)
}

fn main() {
entry_demo := new_entry_demo()
window := &entry_demo.window
window.on('destroy', on_window_destroy, voidptr(0))
window.on('destroy', on_window_destroy, unsafe { nil })
window.show_all()
gtk.main()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/grid.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
grid.attach(button5, 1, 2, 1, 1)
grid.attach_next_to(button6, button5, .right, 1, 1)

window.on('destroy', on_destroy, voidptr(0))
window.on('destroy', on_destroy, unsafe { nil })
window.show_all()
gtk.main()
}
Expand Down
40 changes: 17 additions & 23 deletions examples/label.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ fn main() {
hbox := gtk.new_hbox(10)
vbox_left := gtk.new_vbox(10)
vbox_right := gtk.new_vbox(10)

hbox.pack_start(vbox_left, true, true, 0)
hbox.pack_start(vbox_right, true, true, 0)

mut label := gtk.new_label('This is a normal label')
vbox_left.pack_start(label, true, true, 0)

Expand All @@ -27,35 +27,29 @@ fn main() {
label.set_justify(.right)
vbox_left.pack_start(label, true, true, 0)

label = gtk.new_label("This is an example of a line-wrapped label. It " +
"should not be taking up the entire " +
"width allocated to it, but automatically " +
"wraps the words to fit.\n" +
" It supports multiple paragraphs correctly, " +
"and correctly adds " +
"many extra spaces. ")
label = gtk.new_label('This is an example of a line-wrapped label. It ' +
'should not be taking up the entire ' +
'width allocated to it, but automatically ' + 'wraps the words to fit.\n' +
' It supports multiple paragraphs correctly, ' + 'and correctly adds ' +
'many extra spaces. ')
label.set_line_wrap(true)
vbox_right.pack_start(label, true, true, 0)

label = gtk.new_label("This is an example of a line-wrapped, filled label. " +
"It should be taking " +
"up the entire width allocated to it. " +
"Here is a sentence to prove " +
"my point. Here is another sentence. " +
"Here comes the sun, do de do de do.\n" +
" This is a new paragraph.\n" +
" This is another newer, longer, better " +
"paragraph. It is coming to an end, " +
"unfortunately.")
label = gtk.new_label('This is an example of a line-wrapped, filled label. ' +
'It should be taking ' + 'up the entire width allocated to it. ' +
'Here is a sentence to prove ' + 'my point. Here is another sentence. ' +
'Here comes the sun, do de do de do.\n' + ' This is a new paragraph.\n' +
' This is another newer, longer, better ' + 'paragraph. It is coming to an end, ' +
'unfortunately.')
label.set_line_wrap(true)
label.set_justify(.fill)
vbox_right.pack_start(label, true, true, 0)

label = gtk.new_empty_label()
label.set_markup( "Text can be <small>small</small>, <big>big</big>, " +
"<b>bold</b>, <i>italic</i> and even point to " +
"somewhere in the <a href='http://www.gtk.org'" +
"title='Click to find out more'>internets</a>.")
label.set_markup('Text can be <small>small</small>, <big>big</big>, ' +
'<b>bold</b>, <i>italic</i> and even point to ' +
"somewhere in the <a href='http://www.gtk.org'" +
"title='Click to find out more'>internets</a>.")
label.set_line_wrap(true)
vbox_left.pack_start(label, true, true, 0)

Expand Down
39 changes: 20 additions & 19 deletions glib/_cdefs.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module glib

#include <gmodule.h>
#include <glib/glist.h>

[typedef]
pub struct C.GList {
data voidptr
Expand Down Expand Up @@ -85,9 +86,9 @@ fn C.g_array_remove_index_fast(&C.GArray, u32) &C.GArray

fn C.g_array_remove_range(&C.GArray, u32, u32) &C.GArray

fn C.g_array_sort(&C.GArray, int)
fn C.g_array_sort(&C.GArray, voidptr)

fn C.g_array_sort_with_data(&C.GArray, int, voidptr)
fn C.g_array_sort_with_data(&C.GArray, voidptr, voidptr)

fn C.g_array_binary_search(&C.GArray, voidptr, int, &u32) bool

Expand All @@ -108,13 +109,13 @@ fn C.g_string_sized_new(int) &C.GString

fn C.g_string_assign(&C.GString, charptr) &C.GString

fn C.g_string_vprintf(&C.GString, charptr, va_list)
fn C.g_string_vprintf(&C.GString, charptr, voidptr va_list)

fn C.g_string_append_vprintf(&C.GString, charptr, va_list)
fn C.g_string_append_vprintf(&C.GString, charptr, voidptr va_list)

fn C.g_string_printf(&C.GString, charptr)
// fn C.g_string_printf(&C.GString, charptr)

fn C.g_string_append_printf(&C.GString, charptr)
// fn C.g_string_append_printf(&C.GString, charptr)

fn C.g_string_append(&C.GString, charptr) &C.GString

Expand Down Expand Up @@ -154,7 +155,7 @@ fn C.g_string_set_size(&C.GString, int) &C.GString

fn C.g_string_free(&C.GString, bool) charptr

fn C.g_string_free_to_bytes(&C.GString) &GBytes
fn C.g_string_free_to_bytes(&C.GString) &C.GBytes

fn C.g_string_up(&C.GString) &C.GString

Expand All @@ -175,7 +176,7 @@ fn C.g_slist_insert(&C.GSList, voidptr, int) &C.GSList

fn C.g_slist_insert_before(&C.GSList, &C.GSList, voidptr) &C.GSList

fn C.g_slist_insert_sorted(&C.GSList, voidptr, int) &C.GSList
fn C.g_slist_insert_sorted(&C.GSList, voidptr, voidptr) &C.GSList

fn C.g_slist_remove(&C.GSList, voidptr) &C.GSList

Expand All @@ -195,19 +196,19 @@ fn C.g_slist_length(&C.GSList) u32

fn C.g_slist_copy(&C.GSList) &C.GSList

fn C.g_slist_copy_deep(&C.GSList, int, voidptr) &C.GSList
fn C.g_slist_copy_deep(&C.GSList, voidptr, voidptr) &C.GSList

fn C.g_slist_reverse(&C.GSList) &C.GSList

fn C.g_slist_insert_sorted_with_data(&C.GSList, voidptr, int, voidptr) &C.GSList
fn C.g_slist_insert_sorted_with_data(&C.GSList, voidptr, voidptr, voidptr) &C.GSList

fn C.g_slist_sort(&C.GSList, int) &C.GSList
fn C.g_slist_sort(&C.GSList, voidptr) &C.GSList

fn C.g_slist_sort_with_data(&C.GSList, int, voidptr) &C.GSList
fn C.g_slist_sort_with_data(&C.GSList, voidptr, voidptr) &C.GSList

fn C.g_slist_concat(&C.GSList, &C.GSList) &C.GSList

fn C.g_slist_foreach(&C.GSList, int, voidptr)
fn C.g_slist_foreach(&C.GSList, voidptr, voidptr)

fn C.g_slist_last(&C.GSList) &C.GSList

Expand All @@ -219,7 +220,7 @@ fn C.g_slist_nth_data(&C.GSList, u32) voidptr

fn C.g_slist_find(&C.GSList, voidptr) &C.GSList

fn C.g_slist_find_custom(&C.GSList, voidptr, int) &C.GSList
fn C.g_slist_find_custom(&C.GSList, voidptr, voidptr) &C.GSList

fn C.g_slist_position(&C.GSList, &C.GSList) int

Expand Down Expand Up @@ -258,15 +259,15 @@ fn C.g_list_length(&C.GList) u32

fn C.g_list_copy(&C.GList) &C.GList

fn C.g_list_copy_deep(&C.GList, int, voidptr) &C.GList
fn C.g_list_copy_deep(&C.GList, voidptr, voidptr) &C.GList

fn C.g_list_reverse(&C.GList) &C.GList

fn C.g_list_sort(&C.GList, int) &C.GList
fn C.g_list_sort(&C.GList, voidptr) &C.GList

fn C.g_list_insert_sorted_with_data(&C.GList, voidptr, int, voidptr) &C.GList
fn C.g_list_insert_sorted_with_data(&C.GList, voidptr, voidptr, voidptr) &C.GList

fn C.g_list_sort_with_data(&C.GList, int, voidptr) &C.GList
fn C.g_list_sort_with_data(&C.GList, voidptr, voidptr) &C.GList

fn C.g_list_concat(&C.GList, &C.GList) &C.GList

Expand All @@ -288,7 +289,7 @@ fn C.g_list_nth_prev(&C.GList, u32) &C.GList

fn C.g_list_find(&C.GList, voidptr) &C.GList

fn C.g_list_find_custom(&C.GList, voidptr, int) &C.GList
fn C.g_list_find_custom(&C.GList, voidptr, voidptr) &C.GList

fn C.g_list_position(&C.GList, &C.GList) int

Expand Down
5 changes: 3 additions & 2 deletions glib/array.v
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn (a Array) sort_with_data(compare_fn CompareDataFunc, user_data voidptr) {
// pub fn (a Array) binary_search(target voidptr, compare_fn CompareFunc, out_match_index &u32) bool {
// return C.g_array_binary_search(a.c, target, compare_fn, out_match_index)
// }

pub fn (a Array) set_size(len u32) Array {
cptr := C.g_array_set_size(a.c, len)
return Array{cptr}
Expand All @@ -91,6 +92,6 @@ pub fn (a Array) set_clear_func(clear_fn DestroyNotify) {
C.g_array_set_clear_func(a.c, clear_fn)
}

pub fn (a Array) free(free_segment bool) {
C.g_array_free(a.c, free_segment)
pub fn (mut a Array) free() {
C.g_array_free(a.c, true)
}
Loading
Loading