Skip to content

Instantly share code, notes, and snippets.

@Capital-EX
Created March 9, 2024 20:20
Show Gist options
  • Save Capital-EX/d08a37765ef898cd432f662ffc7aaf98 to your computer and use it in GitHub Desktop.
Save Capital-EX/d08a37765ef898cd432f662ffc7aaf98 to your computer and use it in GitHub Desktop.
fyne: context {
app: ?fyne-app
label: ?fyne-label
entry: ?fyne-entry
button: ?fyne-button
container: ?fyne-container
}
; If we create Fyne constructor function inside a fyne context
rye .needs { fyne }
do\in fyne {
cont: container 'vbox vals {
container 'hbox vals {
label "B:" :slot-b
entry :value-b
}
container 'hbox vals {
label "A:" :slot-a
entry :value-a
}
container 'hbox vals {
button "1" { value-a |get-text |to-string |concat "1" |set-text* value-a }
button "2" { value-a |get-text |to-string |concat "2" |set-text* value-a }
button "3" { value-a |get-text |to-string |concat "3" |set-text* value-a }
button "/" {
value-b |get-text |to-string |to-integer :x
value-a |get-text |to-string |to-integer :y
x / y |to-string |set-text* value-a
value-b .set-text ""
}
}
container 'hbox vals {
button "4" { value-a |get-text |to-string |concat "4" |set-text* value-a }
button "5" { value-a |get-text |to-string |concat "5" |set-text* value-a }
button "6" { value-a |get-text |to-string |concat "6" |set-text* value-a }
button "*" {
value-b |get-text |to-string |to-integer :x
value-a |get-text |to-string |to-integer :y
x * y |to-string |set-text* value-a
value-b |set-text ""
}
}
container 'hbox vals {
button "7" { value-a |get-text |to-string |concat "7" |set-text* value-a }
button "8" { value-a |get-text |to-string |concat "8" |set-text* value-a }
button "9" { value-a |get-text |to-string |concat "9" |set-text* value-a }
button "- " {
value-b |get-text |to-string |to-integer :x
value-a |get-text |to-string |to-integer :y
x - y |to-string |set-text* value-a
value-b |set-text ""
}
}
container 'hbox vals {
button "0" { value-a |get-text |to-string |concat "0" |set-text* value-a }
button "=" { value-a |get-text |to-string |set-text* value-b value-a |set-text "" }
button "~" { value-a |get-text |to-string :a
value-b |get-text |to-string :b
value-a |set-text b
value-b |set-text a }
button "+" {
value-b |get-text |to-string |to-integer :x
value-a |get-text |to-string |to-integer :y
x + y |to-string |set-text* value-a
value-b |set-text ""
}
}
}
app .new-window "Feedback"
|set-content cont
|show-and-run
}
@refaktor
Copy link

refaktor commented Mar 20, 2024

Thank you for a great GUI example. I used all my rye knowledge and fixed a bug in between to make it a little nicer :), here:
https://gist.github.com/refaktor/63693faae0bea092da092f45920daaa9
rye_fyne_rpn_calculator_2
Next step will be to add error handling. It will all be in github repo. Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment