aardio窗體應用程序內置自定義漂亮消息提示框

職場菊菊子 2024-04-29 10:19:47

aardio是一門曆史悠久的國産編程語言。17年來,作者一直默默耕耘,不斷給aardio添加新功能,封裝新特性。

我們知道Windows應用程序自帶的消息對話框樣式不太好看。

aardio考慮到了用戶對于漂亮消息提示框的訴求,于是給我們內置了一個還算漂亮的消息對話框,用戶可以照葫蘆畫瓢,定義自己的消息對話框。

消息對話框效果

先睹爲快,看看aardio自定義的消息對話框效果。每個對話框左側的icon不一樣,icon可以自定義。每個消息框可以添加一個timeout參數,消息框超時後自動關閉。當前總共內置了以下幾種風格消息對話框,ok, error, info, warn, smile, frown, great, ask.

如何使用消息對話框

aardio消息對話框封裝在win.dlg.message。使用的時候需要導入該包,aardio會自動爲當前主窗口安裝msgInfo,msgAsk,msgErr等msg前綴的消息框函數。這類消息框函數有兩個參數,msg(必填)和timeout(可選)。簡單看看消息框函數源碼實現:

msgInfo = function(str,timeOut){ message(owner).info( str,timeOut ); }; msgErr = function(str,timeOut){ message(owner).err( str,timeOut ); }; msgWarn = function(str,timeOut){ message(owner).warn( str,timeOut ); }; msgGreat = function(str,timeOut){ message(owner).great( str,timeOut ); }; msgSmile = function(str,timeOut){ message(owner).smile( str,timeOut ); }; msgFrown = function(str,timeOut){ message(owner).frown( str,timeOut ); }; msgOk = function(str,timeOut){ message(owner).ok( str,timeOut ); }; msgSorry = function(str,timeOut){ message(owner).sorry( str,timeOut ); }; msgAsk = function(str){ return message(owner).ask( str ); };

然後我們就可以調用上述的msg函數。內置的幾個消息框左側的圖標不一樣,其他樣式都一樣。看看一個簡單的案例,使用上述msg消息框函數。

import fonts.fontAwesome;import win.ui;import win.dlg.message;/*DSG{{*/var winform = win.form(text="aardio form";right=759;bottom=469)winform.add(button={cls="button";text="Button";left=111;top=362;right=262;bottom=390;z=3};)/*}}*/winform.button.oncommand = function(id,event){ winform.msgSmile("smile"); winform.msgGreat("great", 1000); // 添加timeout自動關閉,單位爲毫秒 winform.msgFrown("frown"); winform.msgOk("ok"); winform.msgInfo("info"); winform.msgSorry("sorry"); winform.msgErr("error"); winform.msgAsk("ask"); winform.close();}winform.show();return win.loopMessage();消息對話框實現原理

翻看源碼,很容易看到自定義的消息對話框本質上就是一個單獨的窗體,該窗體包含兩個plus控件,一個負責左側圖標顯示,另一個負責展示消息。

var winform = ..win.form(text="info";right=831;bottom=679;bgcolor=this.bgcolor;border="none";exmode="toolwindow";min=false;parent=parentForm) if(!winform){ return; } winform.add( icon={cls="plus";text=this.icon;left=10;top=10;right=80;bottom=62;color=this.iconColor;dl=1;dt=1;font=LOGFONT(name='FontAwesomeDlg';h=-37);z=1}; message={cls="plus";text=msg;left=80;top=24;right=777;bottom=654;align="left";color=this.textColor;dl=1;dr=1;dl=1;dt=1;db=1;font=LOGFONT(h=-16);valign="top";z=2}; )

我們也可以新建一個win.dlg.message,然後自定義消息屬性,就可以做出符合自己項目的消息對話框了。下面是一個可以自定義設置的屬性

parent = 父窗口\n信息框顯示在父窗口中間,\n並在信息框關閉前禁用父窗口cancelLabel = 取消按鈕文本,支持fontAwesome圖標okLabel = 確定按鈕文本,支持fontAwesome圖標icon = Font Awesome字體圖標,請使用_FA_前綴常量指定;iconColor = 圖標顔色,GDI數值格式;textColor = 文本顔色,GDI數值格式bgcolor = 窗口背景顔色,GDI數值格式fadeInterval = 淡出淡出動畫時間間隔,設爲0不顯示動畫fadeDuration = 淡出淡出動畫時長create() = !winDlgMessageForm.create(.(顯示信息,是否顯示按鈕,是否顯示進度條) = 創建信息框,返回窗體對象,\n如果選擇顯示按鈕則不會同時顯示進度條\n所有參數都是可選參數doModal(.(顯示信息,是否顯示按鈕) = 創建信息框,並顯示爲模態窗口show(.(顯示信息) = = 創建信息框,並顯示爲非模態窗口info(__) = 顯示提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數\n\n如果指定參數@3或更多參數,\n則使用這些參數調用 string.format 格式化參數@1warn(__) = 顯示警告提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數ok(__) = 顯示正確提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數err(__) = 顯示錯誤提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數great(__) = 顯示豎大拇指圖標提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數sorry(__) = 顯示倒豎大拇指圖標提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數 smile(__) = 顯示微笑圖標提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數 frown(__) = 顯示皺眉圖標提示框,\n可選使用參數@2指定延時自動關閉提示框的毫秒數 ask(__) = 顯示詢問提示框\n用戶按確定或回車返回true,其他返回false或nullbuttonStyle = @.buttonStyle = { color = { hover = 0xF0FFFFFF; active = 0x30FFFFFF; default = 0x90FFFFFF; } border = { default = {width=0;} hover = { bottom = 1;color= 0xF0FFFFFF; } focus = { bottom = 1;color= 0xF0FFFFFF; } active = { bottom = 1;color= 0x30FFFFFF; } } }titlebarStyle = @.titlebarStyle = { color = { hover = 0xffffffff; active = 0x33ffffff; default = 0x66ffffff; }}
0 阅读:1

職場菊菊子

簡介:感謝大家的關注