diff --git a/devel/scheme/gui/scheme-gui.en.tm b/devel/scheme/gui/scheme-gui.en.tm new file mode 100644 index 0000000..e533c52 --- /dev/null +++ b/devel/scheme/gui/scheme-gui.en.tm @@ -0,0 +1,215 @@ + + + + +<\body> + + + Most of the user interface to is dynamically created from within + the interpreted scheme code. Imagine you want to implement some feature + which requires interaction with the user. One possible approach is to use + the facility , which will either popoup a dialog or ask in + the footer bar, based in metadata you provide inside your 'd + function. See for more on this topic. However, + automatically generated stuff is not always the best approach, so you might + want to explicitly design your interface placing it inside a complicated + dialog. + + + + In you create visual interfaces using . This word + means either the basic building blocks you have at your disposal, like + buttons, popup lists, etc. or the collections of those into dialogs, menus + or whatever. The latter can be aggregated to build more complicated ones as + well.<\footnote> + If you miss some particular ``building block'' from your OS, you might + see whether it's feasible as an aggregation of simpler ones or try and + play with the UI interface code in C++ (but you'll have to add it for + every supported platform!). + + + Let's see how you create a dialog. First you'll want to use + to define a new widget. The call to this function uses its particular + syntax, with many keywords for the creation of widgets. You can see the + whole list in the table inside + . + Here is one little example taken from : + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (tm-widget (widget1) + + \ \ (centered + + \ \ \ \ (aligned + + \ \ \ \ \ \ (item (text "First:") + + \ \ \ \ \ \ \ \ (toggle (display* "First " answer "\\n") #f)) + + \ \ \ \ \ \ (item (text "Second:") + + \ \ \ \ \ \ \ \ (toggle (display* "Second " answer "\\n") #f))))) + <|unfolded-io> + \; + + + + In order to display this you create a and give it a title. + + <\session|scheme|default> + <\input|Scheme] > + (top-window widget1 "Two toggle widgets") + + + + You'll notice that the created window is too small and the title is not + wholly displayed. You can force it to be of a certain size using + : + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (tm-widget (widget1) + + \ \ (centered + + \ \ \ \ (resize "500px" "200px" + + \ \ \ \ \ \ (aligned + + \ \ \ \ \ \ \ \ (item (text "First:") + + \ \ \ \ \ \ \ \ \ \ (toggle (display* "First " answer "\\n") #f)) + + \ \ \ \ \ \ \ \ (item (text "Second:") + + \ \ \ \ \ \ \ \ \ \ (toggle (display* "Second " answer "\\n") #f)))))) + <|unfolded-io> + ((guile-user) (guile-user)) + + + <\input|Scheme] > + (top-window widget1 "A bigger window") + + + + + + If you want to add the usual buttons you use like in + the following example. Notice the widget now accepts one parameter + which will be called when the user clicks the ``Ok'' button. This + will also automatically close the window.\ + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (tm-widget (form2 cmd) + + \ \ (centered + + \ \ \ \ (aligned + + \ \ \ \ \ \ (item (text "First:") + + \ \ \ \ \ \ \ \ (toggle (display* "First " answer "\\n") #f)) + + \ \ \ \ \ \ (item (text "Second:") + + \ \ \ \ \ \ \ \ (toggle (display* "Second " answer "\\n") #f)))) + + \ \ (bottom-buttons \\ ("Ok" (cmd "Ok")))) + <|unfolded-io> + \; + + + + Since the widget now needs an argument, we must use another function to + display it, namely , like this: + + <\session|scheme|default> + <\input|Scheme] > + (dialogue-window form2 (lambda (arg) (display* arg "\\n")) "Two + toggles") + + + + As you can see, this approach has a shortcoming: there's no way to access + all the values of the different widgets in your dialog at the same time. Of + course you can use the function passed to your widget to perform + some computations, but in case you need to retrieve or store complicated + data, what you need is a form (See ). + + + + As explained in the available widgets can be + used to create menu items and dialog windows, but you may want to create + more complex dialogs to perform more complicated tasks. Forms provide one + mechanism to do this. They allow you to define multiple named fields of + several types, whose values are stored in a . + You can retrieve and return the values of this hash when the user clicks a + button using the functions and . + + In the following example you can see that the syntax is pretty much the + same as for regular widgets, but you must prefix your widgets with + : + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (tm-widget (form3 cmd) + + \ \ (form "Test" + + \ \ \ \ (centered + + \ \ \ \ \ \ (aligned + + \ \ \ \ \ \ \ \ (item (text "Input:") + + \ \ \ \ \ \ \ \ \ \ (form-input "fieldname1" "string" '("one" "two" + "three") "1w")) + + \ \ \ \ \ \ \ \ (item (text "Enum:") + + \ \ \ \ \ \ \ \ \ \ (form-enum "fieldname2" '("one" "two" "three") + "two" "1w")) + + \ \ \ \ \ \ \ \ (item (text "Choice") + + \ \ \ \ \ \ \ \ \ \ (form-choice "fieldname3" '("one" "two" "three") + "one")) + + \ \ \ \ \ \ \ \ (item (text "Choices") + + \ \ \ \ \ \ \ \ \ \ (form-choices "fieldname4"\ + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ '("one" "two" "three")\ + + \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ '("one" "two")))) + + \ \ \ \ \ \ (bottom-buttons + + \ \ \ \ \ \ \ \ ("Cancel" (cmd "cancel")) \\ + + \ \ \ \ \ \ \ \ ("Ok" + + \ \ \ \ \ \ \ \ \ (display* (form-fields) " -\ " (form-values) + "\\n") + + \ \ \ \ \ \ \ \ \ (cmd "ok")))))) + <|unfolded-io> + ((guile-user) (guile-user)) + + + <\input|Scheme] > + (dialogue-window form3 (lambda (x) (display* x "\\n")) "Test of form3") + + + <\input|Scheme] > + \; + + + + A complete list of the widgets you can embed in a form is in the table + inside . + + \; + \ No newline at end of file diff --git a/devel/scheme/scheme.en.tm b/devel/scheme/scheme.en.tm index 2f5efaa..675f3ef 100644 --- a/devel/scheme/scheme.en.tm +++ b/devel/scheme/scheme.en.tm @@ -17,6 +17,9 @@ + + bibliography styles|bibliography/bibliography.en.tm>