mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 16:28:23 +00:00
more window stuff
This commit is contained in:
@@ -3,6 +3,7 @@ local Backend = require 'luigi.backend'
|
|||||||
|
|
||||||
local window = Layout {
|
local window = Layout {
|
||||||
type = 'window',
|
type = 'window',
|
||||||
|
background = { 255, 255, 255 },
|
||||||
icon = 'logo.png',
|
icon = 'logo.png',
|
||||||
title = 'Test window',
|
title = 'Test window',
|
||||||
width = 300,
|
width = 300,
|
||||||
@@ -11,9 +12,37 @@ local window = Layout {
|
|||||||
minheight = 100,
|
minheight = 100,
|
||||||
maxwidth = 640,
|
maxwidth = 640,
|
||||||
maxheight = 480,
|
maxheight = 480,
|
||||||
{ type = 'button', id = 'maximize', text = 'Maximize' },
|
left = 400,
|
||||||
{ type = 'button', id = 'minimize', text = 'Minimize' },
|
top = 400,
|
||||||
{ type = 'button', id = 'restore', text = 'Restore' },
|
{ type = 'panel',
|
||||||
|
{
|
||||||
|
text = 'This is an example of the "window" widget type.',
|
||||||
|
align = 'middle center', wrap = true,
|
||||||
|
},
|
||||||
|
{ flow = 'x', height = 'auto',
|
||||||
|
{ type = 'button', id = 'maximize', text = 'Maximize' },
|
||||||
|
{ type = 'button', id = 'minimize', text = 'Minimize' },
|
||||||
|
{ type = 'button', id = 'restore', text = 'Restore' },
|
||||||
|
},
|
||||||
|
{ flow = 'x', height = 'auto',
|
||||||
|
{
|
||||||
|
{ type = 'label', text = 'Left' },
|
||||||
|
{ type = 'text', id = 'left' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ type = 'label', text = 'Top' },
|
||||||
|
{ type = 'text', id = 'top' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ type = 'label', text = 'Width' },
|
||||||
|
{ type = 'text', id = 'width' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ type = 'label', text = 'Height' },
|
||||||
|
{ type = 'text', id = 'height' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.maximize:onPress(function ()
|
window.maximize:onPress(function ()
|
||||||
@@ -25,6 +54,20 @@ end)
|
|||||||
window.restore:onPress(function ()
|
window.restore:onPress(function ()
|
||||||
window.root.maximized = false
|
window.root.maximized = false
|
||||||
end)
|
end)
|
||||||
|
window:onReshape(function (event)
|
||||||
|
local w, h = Backend:getWindowSize()
|
||||||
|
-- use widget.attributes to do a raw update, avoid firing onChange
|
||||||
|
window.width.attributes.value = tostring(w)
|
||||||
|
window.height.attributes.value = tostring(h)
|
||||||
|
end)
|
||||||
|
window:onChange(function (event)
|
||||||
|
local target = event.target
|
||||||
|
if target.type ~= 'text' then return end
|
||||||
|
local id = target.id
|
||||||
|
if id and window.root.attributeDescriptors[id] then
|
||||||
|
window.root[id] = tonumber(event.value)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
window:show()
|
window:show()
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
local ROOT = (...):gsub('[^.]*$', '')
|
local ROOT = (...):gsub('[^.]*$', '')
|
||||||
|
|
||||||
local Backend
|
|
||||||
|
|
||||||
if _G.love and _G.love._version_minor > 8 then
|
if _G.love and _G.love._version_minor > 8 then
|
||||||
return require(ROOT .. 'backend.love')
|
return require(ROOT .. 'backend.love')
|
||||||
else
|
else
|
||||||
return require(ROOT .. 'backend.ffisdl')
|
return require(ROOT .. 'backend.ffisdl')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ local Renderer = Base:extend()
|
|||||||
local imageCache = {}
|
local imageCache = {}
|
||||||
local sliceCache = {}
|
local sliceCache = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function intersectScissor (x, y, w, h)
|
local function intersectScissor (x, y, w, h)
|
||||||
local sx, sy, sw, sh = Backend.getScissor()
|
local sx, sy, sw, sh = Backend.getScissor()
|
||||||
if not sx then
|
if not sx then
|
||||||
@@ -128,7 +126,7 @@ end
|
|||||||
|
|
||||||
-- returns icon coordinates and rectangle with remaining space
|
-- returns icon coordinates and rectangle with remaining space
|
||||||
function Renderer:positionIcon (widget, x1, y1, x2, y2)
|
function Renderer:positionIcon (widget, x1, y1, x2, y2)
|
||||||
if not widget.attributes.icon then
|
if not widget.icon then
|
||||||
return nil, nil, x1, y1, x2, y2
|
return nil, nil, x1, y1, x2, y2
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -167,11 +165,7 @@ function Renderer:positionText (widget, x1, y1, x2, y2)
|
|||||||
return nil, nil, x1, y1, x2, y2
|
return nil, nil, x1, y1, x2, y2
|
||||||
end
|
end
|
||||||
|
|
||||||
if not widget.fontData then
|
local font = widget:getFont()
|
||||||
widget.fontData = Font(widget.font, widget.size)
|
|
||||||
end
|
|
||||||
|
|
||||||
local font = widget.fontData
|
|
||||||
local align = widget.align or ''
|
local align = widget.align or ''
|
||||||
local horizontal = 'left'
|
local horizontal = 'left'
|
||||||
|
|
||||||
@@ -206,12 +200,9 @@ function Renderer:positionText (widget, x1, y1, x2, y2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Renderer:renderIconAndText (widget)
|
function Renderer:renderIconAndText (widget)
|
||||||
|
if not (widget.icon or widget.text) then return end
|
||||||
local x, y, w, h = widget:getRectangle(true, true)
|
local x, y, w, h = widget:getRectangle(true, true)
|
||||||
|
if w < 1 or h < 1 then return end
|
||||||
-- if the drawable area has no width or height, don't render
|
|
||||||
if w < 1 or h < 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- calculate position for icon and text based on alignment and padding
|
-- calculate position for icon and text based on alignment and padding
|
||||||
local iconX, iconY, x1, y1, x2, y2 = self:positionIcon(
|
local iconX, iconY, x1, y1, x2, y2 = self:positionIcon(
|
||||||
@@ -219,7 +210,7 @@ function Renderer:renderIconAndText (widget)
|
|||||||
local font, textX, textY = self:positionText(
|
local font, textX, textY = self:positionText(
|
||||||
widget, x1, y1, x2, y2)
|
widget, x1, y1, x2, y2)
|
||||||
|
|
||||||
local icon = widget.attributes.icon and self:loadImage(widget.icon)
|
local icon = widget.icon and self:loadImage(widget.icon)
|
||||||
local text = widget.text
|
local text = widget.text
|
||||||
local align = widget.align or ''
|
local align = widget.align or ''
|
||||||
local padding = widget.padding or 0
|
local padding = widget.padding or 0
|
||||||
|
|||||||
@@ -634,6 +634,13 @@ function Widget:getContentHeight ()
|
|||||||
return height
|
return height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Widget:getFont ()
|
||||||
|
if not self.fontData then
|
||||||
|
self.fontData = Font(self.font, self.size)
|
||||||
|
end
|
||||||
|
return self.fontData
|
||||||
|
end
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Get x/y/width/height values describing a rectangle within the widget.
|
Get x/y/width/height values describing a rectangle within the widget.
|
||||||
|
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ This color is used to indicate the selected range of text.
|
|||||||
local startX, endX = self.startX or 0, self.endX or 0
|
local startX, endX = self.startX or 0, self.endX or 0
|
||||||
local x, y, w, h = self:getRectangle(true, true)
|
local x, y, w, h = self:getRectangle(true, true)
|
||||||
local width, height = endX - startX, h
|
local width, height = endX - startX, h
|
||||||
local font = self.fontData
|
local font = self:getFont()
|
||||||
local color = self.color or { 0, 0, 0, 255 }
|
local color = self.color or { 0, 0, 0, 255 }
|
||||||
local textTop = math.floor(y + (h - font:getLineHeight()) / 2)
|
local textTop = math.floor(y + (h - font:getLineHeight()) / 2)
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ Set to `false` to restore the size and position.
|
|||||||
set = function (_, value)
|
set = function (_, value)
|
||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowMaximized(value)
|
Backend.setWindowMaximized(value)
|
||||||
|
self.layout.root:reshape()
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowMaximized
|
get = Backend.getWindowMaximized
|
||||||
})
|
})
|
||||||
@@ -79,6 +80,7 @@ You can't change the border state of a fullscreen window.
|
|||||||
set = function (_, value)
|
set = function (_, value)
|
||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowBorderless(value)
|
Backend.setWindowBorderless(value)
|
||||||
|
self.layout.root:reshape()
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowBorderless
|
get = Backend.getWindowBorderless
|
||||||
})
|
})
|
||||||
@@ -93,6 +95,7 @@ of the window.
|
|||||||
set = function (_, value)
|
set = function (_, value)
|
||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowFullscreen(value)
|
Backend.setWindowFullscreen(value)
|
||||||
|
self.layout.root:reshape()
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowFullscreen
|
get = Backend.getWindowFullscreen
|
||||||
})
|
})
|
||||||
@@ -127,10 +130,8 @@ Window icon. Should be a string containing a path to an image.
|
|||||||
icon = value
|
icon = value
|
||||||
Backend.setWindowIcon(value)
|
Backend.setWindowIcon(value)
|
||||||
end,
|
end,
|
||||||
get = function () return icon end
|
-- get = function () return false end
|
||||||
})
|
})
|
||||||
|
|
||||||
self.attributes.icon = nil
|
|
||||||
--[[--
|
--[[--
|
||||||
Maximum width of the window's client area.
|
Maximum width of the window's client area.
|
||||||
|
|
||||||
@@ -193,7 +194,7 @@ Position of the window's top edge.
|
|||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowTop(value)
|
Backend.setWindowTop(value)
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowTop
|
-- get = Backend.getWindowTop
|
||||||
})
|
})
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
@@ -206,7 +207,7 @@ Position of the window's left edge.
|
|||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowLeft(value)
|
Backend.setWindowLeft(value)
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowLeft
|
-- get = Backend.getWindowLeft
|
||||||
})
|
})
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
@@ -218,6 +219,7 @@ Width of the window's content area.
|
|||||||
set = function (_, value)
|
set = function (_, value)
|
||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowWidth(value)
|
Backend.setWindowWidth(value)
|
||||||
|
self.layout.root:reshape()
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowWidth
|
get = Backend.getWindowWidth
|
||||||
})
|
})
|
||||||
@@ -231,6 +233,7 @@ Height of the window's content area.
|
|||||||
set = function (_, value)
|
set = function (_, value)
|
||||||
if value == nil then return end
|
if value == nil then return end
|
||||||
Backend.setWindowHeight(value)
|
Backend.setWindowHeight(value)
|
||||||
|
self.layout.root:reshape()
|
||||||
end,
|
end,
|
||||||
get = Backend.getWindowHeight
|
get = Backend.getWindowHeight
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user