How to set GUI window position in the bottom right corner?

Place to get help with not working mods / modding interface.
Post Reply
Xiomax
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Mar 28, 2016 5:16 pm
Contact:

How to set GUI window position in the bottom right corner?

Post by Xiomax »

Total noob here, I'm trying to get the GUI in the bottom right corner at all times
Image

My code so far:

Code: Select all

local function set_hud_position(player)
	local root_frame = get_hud(player)
	if root_frame then
		local x = player.display_resolution.width - root_frame.style.width
		local y = root_frame.location.y
		root_frame.location = {x, y}
		player.print("gui location: x: " .. x)
	end
end

local function create_hud(player)
	-- Create frame in which to put the other GUI elements
	local root_frame = player.gui.screen.add {type = "frame", direction = "vertical", name = "hud-root-frame"}
	if global.hud_position_map[player.index] then
		local new_location = global.hud_position_map[player.index]
		root_frame.location = new_location
	end

	local title_flow = create_frame_title(root_frame, "Circuit HUD")

	-- add a "toggle" button
	global.toggle_button =
		title_flow.add {
		type = "sprite-button",
		style = "frame_action_button",
		sprite = (global.hud_collapsed_map[player.index] == true) and "utility/expand" or "utility/collapse",
		name = "toggle-circuit-hud"
	}

	local scroll_pane =
		root_frame.add {
		type = "scroll-pane",
		vertical_scroll_policy = "auto",
		style = "hud_scrollpane_style"
	}

	local inner_frame =
		scroll_pane.add {
		type = "frame",
		style = "inside_shallow_frame_with_padding",
		direction = "vertical"
	}

	global["last_frame"][player.index] = root_frame
	global["inner_frame"][player.index] = inner_frame
end
Changing the location works, but now I'm trying to find out the width and height of the GUI element so I can substract that from the display_resolution to keep the GUI in the screen. But for a GUI Element of type Frame there doesn't seem to be an option/value, debugging through the code doesn't reveal anything either.

Am I trying to do the impossible here?

Thanks in advance!

Post Reply

Return to “Modding help”