Skip to content

Commit

Permalink
Add scroll_container formspec element (redo) (#9101)
Browse files Browse the repository at this point in the history
New formspec elements:

 - `scroll_container[<X>,<Y>;<W>,<H>;<scrollbar name>;<orientation>;<scroll factor>]`
 - `scroll_container_end[]`

Other elements can be embedded in this element. Scrollbar must be placed manually.
  • Loading branch information
Desour committed Apr 13, 2020
1 parent 6cf15cf commit 0ac999d
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 50 deletions.
1 change: 1 addition & 0 deletions build/android/jni/Android.mk
Expand Up @@ -194,6 +194,7 @@ LOCAL_SRC_FILES := \
jni/src/gui/guiPasswordChange.cpp \
jni/src/gui/guiPathSelectMenu.cpp \
jni/src/gui/guiScrollBar.cpp \
jni/src/gui/guiScrollContainer.cpp \
jni/src/gui/guiSkin.cpp \
jni/src/gui/guiTable.cpp \
jni/src/gui/guiVolumeChange.cpp \
Expand Down
20 changes: 20 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -2102,6 +2102,26 @@ Elements
* End of a container, following elements are no longer relative to this
container.

### `scroll_container[<X>,<Y>;<W>,<H>;<scrollbar name>;<orientation>;<scroll factor>]`

* Start of a scroll_container block. All contained elements will ...
* take the scroll_container coordinate as position origin,
* be additionally moved by the current value of the scrollbar with the name
`scrollbar name` times `scroll factor` along the orientation `orientation` and
* be clipped to the rectangle defined by `X`, `Y`, `W` and `H`.
* `orientation`: possible values are `vertical` and `horizontal`.
* `scroll factor`: optional, defaults to `0.1`.
* Nesting is possible.
* Some elements might work a little different if they are in a scroll_container.
* Note: If you want the scroll_container to actually work, you also need to add a
scrollbar element with the specified name. Furthermore, it is highly recommended
to use a scrollbaroptions element on this scrollbar.

### `scroll_container_end[]`

* End of a scroll_container, following elements are no longer bound to this
container.

### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]`

* Show an inventory list if it has been sent to the client. Nothing will
Expand Down
69 changes: 67 additions & 2 deletions games/minimal/mods/test/formspec.lua
@@ -1,5 +1,35 @@
local color = minetest.colorize

local hypertext = minetest.formspec_escape([[
<global halign=justify valign=center background=#CCF color=#444 actioncolor=darkblue margin=10>
<center><bigger>Furnace</bigger></center>
<style color=black>Furnaces</style> are <action name="crafting">crafted</action> and used by the player for the purpose of cooking food and <action name="smelting">smelting</action> various items.
<item name=default:furnace float=right width=128 rotate=yes>
<style color=black>Type:</style> Solid block
<style color=black>Drops:</style> Itself
<style color=black>Physics:</style> No
<style color=black>Luminance:</style> Inactive:No Active:Yes (8)
<style color=black>Flammable:</style> No
<style color=black>Generated:</style> No
<style color=black>Renewable:</style> Yes
<style color=black>Stackable:</style> Yes (99)
<style color=black>Itemstring:</style> default:furnace default:furnace_active
<big>Usage</big>
The furnace menu can be accessed by <action name="using">using</action> the furnace.
The furnace has 3 <action name="inventory">inventories</action>: An input slot, a fuel slot and 4 output slots. The fire in the furnace will automatically start when there is a smeltable item in the input slot and a fuel in the fuel slot.
As long as the fire is on, the furnace will smelt any smeltable item in the input slot, one by one, until it is empty. When the fire goes off, it will smelt the next item until there are no smeltable items and no fuel items left.
The current stage of cooking can be seen by <action name="pointing">pointing</action> the furnace or by viewing the furnace menu. In the furnace menu, the flame symbol roughly shows the remaining burning time. The arrow symbol shows the progress of the current smelting process.
<big>Renewing</big>
Furnaces can be crafted from e.g. <action name="default:cobblestone">cobblestone</action>, a renewable resource.
<big>Crafting</big>
Sorry no way to display crafting yet in formspec pages.
<big>Fuel</big>
See <action name="smelting">Smelting</action> for a list of furnace fuels.
<big>Recipes</big>
See the <action name="smelting">Smelting</action> page.
]])


local clip_fs = [[
style_type[label,button,image_button,item_image_button,
tabheader,scrollbar,table,animated_image
Expand Down Expand Up @@ -188,13 +218,48 @@ Number]
animated_image[3,4.25;1,1;;test_animation.png;4;0;3]
animated_image[5.5,0.5;5,2;;test_animation.png;4;100]
animated_image[5.5,2.75;5,2;;test_animation.jpg;4;100]
]]
]],

"formspec_version[3]"..
"size[12,12]"..
"button[8.5,1;1,1;bla;Bla]"..
"box[1,1;8,6;#00aa]"..
"scroll_container[1,1;8,6;scrbar;vertical]"..
"button[0,1;1,1;lorem;Lorem]"..
"button[0,10;1,1;ipsum;Ipsum]"..
"pwdfield[2,2;1,1;lorem2;Lorem]"..
"list[current_player;main;4,4;1,5;]"..
"box[2,5;3,2;#ffff00]"..
"image[1,10;3,2;bubble.png]"..
"image[3,1;bubble.png]"..
"item_image[2,6;3,2;default:mese]"..
"label[2,15;bla Bli\nfoo bar]"..
"item_image_button[2,3;1,1;default:dirt_with_grass;itemimagebutton;ItemImageButton]"..
"tooltip[0,11;3,2;Buz;#f00;#000]"..
"box[0,11;3,2;#00ff00]"..
"hypertext[3,13;3,3;;" .. hypertext .. "]" ..
"container[0,18]"..
"box[1,2;3,2;#0a0a]"..
"scroll_container[1,2;3,2;scrbar2;horizontal;0.06]"..
"button[0,0;6,1;butnest;Nest]"..
"label[10,0.5;nest]"..
"scroll_container_end[]"..
"scrollbar[1,0;3.5,0.3;horizontal;scrbar2;0]"..
"container_end[]"..
"dropdown[0,6;2;hmdrpdwn;apple,bulb;1]"..
"image_button[0,4;2,2;bubble.png;bubblebutton;bbbbtt;false;true;heart.png]"..
"box[1,22.5;4,1;#a00a]"..
"scroll_container_end[]"..
"scrollbaroptions[max=170]".. -- lowest seen pos is: 0.1*170+6=23 (factor*max+height)
"scrollbar[7.5,0;0.3,4;vertical;scrbar;0]"..
"scrollbar[8,0;0.3,4;vertical;scrbarhmmm;0]"..
"dropdown[0,6;2;hmdrpdwnnn;apple,bulb;1]",
}

local function show_test_formspec(pname, page_id)
page_id = page_id or 2

local fs = pages[page_id] .. "tabheader[0,0;6,0.65;maintabs;Real Coord,Styles,Noclip,MiscEle;" .. page_id .. ";false;false]"
local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,MiscEle,Scroll Container;" .. page_id .. ";false;false]"

minetest.show_formspec(pname, "test:formspec", fs)
end
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ set(gui_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollContainer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp
Expand Down

0 comments on commit 0ac999d

Please sign in to comment.