From e5ee3109fe92c4786fb2482093a22cadea56f7ad Mon Sep 17 00:00:00 2001 From: trustable-code Date: Sat, 8 Jul 2017 22:53:50 +0200 Subject: Moved "msgbox.nim" inside "nigui" subdirectory --- src/msgbox.nim | 82 ---------------------------------------------------- src/nigui/msgbox.nim | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 82 deletions(-) delete mode 100755 src/msgbox.nim create mode 100755 src/nigui/msgbox.nim (limited to 'src') diff --git a/src/msgbox.nim b/src/msgbox.nim deleted file mode 100755 index 5071dfb..0000000 --- a/src/msgbox.nim +++ /dev/null @@ -1,82 +0,0 @@ -# NiGui - extended message box - -# This module provides an extended message box. -# The message box is shown as modal window. -# The message box can have up to 3 buttons with customizable titles. -# Call the proc msgBox() to open the message box. -# It will wait until the message box is closed. -# Meaning of the result value: -# 0 - message box was closed over the window close button -# 1..3 - button 1..3 clicked - -# For an example see "example_04_msgboxes.nim". - -import nigui - -type MessageBoxWindow = ref object of WindowImpl - clickedButton: Button - -proc buttonClick(event: ClickEvent) = - cast[MessageBoxWindow](event.control.parentWindow).clickedButton = cast[Button](event.control) - event.control.parentWindow.dispose() - -proc msgBox*(parent: Window, message: string, title = "Message", button1 = "OK", button2, button3: string = nil): int {.discardable.} = - const buttonMinWidth = 100 - var window = new MessageBoxWindow - window.init() - window.title = title - - var container = newLayoutContainer(Layout_Vertical) - container.padding = 10 - window.control = container - - var labelContainer = newLayoutContainer(Layout_Horizontal) - container.add(labelContainer) - labelContainer.widthMode = WidthMode_Expand - labelContainer.heightMode = HeightMode_Expand - - var label = newLabel(message) - labelContainer.add(label) - - var buttonContainer = newLayoutContainer(Layout_Horizontal) - buttonContainer.widthMode = WidthMode_Expand - buttonContainer.xAlign = XAlign_Center - buttonContainer.spacing = 12 - container.add(buttonContainer) - var b1, b2, b3: Button - - b1 = newButton(button1) - b1.minWidth = buttonMinWidth - b1.onClick = buttonClick - buttonContainer.add(b1) - - if button2 != nil: - b2 = newButton(button2) - b2.minWidth = buttonMinWidth - b2.onClick = buttonClick - buttonContainer.add(b2) - - if button3 != nil: - b3 = newButton(button3) - b3.minWidth = buttonMinWidth - b3.onClick = buttonClick - buttonContainer.add(b3) - - window.width = min(max(label.width + 40, buttonMinWidth * 3 + 65), 600) - window.height = min(label.height, 300) + buttonContainer.height + 70 - - # Center message box on window: - window.x = parent.x + ((parent.width - window.width) div 2) - window.y = parent.y + ((parent.height - window.height) div 2) - - window.showModal(parent) - - while not window.disposed: - app.sleep(100) - - if window.clickedButton == b1: - result = 1 - elif window.clickedButton == b2: - result = 2 - elif window.clickedButton == b3: - result = 3 diff --git a/src/nigui/msgbox.nim b/src/nigui/msgbox.nim new file mode 100755 index 0000000..5071dfb --- /dev/null +++ b/src/nigui/msgbox.nim @@ -0,0 +1,82 @@ +# NiGui - extended message box + +# This module provides an extended message box. +# The message box is shown as modal window. +# The message box can have up to 3 buttons with customizable titles. +# Call the proc msgBox() to open the message box. +# It will wait until the message box is closed. +# Meaning of the result value: +# 0 - message box was closed over the window close button +# 1..3 - button 1..3 clicked + +# For an example see "example_04_msgboxes.nim". + +import nigui + +type MessageBoxWindow = ref object of WindowImpl + clickedButton: Button + +proc buttonClick(event: ClickEvent) = + cast[MessageBoxWindow](event.control.parentWindow).clickedButton = cast[Button](event.control) + event.control.parentWindow.dispose() + +proc msgBox*(parent: Window, message: string, title = "Message", button1 = "OK", button2, button3: string = nil): int {.discardable.} = + const buttonMinWidth = 100 + var window = new MessageBoxWindow + window.init() + window.title = title + + var container = newLayoutContainer(Layout_Vertical) + container.padding = 10 + window.control = container + + var labelContainer = newLayoutContainer(Layout_Horizontal) + container.add(labelContainer) + labelContainer.widthMode = WidthMode_Expand + labelContainer.heightMode = HeightMode_Expand + + var label = newLabel(message) + labelContainer.add(label) + + var buttonContainer = newLayoutContainer(Layout_Horizontal) + buttonContainer.widthMode = WidthMode_Expand + buttonContainer.xAlign = XAlign_Center + buttonContainer.spacing = 12 + container.add(buttonContainer) + var b1, b2, b3: Button + + b1 = newButton(button1) + b1.minWidth = buttonMinWidth + b1.onClick = buttonClick + buttonContainer.add(b1) + + if button2 != nil: + b2 = newButton(button2) + b2.minWidth = buttonMinWidth + b2.onClick = buttonClick + buttonContainer.add(b2) + + if button3 != nil: + b3 = newButton(button3) + b3.minWidth = buttonMinWidth + b3.onClick = buttonClick + buttonContainer.add(b3) + + window.width = min(max(label.width + 40, buttonMinWidth * 3 + 65), 600) + window.height = min(label.height, 300) + buttonContainer.height + 70 + + # Center message box on window: + window.x = parent.x + ((parent.width - window.width) div 2) + window.y = parent.y + ((parent.height - window.height) div 2) + + window.showModal(parent) + + while not window.disposed: + app.sleep(100) + + if window.clickedButton == b1: + result = 1 + elif window.clickedButton == b2: + result = 2 + elif window.clickedButton == b3: + result = 3 -- cgit v1.2.3