From 57c1e20ace81a24db30d239981d8f7888ef190ad Mon Sep 17 00:00:00 2001 From: luk3yx Date: Sat, 8 Jul 2023 12:17:30 +1200 Subject: [PATCH] Reset bgimg style when centering labels --- README.md | 1 + init.lua | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0278810..3a162e0 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ These utilities likely aren't compatible with flow. - [Just_Visiting's formspec editor](https://content.minetest.net/packages/Just_Visiting/formspec_editor) is a Minetest (sub)game that lets you edit formspecs and preview them as you go - [kuto](https://github.com/TerraQuest-Studios/kuto/) is a formspec library that has some extra widgets/components and has a callback API. Some automatic sizing can be done for buttons. - It may be possible to use kuto's components with flow somehow as they both use formspec_ast internally. + - kuto was the the source of the "on_event" function idea. - [My web-based formspec editor](https://forum.minetest.net/viewtopic.php?f=14&t=24130) lets you add elements and drag+drop them, however it doesn't support all formspec features. ## Elements diff --git a/init.lua b/init.lua index a0d1997..af4ed93 100644 --- a/init.lua +++ b/init.lua @@ -309,29 +309,51 @@ function align_types.fill(node, x, w, extra_space) -- Hack node.type = "container" + + -- Reset bgimg, some games apply styling to all image_buttons inside + -- the formspec prepend node[1] = { + type = "style", + -- MT 5.1.0 only supports one style selector + selectors = {"\1"}, + + -- bgimg_pressed is included for 5.1.0 support + -- bgimg_hovered is unnecessary as it was added in 5.2.0 (which + -- also adds support for :hovered and :pressed) + props = {bgimg = "", bgimg_pressed = ""}, + } + + -- Use the newer pressed selector as well in case the deprecated one is + -- removed + node[2] = { + type = "style", + selectors = {"\1:hovered", "\1:pressed"}, + props = {bgimg = ""}, + } + + node[3] = { type = "image_button", texture_name = "blank.png", drawborder = false, x = 0, y = 0, w = node.w + extra_space, h = node.h, - label = node.label, + name = "\1", label = node.label, } -- Overlay button to prevent clicks from doing anything - node[2] = { + node[4] = { type = "image_button", texture_name = "blank.png", drawborder = false, x = 0, y = 0, w = node.w + extra_space, h = node.h, - label = "", + name = "\1", label = "", } node.y = node.y - LABEL_OFFSET node.label = nil node._label_hack = true - assert(#node == 2) + assert(#node == 4) end if node[w] then