Add info and sample for SVG icons and prefs edit dialog

This commit is contained in:
Evgeny
2024-05-16 14:21:05 +04:00
parent 7fb9d43cea
commit 1c2ab3341a
4 changed files with 53 additions and 2 deletions

View File

@@ -25,6 +25,11 @@ The type of script is determined by the line (meta tag) at the beginning of the
# Changelog # Changelog
### 5.3.0
* Added `prefs:show_dialog` method
* Added support for SVG icons to the Rich UI API
### 5.2.3 ### 5.2.3
* Added `on_load()` callback * Added `on_load()` callback
@@ -139,7 +144,8 @@ The `ui:show_chart()` function takes a string as its third argument to format th
* `number` - an ordinary number with group separation; * `number` - an ordinary number with group separation;
* `float` - the same, but with two decimal places; * `float` - the same, but with two decimal places;
* `date` - date in day.month format; * `date` - date in day.month format;
* `time` - time in hours:minutes format. * `time` - time in hours:minutes format;
* `none` - disable.
### Clicks ### Clicks
@@ -671,6 +677,8 @@ end
The `new_key` will be present in the table even after the AIO Launcher has been restrated. The `new_key` will be present in the table even after the AIO Launcher has been restrated.
The `show_dialog()` method automatically creates a window of current settings from fields defined in prefs. The window will display all fields with a text key and a value of one of three types: string, number, or boolean. All other fields of different types will be omittedi. Fields whose names start with an underscore will also be omitted. Script will be reloaded on settings save.
## Animation and real time updates ## Animation and real time updates
_Available only in widget scripts._ _Available only in widget scripts._

View File

@@ -72,7 +72,7 @@ Third way: display icon in the button:
{"button", "Text with icon: %%fa:microphone%%"} {"button", "Text with icon: %%fa:microphone%%"}
``` ```
The second method also allows displaying icons of applications and contacts. How to do this is shown in the example [samples/rich-ui-sample.lua]. The second method also allows displaying icons of applications and contacts. How to do this is shown in the example [rich-ui-sample.lua](samples/rich-ui-sample.lua). You can also use the `icon` element to display your own icons in SVG format. Example: [svg-sample.lua](samples/svg-sample.lua).
By the way, if you want the button to stretch across the entire width of the screen, you can use the expand argument: By the way, if you want the button to stretch across the entire width of the screen, you can use the expand argument:

31
samples/prefs-widget3.lua Normal file
View File

@@ -0,0 +1,31 @@
--[[
This example shows how to use the prefs module
to display a settings dialog automatically generated on the screen.
]]
prefs = require("prefs")
function on_load()
-- Initialize settings with default values
prefs.text_field_1 = "Test"
prefs.text_field_2 = "Test #2"
prefs.numeric_field = 123
prefs.boolean_field = false
prefs._hidden_field = "Hidden"
end
function on_resume()
ui:show_toast("On resume called")
ui:show_text("Click to edit preferencies")
end
function on_click()
--[[
The `show_dialog()` method automatically creates a window of current settings from fields defined in prefs.
The window will display all fields with a text key and a value of one of three types: string, number, or boolean.
All other fields of different types will be omittedi.
Fields whose names start with an underscore will also be omitted.
Script will be reloaded on settings save.
]]
prefs:show_dialog()
end

12
samples/svg-sample.lua Normal file
View File

@@ -0,0 +1,12 @@
local icon = [[
<?xml version="1.0" encoding="utf-8"?>
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 14.7519C3.37037 13.8768 3 12.8059 3 11.6493C3 9.20008 4.8 6.9375 7.5 6.5C8.34694 4.48637 10.3514 3 12.6893 3C15.684 3 18.1317 5.32251 18.3 8.25C19.8893 8.94488 21 10.6503 21 12.4969C21 13.5693 20.6254 14.5541 20 15.3275M12.5 12.9995L10.5 21.0008M8.5 11.9995L6.5 20.0008M16.5 12L14.5 20.0013" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
]]
function on_resume()
gui{
{"icon", "svg:"..icon, {size = 100}},
}.render()
end