Demonstrate proper widget alignment

This commit is contained in:
Wuzzy 2016-12-20 19:06:28 +01:00
parent da28003e9c
commit 68404f0016

40
doc.lua
View File

@ -133,24 +133,44 @@ doc.new_category("example3", {
--[[ This demonstrates the custom sorting type. In the entry list, the
entries will appear in the exact order as specified. ]]
sorting = "custom",
sorting_data = { "simple", "widgets", "testbutton" },
sorting_data = { "simple_bad", "simple_good", "multi", "testbutton" },
})
doc.new_entry("example3", "simple", {
-- Just an entry with a label (BAD example)
doc.new_entry("example3", "simple_bad", {
name="Label",
-- Please note the coordinates are shoddily chosen here.
-- TODO: Show how to properly align widgets
data = "label[5,5;Just a label.]"
-- Please note the coordinates are shoddily chosen here, the don't respect
-- the Documention System formspec boundaries at all, so this is just a guess.
data = "label[5,5;Just a bad, bad label.]"
})
doc.new_entry("example3", "widgets", {
name="Widget Chaos",
-- Just some chaotic meaningless widgets for demonstration purposes
data = "label[0,1;Label]label[0,2;Label 2]button[0,3;3,1;example_ignored;Button]textlist[0,4;4,4;example_ignored2;A,B,C,D;]scrollbar[4,1;2,0.2;horizontal;example_ignored3;0]",
-- Just an entry with a label (good example)
doc.new_entry("example3", "simple_good", {
name="Label",
--[[ This is the proper way to add widgets (this is also how you should do it in build_formspec):
Defining the coordinates relative to the Documentation System's boundaries. In this case,
the label will be at the top right. ]]
data = "label["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";Just a good label.]"
})
-- Now let's get crazy with MULTIPLE formspec entries. How awesome is that?
doc.new_entry("example3", "multi", {
name="Label",
-- Label, just like before
data = "label["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";Just another label.]" ..
-- Note the different Y offsets
"button["..doc.FORMSPEC.ENTRY_START_X..","..(doc.FORMSPEC.ENTRY_START_Y + 1)..";5,1;example_useless;Useless button]" ..
"button["..doc.FORMSPEC.ENTRY_START_X..","..(doc.FORMSPEC.ENTRY_START_Y + 2)..";5,1;example_useless;Useless button 2]" ..
"button["..doc.FORMSPEC.ENTRY_START_X..","..(doc.FORMSPEC.ENTRY_START_Y + 3)..";5,1;example_useless;Useless button 3]"
-- As you see, it's special at all. It's a normal formspec string, just longer.
})
-- This entry will be interactive.
doc.new_entry("example3", "testbutton", {
name="Event Button",
-- This button actually will be used for an event …
data = "button[2,2;3,1;example_button;Event]",
data = "button["..doc.FORMSPEC.ENTRY_START_X..","..doc.FORMSPEC.ENTRY_START_Y..";5,1;example_button;Event]",
})
-- … and here we react on the button event by writing something into the chat