Skip to content

Commit

Permalink
[Dialog]
Browse files Browse the repository at this point in the history
Moved message box handling to Dialog namespace. FileDialog function depends on this.
  • Loading branch information
coding-jackalope committed Apr 14, 2020
1 parent 3efd6a5 commit 05f95f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
33 changes: 1 addition & 32 deletions API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1359,38 +1359,7 @@ end
Return: [String] The name of the button that was clicked. If none was clicked, an emtpy string is returned.
--]]
function Slab.MessageBox(Title, Message, Options)
Options = Options == nil and {} or Options
Options.Buttons = Options.Buttons == nil and {"OK"} or Options.Buttons

local Result = ""

Slab.OpenDialog('MessageBox')
if Slab.BeginDialog('MessageBox', {Title = Title, Border = 12}) then
Slab.BeginLayout('MessageBox_Message_Layout', {AlignX = 'center', AlignY = 'center'})
local TextW = math.min(Slab.GetTextWidth(Message), love.graphics.getWidth() * 0.80)
Slab.Textf(Message, {Align = 'center', W = TextW})
Slab.EndLayout()

Slab.NewLine()
Slab.NewLine()

Slab.BeginLayout('MessageBox_Buttons_Layout', {AlignX = 'right', AlignY = 'bottom'})
for I, V in ipairs(Options.Buttons) do
if Button.Begin(V) then
Result = V
end
Slab.SameLine()
end
Slab.EndLayout()

if Result ~= "" then
Slab.CloseDialog()
end

Slab.EndDialog()
end

return Result
return Dialog.MessageBox(Title, Message, Options)
end

--[[
Expand Down
36 changes: 36 additions & 0 deletions Internal/UI/Dialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,42 @@ function Dialog.IsOpen()
return #Stack > 0
end

function Dialog.MessageBox(Title, Message, Options)
local Result = ""
Dialog.Open('MessageBox')
if Dialog.Begin('MessageBox', {Title = Title, Border = 12}) then
Options = Options == nil and {} or Options
Options.Buttons = Options.Buttons == nil and {"OK"} or Options.Buttons

LayoutManager.Begin('MessageBox_Message_Layout', {AlignX = 'center', AlignY = 'center'})
LayoutManager.NewLine()
local TextW = min(Text.GetWidth(Message), love.graphics.getWidth() * 0.80)
Text.BeginFormatted(Message, {Align = 'center', W = TextW})
LayoutManager.End()

Cursor.NewLine()
Cursor.NewLine()

LayoutManager.Begin('MessageBox_Buttons_Layout', {AlignX = 'right', AlignY = 'bottom'})
for I, V in ipairs(Options.Buttons) do
if Button.Begin(V) then
Result = V
end
Cursor.SameLine()
LayoutManager.SameLine()
end
LayoutManager.End()

if Result ~= "" then
Dialog.Close()
end

Dialog.End()
end

return Result
end

function Dialog.FileDialog(Options)
Options = Options == nil and {} or Options
Options.AllowMultiSelect = Options.AllowMultiSelect == nil and true or Options.AllowMultiSelect
Expand Down
2 changes: 0 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
v0.6.3 RELEASE
==========
[FileSystem]: Test file system on Linux.
[FileSystem]: Investigate crash when selecting an existing file in Save Dialog.
[Wiki]: Include gif of new close button support.

v0.7.0 RELEASE
Expand Down

0 comments on commit 05f95f4

Please sign in to comment.