Adjusts multiline widget to allow monospace font

This commit is contained in:
sloum 2022-04-28 15:42:02 -07:00
parent 79147a8b53
commit 66239c9b7b
3 changed files with 13 additions and 5 deletions

View File

@ -563,7 +563,7 @@ Implemented:
<li><code>(widget-make-image [source: string] [location: string] [[mode: string]] [[min-width: number]] [[min-height]]) => gui-widget</code></li>
<li><code>(widget-make-label [text: string] [[alignment: number]] [[wrap-text: bool]]) => gui-widget</code></li>
<li><code>(widget-make-markdown [markdown-text: string] [[wrap-text: bool]]) => gui-widget</code></li>
<li><code>(widget-make-multiline [placeholder-text: string] [[wrap-text: bool]] [[validation-callback: lambda]]) => gui-widget</code></li>
<li><code>(widget-make-multiline [placeholder-text: string] [[wrap-text: bool]] [[use-monospace-font: bool]] [[validation-callback: lambda]]) => gui-widget</code></li>
<li><code>(widget-make-password [placeholder-text: string] [[wrap-text: bool]] [[validation-callback: lambda]]) => gui-widget</code></li>
<li><code>(widget-make-select [options: list] [callback: lambda] [[alignment: number]]) => gui-widget</code></li>
<li><code>(widget-make-separator) => gui-widget</code></li>

14
gui.go
View File

@ -597,11 +597,18 @@ var guiLib = vars{
e.(*widget.Entry).Wrapping = fyne.TextTruncate
}
// Handle validation
if len(a) > 2 {
cb, ok := a[2].(proc)
b := AnythingToBool(a[2]).(bool)
if b {
e.(*widget.Entry).TextStyle = fyne.TextStyle{false, false, true, 4}
}
}
// Handle validation
if len(a) > 3 {
cb, ok := a[3].(proc)
if !ok {
return exception("'widget-make-entry' expects a callback as its optional third argument, a non-callback value was given")
return exception("'widget-make-entry' expects a callback as its optional fourth argument, a non-callback value was given")
}
e.(*widget.Entry).Validator = func(in string) error {
result := apply(cb, []expression{in})
@ -613,6 +620,7 @@ var guiLib = vars{
}
}
}
return e
},
"widget-make-label": func(a ...expression) expression {

View File

@ -30,7 +30,7 @@ var guiUsageStrings = map[string]string{
"widget-make-image": "(widget-make-image [source: string] [location: string] [[mode: string]] [[min-width: number]] [[min-height: number]]) => gui-widget\n\nCreates an image widget from the given source. Available sources are: \"path\" and \"url\", the later of which will actually load any available URI. The `location` string represents the address or path of the image. The optional `mode` argument defaults to \"fit\" which will keep the original aspect ratio of the image but size it to fit the container (latching to the smallest container dimension). \"original\" may be passed to over-ride the default behavior and use the original image size, expanding the container if need be. Passing a min-width or min-height will cause the resulting image widget to size to this dimension as a minimum value. The way the size minimums work may be surprising as they interact with attempts to keep the aspect ratio and size to the container, so a 50x10 image set to 10x100 will not work, since aspect ratio is being kept. One value will be chosen as the one to use in sizing, this may depend on the type of container",
"widget-make-label": "(widget-make-label [text: string] [[alignment: number]] [[wrap-text: bool]]) => gui-widget\n\nCreates a label widget with the given text. If alignment is given it should be one of:\n\n\t-1: Align Leading\n\t 0: Align Center\n\t 1: Align Trailing",
"widget-make-markdown": "(widget-make-markdown [markdown-text: string] [[wrap-text: bool]]) => gui-widget\n\nCreates a markdown text block. The markdown-text string should be markdown, which will be parsed and rendered. wrap-text defaults to #f. If set to #t the text will be wrapped at word boundaries using the minimum size of the container",
"widget-make-multiline": "(widget-make-multiline [placeholder-text: string] [[wrap-text: bool]] [[validation-callback: lambda]]) => gui-widget\n\nCreates a multiline text entry widget with the given placeholder value. For accessibility purposes it is always advised to also have a label widget describing this widget. If a validation lambda is given it should take a string value as its argument and should validate based on that string. If it successfully validates `#t` or any non-string value should be returned, otherwise a string explaining the error should be returned",
"widget-make-multiline": "(widget-make-multiline [placeholder-text: string] [[wrap-text: bool]] [[use-monospace-font: bool]] [[validation-callback: lambda]]) => gui-widget\n\nCreates a multiline text entry widget with the given placeholder value. For accessibility purposes it is always advised to also have a label widget describing this widget. If `#t` is passed to `use-monospace-font` the system's monospace font will be for text within the widget. If a validation lambda is given it should take a string value as its argument and should validate based on that string. If it successfully validates `#t` or any non-string value should be returned, otherwise a string explaining the error should be returned",
"widget-make-password": "(widget-make-password [placeholder-text: string] [[wrap-text: bool]] [[validation-callback: lambda]]) => gui-widget\n\nCreates an password widget with the given placeholder value. For accessibility purposes it is always advised to also have a label widget describing this widget. If a validation lambda is given it should take a string value as its argument and should validate based on that string. If it successfully validates `#t` or any non-string value should be returned, otherwise a string explaining the error should be returned",
"widget-make-select": "(widget-make-select [options: list] [callback: lambda] [[alignment: number]]) => gui-widget\n\nCreates a select widget with the given options. Any non-string options will be converted to string. The callback should accept a string argument representing the selected element and should only create side effects (the return value will be discarded). If alignment is given it should be one of:\n\n\t-1: Align Leading\n\t 0: Align Center\n\t 1: Align Trailing",
"widget-make-separator": "(widget-make-separator) => gui-widget\n\nReturns a separator widget, which takes the form of a separator line that will go horizontal or vertical automatically depending on the container/layout",