Skip to content

Commit

Permalink
Back to working
Browse files Browse the repository at this point in the history
  • Loading branch information
zenith391 committed Nov 6, 2019
1 parent ddf473a commit 2c81152
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
# Executables files
test
test.exe
27 changes: 23 additions & 4 deletions gtk3/gtk3.v
Expand Up @@ -5,7 +5,7 @@ struct C.GtkWidget {
}

interface Widgeter {
set_size(int,int)
get_gtk_widget() &C.GtkWidget
}

interface Container {
Expand All @@ -18,8 +18,6 @@ struct Window {

struct Button {
gtk_widget &C.GtkWidget
pub mut:
parent ?Container
}

fn init() {
Expand All @@ -33,11 +31,23 @@ pub fn new_window() Window {
return win
}

pub fn new_button(label string) Button {
btn := Button{
gtk_widget: C.gtk_button_new_with_label(label.str)
}
return btn
}

// This function is blocking!
pub fn run() {
C.gtk_main()
}

// Window struct
pub fn (w Window) add(widget Widgeter) {
C.gtk_container_add(w.gtk_widget, widget.get_gtk_widget())
}

pub fn (w Window) show() {
C.gtk_widget_show_all(w.gtk_widget)
}
Expand All @@ -52,4 +62,13 @@ pub fn (w Window) center() {

pub fn (w Window) set_title(title string) {
C.gtk_window_set_title(w.gtk_widget, title.str)
}
}

pub fn (w Window) get_gtk_widget() &C.GtkWidget {
return w.gtk_widget
}

// Button struct
pub fn (b Button) get_gtk_widget() &C.GtkWidget {
return b.gtk_widget
}
13 changes: 4 additions & 9 deletions test.v
Expand Up @@ -2,18 +2,13 @@ import gtk3

fn main() {
window := gtk3.new_window()
btn := gtk3.new_button("Bouton")

window.set_size(640, 480)
window.center()
window.set_title("Bonjour Monde")
window.add(btn)
window.show()

go run()
while true {

}
println("test")
}

fn run() {
gtk3.run()
}
}

0 comments on commit 2c81152

Please sign in to comment.