ui - pkg.dev
文章推薦指數: 80 %
github.com/andlabs/ui ... ui: platform-native GUI library for Go ... Main initializes package ui, runs f to set up the program, and executes ...
WhyGo
GetStarted
Packages
Blog
Details
Validgo.modfile
TheGomodulesystemwasintroducedinGo1.11andistheofficialdependencymanagement
solutionforGo.
Redistributablelicense
Redistributablelicensesplaceminimalrestrictionsonhowsoftwarecanbeused,
modified,andredistributed.
Taggedversion
Moduleswithtaggedversionsgiveimportersmorepredictablebuilds.
Stableversion
Whenaprojectreachesmajorversionv1itisconsideredstable.
Learnmore
Repository
github.com/andlabs/ui
Jumpto...
README
ui:platform-nativeGUIlibraryforGo
Status
Installation
Documentation
Windowsmanifests
macOSprogramexecution
Documentation
Index
Constants
Variables
Functions
LibuiFreeText(c)
Main(f)
MsgBox(w,title,description)
MsgBoxError(w,title,description)
OnShouldQuit(f)
OpenFile(w)
QueueMain(f)
Quit()
SaveFile(w)
Types
typeAlign
typeArea
NewArea(handler)
NewScrollingArea(handler,width,height)
(a)Destroy()
(a)QueueRedrawAll()
(a)ScrollTo(x,y,width,height)
(a)SetSize(width,height)
typeAreaDrawParams
typeAreaHandler
typeAreaKeyEvent
typeAreaMouseEvent
typeAt
typeAttribute
typeAttributedString
NewAttributedString(initialString)
(s)AppendUnattributed(str)
(s)Delete(start,end)
(s)Free()
(s)InsertAtUnattributed(str,at)
(s)SetAttribute(a,start,end)
(s)String()
typeBox
NewHorizontalBox()
NewVerticalBox()
(b)Append(child,stretchy)
(b)Delete(n)
(b)Destroy()
(b)Padded()
(b)SetPadded(padded)
typeButton
NewButton(text)
(b)OnClicked(f)
(b)SetText(text)
(b)Text()
typeCheckbox
NewCheckbox(text)
(c)Checked()
(c)OnToggled(f)
(c)SetChecked(checked)
(c)SetText(text)
(c)Text()
typeColorButton
NewColorButton()
(b)Color()
(b)OnChanged(f)
(b)SetColor(r,g,bl,a)
typeCombobox
NewCombobox()
(c)Append(text)
(c)OnSelected(f)
(c)Selected()
(c)SetSelected(index)
typeControl
ControlFromLibui(c)
typeControlBase
NewControlBase(iface,c)
(c)Destroy()
(c)Disable()
(c)Enable()
(c)Enabled()
(c)Handle()
(c)Hide()
(c)LibuiControl()
(c)Show()
(c)Visible()
typeDateTimePicker
NewDatePicker()
NewDateTimePicker()
NewTimePicker()
(d)OnChanged(f)
(d)SetTime(t)
(d)Time()
typeDrawBrush
typeDrawBrushType
typeDrawContext
(c)Clip(p)
(c)Fill(p,b)
(c)Restore()
(c)Save()
(c)Stroke(p,b,sp)
(c)Text(tl,x,y)
(c)Transform(m)
typeDrawFillMode
typeDrawGradientStop
typeDrawLineCap
typeDrawLineJoin
typeDrawMatrix
DrawNewMatrix()
(m)Invert()
(m)Invertible()
(m)Multiply(m2)
(m)Rotate(x,y,amount)
(m)Scale(xCenter,yCenter,x,y)
(m)SetIdentity()
(m)Skew(x,y,xamount,yamount)
(m)TransformPoint(x,y)
(m)TransformSize(x,y)
(m)Translate(x,y)
typeDrawPath
DrawNewPath(fillMode)
(p)AddRectangle(x,y,width,height)
(p)ArcTo(xCenter,yCenter,radius,startAngle,sweep,isNegative)
(p)BezierTo(c1x,c1y,c2x,c2y,endX,endY)
(p)CloseFigure()
(p)End()
(p)Free()
(p)LineTo(x,y)
(p)NewFigure(x,y)
(p)NewFigureWithArc(xCenter,yCenter,radius,startAngle,sweep,isNegative)
typeDrawStrokeParams
typeDrawTextAlign
typeDrawTextLayout
DrawNewTextLayout(p)
(tl)Free()
typeDrawTextLayoutParams
typeEditableCombobox
NewEditableCombobox()
(e)Append(text)
(e)OnChanged(f)
(e)SetText(text)
(e)Text()
typeEntry
NewEntry()
NewPasswordEntry()
NewSearchEntry()
(e)OnChanged(f)
(e)ReadOnly()
(e)SetReadOnly(ro)
(e)SetText(text)
(e)Text()
typeExtKey
typeFontButton
NewFontButton()
(b)Font()
(b)OnChanged(f)
typeFontDescriptor
typeForm
NewForm()
(f)Append(label,child,stretchy)
(f)Delete(n)
(f)Destroy()
(f)Padded()
(f)SetPadded(padded)
typeGrid
NewGrid()
(g)Append(child,left,top,xspan,yspan,hexpand,halign,vexpand,valign)
(g)InsertAt(child,existing,at,xspan,yspan,hexpand,halign,vexpand,valign)
(g)Padded()
(g)SetPadded(padded)
typeGroup
NewGroup(title)
(g)Destroy()
(g)Margined()
(g)SetChild(child)
(g)SetMargined(margined)
(g)SetTitle(title)
(g)Title()
typeImage
NewImage(width,height)
(i)Append(img)
(i)Free()
typeLabel
NewLabel(text)
(l)SetText(text)
(l)Text()
typeModifiers
typeMultilineEntry
NewMultilineEntry()
NewNonWrappingMultilineEntry()
(m)Append(text)
(m)OnChanged(f)
(m)ReadOnly()
(m)SetReadOnly(ro)
(m)SetText(text)
(m)Text()
typeOpenTypeFeatures
typeOpenTypeTag
ToOpenTypeTag(a,b,c,d)
typeProgressBar
NewProgressBar()
(p)SetValue(value)
(p)Value()
typeRadioButtons
NewRadioButtons()
(r)Append(text)
(r)OnSelected(f)
(r)Selected()
(r)SetSelected(index)
typeSeparator
NewHorizontalSeparator()
NewVerticalSeparator()
typeSlider
NewSlider(min,max)
(s)OnChanged(f)
(s)SetValue(value)
(s)Value()
typeSpinbox
NewSpinbox(min,max)
(s)OnChanged(f)
(s)SetValue(value)
(s)Value()
typeTab
NewTab()
(t)Append(name,child)
(t)Delete(n)
(t)Destroy()
(t)InsertAt(name,n,child)
(t)Margined(n)
(t)NumPages()
(t)SetMargined(n,margined)
typeTable
NewTable(p)
(t)AppendButtonColumn(name,buttonModelColumn,buttonClickableModelColumn)
(t)AppendCheckboxColumn(name,checkboxModelColumn,checkboxEditableModelColumn)
(t)AppendCheckboxTextColumn(name,checkboxModelColumn,checkboxEditableModelColumn,textModelColumn,...)
(t)AppendImageColumn(name,imageModelColumn)
(t)AppendImageTextColumn(name,imageModelColumn,textModelColumn,textEditableModelColumn,textParams)
(t)AppendProgressBarColumn(name,progressModelColumn)
(t)AppendTextColumn(name,textModelColumn,textEditableModelColumn,textParams)
typeTableColor
typeTableImage
typeTableInt
typeTableModel
NewTableModel(handler)
(m)Free()
(m)RowChanged(index)
(m)RowDeleted(index)
(m)RowInserted(index)
typeTableModelHandler
typeTableParams
typeTableString
typeTableTextColumnOptionalParams
typeTableValue
typeTextBackground
typeTextColor
typeTextFamily
typeTextItalic
typeTextSize
typeTextStretch
typeTextWeight
typeUnderline
typeUnderlineColor
typeUnderlineColorCustom
typeWindow
NewWindow(title,width,height,hasMenubar)
(w)Borderless()
(w)Destroy()
(w)Margined()
(w)OnClosing(f)
(w)SetBorderless(borderless)
(w)SetChild(child)
(w)SetMargined(margined)
(w)SetTitle(title)
(w)Title()
SourceFiles
Directories
README
README
¶
ui:platform-nativeGUIlibraryforGo
ThisisalibrarythataimstoprovidesimpleGUIsoftwaredevelopmentinGo.Itisbasedonmylibui,asimplecross-platformlibrarythatdoesthesamething,butwritteninC.
Itrunson/requires:
Windows:cgo,WindowsVistaSP2withPlatformUpdateandnewer
MacOSX:cgo,MacOSX10.8andnewer
otherUnixes:cgo,GTK+3.10andnewer
Debian,Ubuntu,etc.:sudoapt-getinstalllibgtk-3-dev
RedHat/Fedora,etc.:sudodnfinstallgtk3-devel
ItalsorequiresGo1.8ornewer.
Itcurrentlyalignstolibui'sAlpha4.1,withonlyasmallhandfuloffunctionsnotavailable.
Status
Packageuiiscurrentlymid-alphasoftware.Muchofwhatiscurrentlypresentrunsstabilyenoughfortheexamplesandperhapssomesmallprogramstowork,butthestabilityisstillawork-in-progress,muchofwhatisalreadythereisnotfeature-complete,someofitwillbebuggyoncertainplatforms,andthere'salotofstuffmissing.ThelibuiREADMEhasmoreinformation.
Installation
Onceyouhavethedependenciesinstalled,asimple
gogetgithub.com/andlabs/ui/...
shouldsuffice.
Documentation
Thein-codedocumentationissufficienttogetstarted,butneedsimprovement.
Somesimpleexampleprogramsareintheexamplesdirectory.Youcangobuildeachofthemindividually.
Windowsmanifests
PackageuirequiresamanifestthatspecifiesCommonControlsv6torunonWindows.ItshouldatleastalsostateassupportedWindowsVistaandWindows7,thoughtoavoidsurpriseswithotherpackages(orwithGoitself;seethisissue)youshouldstatecompatibilitywithhigherversionsofWindowstoo.
Thesimplestoptionisprovidedasasubpackagewinmanifest;youcansimplyimportitwithoutaname,andit'llsetthingsupproperly:
import_"github.com/andlabs/ui/winmanifest"
Youdonothavetoworryaboutimportingthisinnon-Windows-onlyfiles;itdoesnothingonnon-Windowsplatforms.
Ifyouwishtouseyourownmanifestinstead,youcanusetheoneinwinmanifestasatemplatetoseewhat'srequiredandhow.You'llneedtospecifythetemplateina.rcfileandusewindresinMinGW-w64togeneratea.sysofileasfollows:
windres-iresources.rc-owinmanifest_windows_GOARCH.syso-Ocoff
Youmayalsobeinterestedinthegithub.com/akavel/rsrcandgithub.com/josephspurrier/goversioninfopackages,whichprovideotherGo-likeoptionsforembeddingthemanifest.
Notethatifyouchoosetoshipamanifestasaseparate.exe.manifestfileinsteadofembeddingitinyourbinary,andyouuseCygwinorMSYS2asthesourceofyourMinGW-w64,CygwinandMSYS2instructgcctoembedadefaultmanifestofitsownifnoneisspecified.Thisdefaultwilloverrideyourmanifestfile!Seethisissueformoredetails,includingworkaroundinstructions.
macOSprogramexecution
IfyourunamacOSprogrambinarydirectlyfromthecommandline,itwillstartinthebackground.Thisisintentional;seethisformoredetails.
Expand▾
Collapse▴
Documentation
¶
Renderedfor
linux/amd64
windows/amd64
darwin/amd64
js/wasm
Index¶
Constants
funcLibuiFreeText(cuintptr)
funcMain(ffunc())error
funcMsgBox(w*Window,titlestring,descriptionstring)
funcMsgBoxError(w*Window,titlestring,descriptionstring)
funcOnShouldQuit(ffunc()bool)
funcOpenFile(w*Window)string
funcQueueMain(ffunc())
funcQuit()
funcSaveFile(w*Window)string
typeAlign
typeArea
funcNewArea(handlerAreaHandler)*Area
funcNewScrollingArea(handlerAreaHandler,widthint,heightint)*Area
func(a*Area)Destroy()
func(a*Area)QueueRedrawAll()
func(a*Area)ScrollTo(xfloat64,yfloat64,widthfloat64,heightfloat64)
func(a*Area)SetSize(widthint,heightint)
typeAreaDrawParams
typeAreaHandler
typeAreaKeyEvent
typeAreaMouseEvent
typeAt
typeAttribute
typeAttributedString
funcNewAttributedString(initialStringstring)*AttributedString
func(s*AttributedString)AppendUnattributed(strstring)
func(s*AttributedString)Delete(start,endint)
func(s*AttributedString)Free()
func(s*AttributedString)InsertAtUnattributed(strstring,atint)
func(s*AttributedString)SetAttribute(aAttribute,start,endint)
func(s*AttributedString)String()string
typeBox
funcNewHorizontalBox()*Box
funcNewVerticalBox()*Box
func(b*Box)Append(childControl,stretchybool)
func(b*Box)Delete(nint)
func(b*Box)Destroy()
func(b*Box)Padded()bool
func(b*Box)SetPadded(paddedbool)
typeButton
funcNewButton(textstring)*Button
func(b*Button)OnClicked(ffunc(*Button))
func(b*Button)SetText(textstring)
func(b*Button)Text()string
typeCheckbox
funcNewCheckbox(textstring)*Checkbox
func(c*Checkbox)Checked()bool
func(c*Checkbox)OnToggled(ffunc(*Checkbox))
func(c*Checkbox)SetChecked(checkedbool)
func(c*Checkbox)SetText(textstring)
func(c*Checkbox)Text()string
typeColorButton
funcNewColorButton()*ColorButton
func(b*ColorButton)Color()(r,g,bl,afloat64)
func(b*ColorButton)OnChanged(ffunc(*ColorButton))
func(b*ColorButton)SetColor(r,g,bl,afloat64)
typeCombobox
funcNewCombobox()*Combobox
func(c*Combobox)Append(textstring)
func(c*Combobox)OnSelected(ffunc(*Combobox))
func(c*Combobox)Selected()int
func(c*Combobox)SetSelected(indexint)
typeControl
funcControlFromLibui(cuintptr)Control
typeControlBase
funcNewControlBase(ifaceControl,cuintptr)ControlBase
func(c*ControlBase)Destroy()
func(c*ControlBase)Disable()
func(c*ControlBase)Enable()
func(c*ControlBase)Enabled()bool
func(c*ControlBase)Handle()uintptr
func(c*ControlBase)Hide()
func(c*ControlBase)LibuiControl()uintptr
func(c*ControlBase)Show()
func(c*ControlBase)Visible()bool
typeDateTimePicker
funcNewDatePicker()*DateTimePicker
funcNewDateTimePicker()*DateTimePicker
funcNewTimePicker()*DateTimePicker
func(d*DateTimePicker)OnChanged(ffunc(*DateTimePicker))
func(d*DateTimePicker)SetTime(ttime.Time)
func(d*DateTimePicker)Time()time.Time
typeDrawBrush
typeDrawBrushType
typeDrawContext
func(c*DrawContext)Clip(p*DrawPath)
func(c*DrawContext)Fill(p*DrawPath,b*DrawBrush)
func(c*DrawContext)Restore()
func(c*DrawContext)Save()
func(c*DrawContext)Stroke(p*DrawPath,b*DrawBrush,sp*DrawStrokeParams)
func(c*DrawContext)Text(tl*DrawTextLayout,x,yfloat64)
func(c*DrawContext)Transform(m*DrawMatrix)
typeDrawFillMode
typeDrawGradientStop
typeDrawLineCap
typeDrawLineJoin
typeDrawMatrix
funcDrawNewMatrix()*DrawMatrix
func(m*DrawMatrix)Invert()bool
func(m*DrawMatrix)Invertible()bool
func(m*DrawMatrix)Multiply(m2*DrawMatrix)
func(m*DrawMatrix)Rotate(xfloat64,yfloat64,amountfloat64)
func(m*DrawMatrix)Scale(xCenterfloat64,yCenterfloat64,xfloat64,yfloat64)
func(m*DrawMatrix)SetIdentity()
func(m*DrawMatrix)Skew(xfloat64,yfloat64,xamountfloat64,yamountfloat64)
func(m*DrawMatrix)TransformPoint(xfloat64,yfloat64)(xoutfloat64,youtfloat64)
func(m*DrawMatrix)TransformSize(xfloat64,yfloat64)(xoutfloat64,youtfloat64)
func(m*DrawMatrix)Translate(xfloat64,yfloat64)
typeDrawPath
funcDrawNewPath(fillModeDrawFillMode)*DrawPath
func(p*DrawPath)AddRectangle(xfloat64,yfloat64,widthfloat64,heightfloat64)
func(p*DrawPath)ArcTo(xCenterfloat64,yCenterfloat64,radiusfloat64,startAnglefloat64,...)
func(p*DrawPath)BezierTo(c1xfloat64,c1yfloat64,c2xfloat64,c2yfloat64,endXfloat64,endYfloat64)
func(p*DrawPath)CloseFigure()
func(p*DrawPath)End()
func(p*DrawPath)Free()
func(p*DrawPath)LineTo(xfloat64,yfloat64)
func(p*DrawPath)NewFigure(xfloat64,yfloat64)
func(p*DrawPath)NewFigureWithArc(xCenterfloat64,yCenterfloat64,radiusfloat64,startAnglefloat64,...)
typeDrawStrokeParams
typeDrawTextAlign
typeDrawTextLayout
funcDrawNewTextLayout(p*DrawTextLayoutParams)*DrawTextLayout
func(tl*DrawTextLayout)Free()
typeDrawTextLayoutParams
typeEditableCombobox
funcNewEditableCombobox()*EditableCombobox
func(e*EditableCombobox)Append(textstring)
func(e*EditableCombobox)OnChanged(ffunc(*EditableCombobox))
func(e*EditableCombobox)SetText(textstring)
func(e*EditableCombobox)Text()string
typeEntry
funcNewEntry()*Entry
funcNewPasswordEntry()*Entry
funcNewSearchEntry()*Entry
func(e*Entry)OnChanged(ffunc(*Entry))
func(e*Entry)ReadOnly()bool
func(e*Entry)SetReadOnly(robool)
func(e*Entry)SetText(textstring)
func(e*Entry)Text()string
typeExtKey
typeFontButton
funcNewFontButton()*FontButton
func(b*FontButton)Font()*FontDescriptor
func(b*FontButton)OnChanged(ffunc(*FontButton))
typeFontDescriptor
typeForm
funcNewForm()*Form
func(f*Form)Append(labelstring,childControl,stretchybool)
func(f*Form)Delete(nint)
func(f*Form)Destroy()
func(f*Form)Padded()bool
func(f*Form)SetPadded(paddedbool)
typeGrid
funcNewGrid()*Grid
func(g*Grid)Append(childControl,left,topint,xspan,yspanint,hexpandbool,halignAlign,...)
func(g*Grid)InsertAt(childControl,existingControl,atAt,xspan,yspanint,hexpandbool,...)
func(g*Grid)Padded()bool
func(g*Grid)SetPadded(paddedbool)
typeGroup
funcNewGroup(titlestring)*Group
func(g*Group)Destroy()
func(g*Group)Margined()bool
func(g*Group)SetChild(childControl)
func(g*Group)SetMargined(marginedbool)
func(g*Group)SetTitle(titlestring)
func(g*Group)Title()string
typeImage
funcNewImage(width,heightfloat64)*Image
func(i*Image)Append(img*image.RGBA)
func(i*Image)Free()
typeLabel
funcNewLabel(textstring)*Label
func(l*Label)SetText(textstring)
func(l*Label)Text()string
typeModifiers
typeMultilineEntry
funcNewMultilineEntry()*MultilineEntry
funcNewNonWrappingMultilineEntry()*MultilineEntry
func(m*MultilineEntry)Append(textstring)
func(m*MultilineEntry)OnChanged(ffunc(*MultilineEntry))
func(m*MultilineEntry)ReadOnly()bool
func(m*MultilineEntry)SetReadOnly(robool)
func(m*MultilineEntry)SetText(textstring)
func(m*MultilineEntry)Text()string
typeOpenTypeFeatures
typeOpenTypeTag
funcToOpenTypeTag(a,b,c,dbyte)OpenTypeTag
typeProgressBar
funcNewProgressBar()*ProgressBar
func(p*ProgressBar)SetValue(valueint)
func(p*ProgressBar)Value()int
typeRadioButtons
funcNewRadioButtons()*RadioButtons
func(r*RadioButtons)Append(textstring)
func(r*RadioButtons)OnSelected(ffunc(*RadioButtons))
func(r*RadioButtons)Selected()int
func(r*RadioButtons)SetSelected(indexint)
typeSeparator
funcNewHorizontalSeparator()*Separator
funcNewVerticalSeparator()*Separator
typeSlider
funcNewSlider(minint,maxint)*Slider
func(s*Slider)OnChanged(ffunc(*Slider))
func(s*Slider)SetValue(valueint)
func(s*Slider)Value()int
typeSpinbox
funcNewSpinbox(minint,maxint)*Spinbox
func(s*Spinbox)OnChanged(ffunc(*Spinbox))
func(s*Spinbox)SetValue(valueint)
func(s*Spinbox)Value()int
typeTab
funcNewTab()*Tab
func(t*Tab)Append(namestring,childControl)
func(t*Tab)Delete(nint)
func(t*Tab)Destroy()
func(t*Tab)InsertAt(namestring,nint,childControl)
func(t*Tab)Margined(nint)bool
func(t*Tab)NumPages()int
func(t*Tab)SetMargined(nint,marginedbool)
typeTable
funcNewTable(p*TableParams)*Table
func(t*Table)AppendButtonColumn(namestring,buttonModelColumnint,buttonClickableModelColumnint)
func(t*Table)AppendCheckboxColumn(namestring,checkboxModelColumnint,checkboxEditableModelColumnint)
func(t*Table)AppendCheckboxTextColumn(namestring,checkboxModelColumnint,checkboxEditableModelColumnint,...)
func(t*Table)AppendImageColumn(namestring,imageModelColumnint)
func(t*Table)AppendImageTextColumn(namestring,imageModelColumnint,textModelColumnint,...)
func(t*Table)AppendProgressBarColumn(namestring,progressModelColumnint)
func(t*Table)AppendTextColumn(namestring,textModelColumnint,textEditableModelColumnint,...)
typeTableColor
typeTableImage
typeTableInt
typeTableModel
funcNewTableModel(handlerTableModelHandler)*TableModel
func(m*TableModel)Free()
func(m*TableModel)RowChanged(indexint)
func(m*TableModel)RowDeleted(indexint)
func(m*TableModel)RowInserted(indexint)
typeTableModelHandler
typeTableParams
typeTableString
typeTableTextColumnOptionalParams
typeTableValue
typeTextBackground
typeTextColor
typeTextFamily
typeTextItalic
typeTextSize
typeTextStretch
typeTextWeight
typeUnderline
typeUnderlineColor
typeUnderlineColorCustom
typeWindow
funcNewWindow(titlestring,widthint,heightint,hasMenubarbool)*Window
func(w*Window)Borderless()bool
func(w*Window)Destroy()
func(w*Window)Margined()bool
func(w*Window)OnClosing(ffunc(*Window)bool)
func(w*Window)SetBorderless(borderlessbool)
func(w*Window)SetChild(childControl)
func(w*Window)SetMargined(marginedbool)
func(w*Window)SetTitle(titlestring)
func(w*Window)Title()string
Constants¶
ViewSource
const(
TableModelColumnNeverEditable=-1
TableModelColumnAlwaysEditable=-2
)
TableModelColumnNeverEditableand
TableModelColumnAlwaysEditablearethevalueofaneditable
modelcolumnparametertooneoftheTablecreatecolumn
functions;ifused,thatjparticularTablecolumisnoteditable
bytheuserandalwayseditablebytheuser,respectively.
ViewSource
constDrawDefaultMiterLimit=10.0
TODOdocument
Variables¶
Thissectionisempty.
Functions¶
funcLibuiFreeText¶
funcLibuiFreeText(cuintptr)
LibuiFreeTextallowsimplementationsofControl
tocallthelibuifunctionuiFreeText.
funcMain¶
funcMain(ffunc())error
Maininitializespackageui,runsftosetuptheprogram,
andexecutestheGUImainloop.fshouldsetuptheprogram's
initialstate:openthemainwindow,createcontrols,andsetup
events.Itshouldthenreturn,atwhichpointMainwill
processeventsuntilQuitiscalled,atwhichpointMainwillreturn
nil.Ifpackageuifailstoinitialize,Mainreturnsanappropriate
error.
funcMsgBox¶
funcMsgBox(w*Window,titlestring,descriptionstring)
funcMsgBoxError¶
funcMsgBoxError(w*Window,titlestring,descriptionstring)
TODO
funcOnShouldQuit¶
funcOnShouldQuit(ffunc()bool)
OnShouldQuitschedulesftobeexeuctedwhentheOSwants
theprogramtoquitorwhenaQuitmenuitemhasbeenclicked.
Onlyonefunctionmayberegisteredatatime.Ifthefunction
returnstrue,Quitwillbecalled.Ifthefunctionreturnsfalse,or
ifOnShouldQuitisnevercalled.Quitwillnotbecalledandthe
OSwillbetoldthattheprogramneedstocontinuerunning.
funcOpenFile¶
funcOpenFile(w*Window)string
funcQueueMain¶
funcQueueMain(ffunc())
QueueMainqueuesftobeexecutedontheGUIthreadwhen
nextpossible.Itreturnsimmediately;thatis,itdoesnotwait
forthefunctiontoactuallybeexecuted.QueueMainistheonly
functionthatcanbecalledfromothergoroutines,andits
primarypurposeistoallowcommunicationbetweenother
goroutinesandtheGUIthread.CallingQueueMainafterQuit
hasbeencalledresultsinundefinedbehavior.
Ifyoustartagoroutineinf,italsocannotcallpackageui
functions.Soforinstance,thefollowingwillresultin
undefinedbehavior:
ui.QueueMain(func(){
goui.MsgBox(...)
})
funcQuit¶
funcQuit()
QuitqueuesareturnfromMain.Itdoesnotexittheprogram.
ItalsodoesnotimmediatelycauseMaintoreturn;Mainwill
returnwhenitnextcan.QuitmustbecalledfromtheGUIthread.
funcSaveFile¶
funcSaveFile(w*Window)string
Types¶
typeAlign¶
typeAlignint
AlignrepresentsthealignmentofaControlinitscellofaGrid.
const(
AlignFillAlign=iota
AlignStart
AlignCenter
AlignEnd
)
typeArea¶
typeAreastruct{
ControlBase
//containsfilteredorunexportedfields
}
AreaisaControlthatrepresentsablankcanvasthataprogram
candrawonasitwishes.Areasalsoreceivekeyboardandmouse
events,andprogramscanreacttothoseastheyseefit.Drawing
andeventhandlingarehandledthroughaninstanceofatype
thatimplementsAreaHandlerthateveryAreahas;seeAreaHandler
fordetails.
Therearetwotypesofareas.Non-scrollingareasarerectangular
andhavenoscrollbars.Programscandrawonandgetmouse
eventsfromanypointintheArea,andthesizeoftheAreais
decidedbypackageuiitself,accordingtothelayoutofcontrols
intheWindowtheAreaislocatedinandthesizeofsaidWindow.
ThereisnowaytoquerytheArea'ssizeorbenotifiedwhenits
sizechanges;instead,youaregiventheareasizeaspartofthe
drawandmouseeventhandlers,forusesolelywithinthose
handlers.
Scrollingareashavehorziontalandverticalscrollbars.Theamount
thatcanbescrolledisdeterminedbythearea'ssize,whichis
decidedbytheprogrammer(bothwhencreatingtheAreaandby
acalltoSetSize).OnlyaportionoftheAreaisvisibleatanytime;
drawingandmouseeventsareautomaticallyadjustedtomatch
whatportionisvisible,soyoudonothavetoworryaboutscrolling
inyoureventhandlers.AreaHandlerhasmoreinformation.
TheinternalcoordinatesystemofanAreaispoints,whichare
floating-pointanddevice-independent.Formoredetails,see
AreaHandler.ThesizeofascrollingAreamustbeanexactinteger
numberofpoints(thatis,youcannothaveanAreathatis32.5
pointstall)andthustheparameterstoNewScrollingAreaand
SetSizeareints.Allotherinstancesofpointsinparametersand
structures(includingsizesofdrawnobjects)arefloat64s.
funcNewArea¶
funcNewArea(handlerAreaHandler)*Area
NewAreacreatesanewnon-scrollingArea.
funcNewScrollingArea¶
funcNewScrollingArea(handlerAreaHandler,widthint,heightint)*Area
NewScrollingAreacreatesanewscrollingAreaofthegivensize,
inpoints.
func(*Area)Destroy¶
func(a*Area)Destroy()
DestroydestroystheArea.
func(*Area)QueueRedrawAll¶
func(a*Area)QueueRedrawAll()
QueueRedrawAllqueuestheentireAreaforredraw.
TheAreaisnotredrawnbeforethisfunctionreturns;itis
redrawnwhennextpossible.
func(*Area)ScrollTo¶
func(a*Area)ScrollTo(xfloat64,yfloat64,widthfloat64,heightfloat64)
ScrollToscrollstheAreatoshowthegivenrectangle;whatthis
meansisimplementation-defined,butyoucansafelyassume
thatasmuchofthegivenrectangleaspossiblewillbevisible
afterthiscall.(TODOverifythisonOSX)ScrollTopanicsifcalled
onanon-scrollingArea.
func(*Area)SetSize¶
func(a*Area)SetSize(widthint,heightint)
SetSizesetsthesizeofascrollingAreatothegivensize,inpoints.
SetSizepanicsifcalledonanon-scrollingArea.
typeAreaDrawParams¶
typeAreaDrawParamsstruct{
//Contextisthedrawingcontexttodrawon.SeeDrawContext
//forhowtodraw.
Context*DrawContext
//AreaWidthandAreaHeightprovidethesizeoftheAreafor
//non-scrollingAreas.ForscrollingAreasbothvaluesarezero.
//
//ToreiteratetheAreaHandlerdocumentation,doNOTsave
//thesevaluesforlater;theycanchangewithoutgenerating
//anevent.
AreaWidthfloat64
AreaHeightfloat64
//Thesefourfieldsdefinetherectanglethatneedstobe
//redrawn.Thesystemwillnotdrawanythingoutsidethis
//rectangle,butyoucanmakeyourdrawingfasterifyou
//alsostaywithinthelines.
ClipXfloat64
ClipYfloat64
ClipWidthfloat64
ClipHeightfloat64
}
AreaDrawParamsprovidesadrawingcontextthatcanbeused
todrawonanAreaandtellsyouwheretodraw.SeeAreaHandler
forintroductoryinformation.
typeAreaHandler¶
typeAreaHandlerinterface{
//DrawissentwhenapartoftheAreaneedstobedrawn.
//dpwillcontainadrawingcontexttodrawon,therectangle
//thatneedstobedrawnin,and(foranon-scrollingarea)the
//sizeofthearea.Therectanglethatneedstobedrawnwill
//havebeenclearedbythesystempriortodrawing,soyouare
//alwaysworkingonacleanslate.
//
//IfyoucallSaveonthedrawingcontext,youmustcallRelease
//beforereturningfromDraw,andthenumberofcallstoSave
//andReleasemustmatch.Failuretodosoresultsinundefined
//behavior.
Draw(a*Area,dp*AreaDrawParams)
//MouseEventiscalledwhenthemousemovesovertheArea
//orwhenamousebuttonispressedorreleased.See
//AreaMouseEventformoredetails.
//
//Ifamousebuttonisbeingheld,MouseEventswillcontinueto
//begenerated,evenifthemouseisnotwithinthearea.On
//somesystems,thesystemcaninterruptthisbehavior;
//seeDragBroken.
MouseEvent(a*Area,me*AreaMouseEvent)
//MouseCrossediscalledwhenthemouseeitherentersor
//leavestheArea.Itiscalledevenifthemousebuttonsarebeing
//held(seeMouseEventabove).Ifthemousehasenteredthe
//Area,leftisfalse;ifithaslefttheArea,leftistrue.
//
//If,whentheAreaisfirstshown,themouseisalreadyinside
//theArea,MouseCrossedwillbecalledwithleft=false.
//TODOwhataboutfutureshows?
MouseCrossed(a*Area,leftbool)
//DragBrokeniscalledifamousedragisinterruptedbythe
//system.Asnotedabove,whenamousebuttonisheld,
//MouseEventwillcontinuetobecalled,evenifthemouseis
//outsidetheArea.Onsomesystems,thisbehaviorcanbe
//stoppedbythesystemitselfforavarietyofreasons.This
//methodisprovidedtoallowyourprogramtocopewiththe
//lossofthemouseinthiscase.Youshouldcopebycancelling
//whateverdrag-relatedoperationyouweredoing.
//
//Notethatthisisonlygeneratedonsomesystemsunder
//specificconditions.Donotimplementbehaviorthatonly
//takeseffectwhenDragBrokeniscalled.
DragBroken(a*Area)
//KeyEventiscalledwhenakeyispressedwhiletheAreahas
//keyboardfocus(iftheAreahasbeentabbedintoorifthe
//mousehasbeenclickedonit).SeeAreaKeyEventforspecifics.
//
//Becausesomekeyboardeventsarehandledbythesystem
//(forinstance,menuacceleratorsandglobalhotkeys),you
//mustreturnwhetheryouhandledthekeyevent;returntrue
//ifyoudidorfalseifyoudidnot.Ifyouwishtoignorethe
//keyboardoutright,thecorrectimplementationofKeyEventis
// func(h*MyHandler)KeyEvent(a*ui.Area,ke*ui.AreaKeyEvent)(handledbool){
// returnfalse
// }
//DONOTRETURNTRUEUNCONDITIONALLYFROMTHIS
//METHOD.BADTHINGSWILLHAPPENIFYOUDO.
KeyEvent(a*Area,ke*AreaKeyEvent)(handledbool)
}
AreaHandlerdefinesthefunctionalityneededforhandlingevents
fromanArea.EachofthemethodsonAreaHandleriscalledfrom
theGUIthread,andeveryparameter(otherthantheAreaitself)
shouldbeassumedtoonlybevalidduringthelifeofthemethod
call(soforinstance,donotsaveAreaDrawParams.AreaWidth,as
thatmightchangewithoutgeneratinganevent).
CoordinatestoDrawandMouseEventaregiveninpoints.Points
aregeneric,floating-point,device-independentcoordinateswith
(0,0)atthetopleftcorner.Youneverhavetoworryaboutthe
mappingbetweenpointsandpixels;simplydraweverythingusing
pointsandyougetniceeffectslikelookingsharponhigh-DPI
monitorsforfree.Properdocumentationonthematterisbeing
written.Inthemeantime,thereareseveralreferenestothiskindof
drawing,mostnotablyonApple'swebsite:https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html#//apple_ref/doc/uid/TP40012302-CH4-SW1
ForascrollingArea,pointsareautomaticallyoffsetbythescroll
position.Soifthemousemovestoposition(5,5)whilethe
horizontalscrollbarisatposition10andthehorizontalscrollbaris
atposition20,thecoordinatestoredintheAreaMouseEvent
structureis(15,25).Thesameappliestodrawing.
typeAreaKeyEvent¶
typeAreaKeyEventstruct{
Keyrune
ExtKeyExtKey
ModifierModifiers
ModifiersModifiers
Upbool
}
TODOdocumentallthese
typeAreaMouseEvent¶
typeAreaMouseEventstruct{
Xfloat64
Yfloat64
//AreaWidthandAreaHeightprovidethesizeoftheAreafor
//non-scrollingAreas.ForscrollingAreasbothvaluesarezero.
//
//ToreiteratetheAreaHandlerdocumentation,doNOTsave
//thesevaluesforlater;theycanchangewithoutgenerating
//anevent.
AreaWidthfloat64
AreaHeightfloat64
Downuint
Upuint
Countuint
ModifiersModifiers
Held[]uint
}
TODOdocumentallthese
TODOnotethatinthecaseofadrag,XandYcanbeoutofbounds,orintheeventofascrollingarea,inplacesthatarenotvisible
typeAt¶
typeAtint
AtrepresentsasideofaControltoaddotherControlstoaGridto.
const(
LeadingAt=iota
Top
Trailing
Bottom
)
typeAttribute¶
typeAttributeinterface{
//containsfilteredorunexportedmethods
}
Attributestoresinformationaboutanattributeinan
AttributedString.
ThefollowingtypescanbeusedasAttributes:
-TextFamily
-TextSize
-TextWeight
-TextItalic
-TextStretch
-TextColor
-TextBackground
-Underline
-UnderlineColor
-UnderlineColorCustom
-OpenTypeFeatures
ForeveryUnicodecodepointintheAttributedString,atmostone
valueofeachattributetypecanbeapplied.
typeAttributedString¶
typeAttributedStringstruct{
//containsfilteredorunexportedfields
}
AttributedStringrepresentsastringofUTF-8textthatcan
optionallybeembellishedwithformattingattributes.Packageui
providesthelistofformattingattributes,whichcovercommon
formattingtraitslikeboldfaceandcoloraswellasadvanced
typographicalfeaturesprovidedbyOpenTypelikesuperscripts
andsmallcaps.Theseattributescanbecombinedinavarietyof
ways.
AttributesareappliedtorunsofUnicodecodepointsinthestring.
Zero-lengthrunsareelided.Consecutiverunsthathavethesame
attributetypeandvaluearemerged.Eachattributeisindependent
ofeachotherattribute;overlappingattributesofdifferenttypes
donotspliteachotherapart,butdifferentvaluesofthesame
attributetypedo.
TheemptystringcanalsoberepresentedbyAttributedString,
butbecauseoftheno-zero-length-attributerule,itwillnothave
attributes.
UnlikeGostrings,AttributedStringsaremutable.
AttributedStringallocatesresourceswithinlibui,whichpackage
uisitsontopof.Assuch,whenyouarefinishedwithan
AttributedString,youmustfreeitwithFree.Likeotherthingsin
packageui,AttributedStringmustonlybeusedfromthemain
goroutine.
Inaddition,AttributedStringprovidesfacilitiesformoving
betweengraphemeclusters,whichrepresentacharacter
fromthepointofviewoftheenduser.Thecursorofatexteditor
isalwaysplacedonagraphemeboundary,soyoucanusethese
featurestomovethecursorleftorrightbyone"character".
TODOdoesuiAttributedStringitselfneedthis
AttributedStringdoesnotprovideenoughinformationtobeable
todrawitselfontoaDrawContextorrespondtouseractions.
Inordertodothat,you'llneedtouseaDrawTextLayout,which
isbuiltfromthecombinationofanAttributedStringandasetof
layout-specificproperties.
funcNewAttributedString¶
funcNewAttributedString(initialStringstring)*AttributedString
NewAttributedStringcreatesanewAttributedStringfrom
initialString.Thestringwillbeentirelyunattributed.
func(*AttributedString)AppendUnattributed¶
func(s*AttributedString)AppendUnattributed(strstring)
AppendUnattributedaddsstrtotheendofs.Thenewsubstring
willbeunattributed.
func(*AttributedString)Delete¶
func(s*AttributedString)Delete(start,endint)
Deletedeletesthecharactersandattributesofsinthebyterange
[start,end).
func(*AttributedString)Free¶
func(s*AttributedString)Free()
Freedestroyss.
func(*AttributedString)InsertAtUnattributed¶
func(s*AttributedString)InsertAtUnattributed(strstring,atint)
InsertAtUnattributedaddsstrtosatthebytepositionspecifiedby
at.Thenewsubstringwillbeunattributed;existingattributeswill
bemovedalongwiththeirtext.
func(*AttributedString)SetAttribute¶
func(s*AttributedString)SetAttribute(aAttribute,start,endint)
SetAttributesetsainthebyterange[start,end)ofs.Anyexisting
attributesinthatbyterangeofthesametypeareremoved.
func(*AttributedString)String¶
func(s*AttributedString)String()string
Stringreturnsthetextualcontentofs.
typeBox¶
typeBoxstruct{
ControlBase
//containsfilteredorunexportedfields
}
BoxisaControlthatholdsagroupofControlshorizontally
orvertically.Ifhorizontally,thenallcontrolshavethesame
height.Ifvertically,thenallcontrolshavethesamewidth.
Bydefault,eachcontrolhasitspreferredwidth(horizontal)
orheight(vertical);ifacontrolismarked"stretchy",itwill
takewhateverspaceisleftover.Ifmultiplecontrolsaremarked
stretchy,theywillbegivenequalsharesoftheleftoverspace.
Therecanalsobespacebetweeneachcontrol("padding").
funcNewHorizontalBox¶
funcNewHorizontalBox()*Box
NewHorizontalBoxcreatesanewhorizontalBox.
funcNewVerticalBox¶
funcNewVerticalBox()*Box
NewVerticalBoxcreatesanewverticalBox.
func(*Box)Append¶
func(b*Box)Append(childControl,stretchybool)
AppendaddsthegivencontroltotheendoftheBox.
func(*Box)Delete¶
func(b*Box)Delete(nint)
DeletedeletesthenthcontroloftheBox.
func(*Box)Destroy¶
func(b*Box)Destroy()
DestroydestroystheBox.IftheBoxhaschildren,
DestroycallsDestroyonthoseControlsaswell.
func(*Box)Padded¶
func(b*Box)Padded()bool
Paddedreturnswhetherthereisspacebetweeneachcontrol
oftheBox.
func(*Box)SetPadded¶
func(b*Box)SetPadded(paddedbool)
SetPaddedcontrolswhetherthereisspacebetweeneachcontrol
oftheBox.ThesizeofthepaddingisdeterminedbytheOSand
itsbestpractices.
typeButton¶
typeButtonstruct{
ControlBase
//containsfilteredorunexportedfields
}
ButtonisaControlthatrepresentsabuttonthattheusercan
clicktoperformanaction.AButtonhasatextlabelthatshould
describewhatthebuttondoes.
funcNewButton¶
funcNewButton(textstring)*Button
NewButtoncreatesanewButtonwiththegiventextasitslabel.
func(*Button)OnClicked¶
func(b*Button)OnClicked(ffunc(*Button))
OnClickedregistersftoberunwhentheuserclickstheButton.
Onlyonefunctioncanberegisteredatatime.
func(*Button)SetText¶
func(b*Button)SetText(textstring)
SetTextsetstheButton'stexttotext.
func(*Button)Text¶
func(b*Button)Text()string
TextreturnstheButton'stext.
typeCheckbox¶
typeCheckboxstruct{
ControlBase
//containsfilteredorunexportedfields
}
CheckboxisaControlthatrepresentsaboxwithatextlabelatits
side.Whentheuserclicksthecheckbox,acheckmarkwillappear
inthebox;clickingitagainremovesthecheck.
funcNewCheckbox¶
funcNewCheckbox(textstring)*Checkbox
NewCheckboxcreatesanewCheckboxwiththegiventextasits
label.
func(*Checkbox)Checked¶
func(c*Checkbox)Checked()bool
CheckedreturnswhethertheCheckboxischecked.
func(*Checkbox)OnToggled¶
func(c*Checkbox)OnToggled(ffunc(*Checkbox))
OnToggledregistersftoberunwhentheuserclickstheCheckbox.
Onlyonefunctioncanberegisteredatatime.
func(*Checkbox)SetChecked¶
func(c*Checkbox)SetChecked(checkedbool)
SetCheckedsetswhethertheCheckboxischecked.
func(*Checkbox)SetText¶
func(c*Checkbox)SetText(textstring)
SetTextsetstheCheckbox'stexttotext.
func(*Checkbox)Text¶
func(c*Checkbox)Text()string
TextreturnstheCheckbox'stext.
typeColorButton¶
typeColorButtonstruct{
ControlBase
//containsfilteredorunexportedfields
}
ColorButtonisaControlthatrepresentsabuttonthattheusercan
clicktoselectacolor.
funcNewColorButton¶
funcNewColorButton()*ColorButton
NewColorButtoncreatesanewColorButton.
func(*ColorButton)Color¶
func(b*ColorButton)Color()(r,g,bl,afloat64)
ColorreturnsthecolorcurrentlyselectedintheColorButton.
Colorsarenotalpha-premultiplied.
TODOrenameborbl
func(*ColorButton)OnChanged¶
func(b*ColorButton)OnChanged(ffunc(*ColorButton))
OnChangedregistersftoberunwhentheuserchangesthe
currentlyselectedcolorintheColorButton.Onlyonefunction
canberegisteredatatime.
func(*ColorButton)SetColor¶
func(b*ColorButton)SetColor(r,g,bl,afloat64)
SetColorsetsthecurrentlyselectedcolorintheColorButton.
Colorsarenotalpha-premultiplied.
TODOrenameborbl
typeCombobox¶
typeComboboxstruct{
ControlBase
//containsfilteredorunexportedfields
}
ComboboxisaControlthatrepresentsadrop-downlistofstrings
thattheusercanchooseoneofatanytime.ForaComboboxthat
userscantypevaluesinto,seeEditableCombobox.
funcNewCombobox¶
funcNewCombobox()*Combobox
NewComboboxcreatesanewCombobox.
func(*Combobox)Append¶
func(c*Combobox)Append(textstring)
AppendaddsthenameditemtotheendoftheCombobox.
func(*Combobox)OnSelected¶
func(c*Combobox)OnSelected(ffunc(*Combobox))
OnSelectedregistersftoberunwhentheuserselectsanitemin
theCombobox.Onlyonefunctioncanberegisteredatatime.
func(*Combobox)Selected¶
func(c*Combobox)Selected()int
Selectedreturnstheindexofthecurrentlyselectediteminthe
Combobox,or-1ifnothingisselected.
func(*Combobox)SetSelected¶
func(c*Combobox)SetSelected(indexint)
SetSelectedsetsthecurrentlyselecteditemintheCombobox
toindex.Ifindexis-1noitemwillbeselected.
typeControl¶
typeControlinterface{
//LibuiControlreturnstheuiControlpointerfortheControl.
//Thisisintendedforusewhenaddingacontroltoa
//container.
LibuiControl()uintptr
//DestroydestroystheControl.
Destroy()
//HandlereturnstheOS-levelhandlethatbacksthe
//Control.OnOSsthatusereferencecountingfor
//controls,Handledoesnotincrementthereference
//count;youaresharingpackageui'sreference.
Handle()uintptr
//VisiblereturnswhethertheControlisvisible.
Visible()bool
//ShowshowstheControl.
Show()
//HideshowstheControl.Hiddencontrolsdonotparticipate
//inlayout(thatis,Box,Grid,etc.doesnotreservespacefor
//hiddencontrols).
Hide()
//EnabledreturnswhethertheControlisenabled.
Enabled()bool
//EnableenablestheControl.
Enable()
//DisabledisablestheControl.
Disable()
}
ControlrepresentsaGUIcontrol.Itprovdesmethods
commontoallControls.
ThepreferredwaytocreatenewControlsistouse
ControlBase;seeControlBasebelow.
funcControlFromLibui¶
funcControlFromLibui(cuintptr)Control
ControlFromLibuireturnstheControlassociatedwithalibui
uiControl.Thisisintendedforimplementingeventhandlers
ontheGoside,topreventsharingGopointerswithC.
ThisfunctiononlyworksonControlsthatuseControlBase.
typeControlBase¶
typeControlBasestruct{
//containsfilteredorunexportedfields
}
ControlBaseisanimplementationofControlthatprovides
allthemethodsthatControlrequires.Touseit,embeda
ControlBase(nota*ControlBase)intoyourstructure,then
assigntheresultofNewControlBasetothatfield:
typeMyControlstruct{
ui.ControlBase
c*C.MyControl
}
funcNewMyControl()*MyControl{
m:=&NewMyControl{
c:C.newMyControl(),
}
m.ControlBase=ui.NewControlBase(m,uintptr(unsafe.Pointer(c)))
returnm
}
funcNewControlBase¶
funcNewControlBase(ifaceControl,cuintptr)ControlBase
NewControlBasecreatesanewControlBase.Seethe
documentationofControlBaseforanexample.
NewControlshouldonlybecalledonceperinstanceofControl.
func(*ControlBase)Destroy¶
func(c*ControlBase)Destroy()
func(*ControlBase)Disable¶
func(c*ControlBase)Disable()
func(*ControlBase)Enable¶
func(c*ControlBase)Enable()
func(*ControlBase)Enabled¶
func(c*ControlBase)Enabled()bool
func(*ControlBase)Handle¶
func(c*ControlBase)Handle()uintptr
func(*ControlBase)Hide¶
func(c*ControlBase)Hide()
func(*ControlBase)LibuiControl¶
func(c*ControlBase)LibuiControl()uintptr
func(*ControlBase)Show¶
func(c*ControlBase)Show()
func(*ControlBase)Visible¶
func(c*ControlBase)Visible()bool
typeDateTimePicker¶
typeDateTimePickerstruct{
ControlBase
//containsfilteredorunexportedfields
}
DateTimePickerisaControlthatrepresentsafieldwheretheuser
canenteradateand/oratime.
funcNewDatePicker¶
funcNewDatePicker()*DateTimePicker
NewDatePickercreatesanewDateTimePickerthatshows
onlyadate.
funcNewDateTimePicker¶
funcNewDateTimePicker()*DateTimePicker
NewDateTimePickercreatesanewDateTimePickerthatshows
bothadateandatime.
funcNewTimePicker¶
funcNewTimePicker()*DateTimePicker
NewTimePickercreatesanewDateTimePickerthatshows
onlyatime.
func(*DateTimePicker)OnChanged¶
func(d*DateTimePicker)OnChanged(ffunc(*DateTimePicker))
OnChangedregistersftoberunwhentheuserchangesthetime
intheDateTimePicker.Onlyonefunctioncanberegisteredata
time.
func(*DateTimePicker)SetTime¶
func(d*DateTimePicker)SetTime(ttime.Time)
SetTimesetsthetimeintheDateTimePickertot.
t'scomponentsarereadas-isviat.Date()andt.Clock();
notimezonemanipulationsaredone.
func(*DateTimePicker)Time¶
func(d*DateTimePicker)Time()time.Time
TimereturnsthetimestoredintheuiDateTimePicker.
Thetimeisassumedtobelocaltime.
typeDrawBrush¶
typeDrawBrushstruct{
TypeDrawBrushType
//IfTypeisSolid.
//TODO
Rfloat64
Gfloat64
Bfloat64
Afloat64
//IfTypeisLinearGradientorRadialGradient.
//TODO
X0float64//startpointforboth
Y0float64
X1float64//linear:endpoint;radial:circlecenter
Y1float64
OuterRadiusfloat64//forradialgradientsonly
Stops[]DrawGradientStop
}
TODO
typeDrawBrushType¶
typeDrawBrushTypeint
DrawBrushTypedefinesthevarioustypesofbrushes.
TODOdisclaimer
const(
DrawBrushTypeSolidDrawBrushType=iota
DrawBrushTypeLinearGradient
DrawBrushTypeRadialGradient
DrawBrushTypeImage//presentlyunimplemented
)
typeDrawContext¶
typeDrawContextstruct{
//containsfilteredorunexportedfields
}
DrawContextrepresentsadrawingsurfacethatyoucandrawto.
AtpresenttheonlyDrawContextsaresurfacesassociatedwith
Areasandareprovidedbypackageui;seeAreaDrawParams.
func(*DrawContext)Clip¶
func(c*DrawContext)Clip(p*DrawPath)
TODO
func(*DrawContext)Fill¶
func(c*DrawContext)Fill(p*DrawPath,b*DrawBrush)
TODO
func(*DrawContext)Restore¶
func(c*DrawContext)Restore()
TODO
func(*DrawContext)Save¶
func(c*DrawContext)Save()
TODO
func(*DrawContext)Stroke¶
func(c*DrawContext)Stroke(p*DrawPath,b*DrawBrush,sp*DrawStrokeParams)
TODO
func(*DrawContext)Text¶
func(c*DrawContext)Text(tl*DrawTextLayout,x,yfloat64)
Textdrawstlincwiththetop-leftpointoftlat(x,y).
func(*DrawContext)Transform¶
func(c*DrawContext)Transform(m*DrawMatrix)
TODO
typeDrawFillMode¶
typeDrawFillModeuint
TODO
TODOdisclaimer
const(
DrawFillModeWindingDrawFillMode=iota
DrawFillModeAlternate
)
typeDrawGradientStop¶
typeDrawGradientStopstruct{
Posfloat64//between0and1inclusive
Rfloat64
Gfloat64
Bfloat64
Afloat64
}
TODO
typeDrawLineCap¶
typeDrawLineCapint
TODO
TODOdisclaimer
TODOrenamethesetoputLineCapatthebeginning?orjustCap?
const(
DrawLineCapFlatDrawLineCap=iota
DrawLineCapRound
DrawLineCapSquare
)
typeDrawLineJoin¶
typeDrawLineJoinint
TODO
TODOdisclaimer
const(
DrawLineJoinMiterDrawLineJoin=iota
DrawLineJoinRound
DrawLineJoinBevel
)
typeDrawMatrix¶
typeDrawMatrixstruct{
M11float64
M12float64
M21float64
M22float64
M31float64
M32float64
}
TODO
TODOshouldthemethodsofthesereturnselfforchaining?
funcDrawNewMatrix¶
funcDrawNewMatrix()*DrawMatrix
TODOidentitymatrix
func(*DrawMatrix)Invert¶
func(m*DrawMatrix)Invert()bool
TODO
Ifmisnotinvertible,falseisreturnedandmisleftunchanged.
func(*DrawMatrix)Invertible¶
func(m*DrawMatrix)Invertible()bool
TODO
func(*DrawMatrix)Multiply¶
func(m*DrawMatrix)Multiply(m2*DrawMatrix)
TODO
func(*DrawMatrix)Rotate¶
func(m*DrawMatrix)Rotate(xfloat64,yfloat64,amountfloat64)
TODO
func(*DrawMatrix)Scale¶
func(m*DrawMatrix)Scale(xCenterfloat64,yCenterfloat64,xfloat64,yfloat64)
TODO
func(*DrawMatrix)SetIdentity¶
func(m*DrawMatrix)SetIdentity()
TODO
func(*DrawMatrix)Skew¶
func(m*DrawMatrix)Skew(xfloat64,yfloat64,xamountfloat64,yamountfloat64)
TODO
func(*DrawMatrix)TransformPoint¶
func(m*DrawMatrix)TransformPoint(xfloat64,yfloat64)(xoutfloat64,youtfloat64)
TODOunimplemented
func(*DrawMatrix)TransformSize¶
func(m*DrawMatrix)TransformSize(xfloat64,yfloat64)(xoutfloat64,youtfloat64)
TODOunimplemented
func(*DrawMatrix)Translate¶
func(m*DrawMatrix)Translate(xfloat64,yfloat64)
TODO
typeDrawPath¶
typeDrawPathstruct{
//containsfilteredorunexportedfields
}
DrawPathrepresentsageometricpathinadrawingcontext.
Thisisthebasicunitofdrawing:alldrawingoperationsconsistof
formingapath,thenstroking,filling,orclippingtothatpath.
ApathisanOSresource;youmustexplicitlyfreeitwhenfinished.
Pathsconsistofmultiplefigures.Onceyouhaveaddedallthe
figurestoapath,youmust"end"thepathtomakeitreadytodraw
with.
TODOrewriteallthat
Ormorevisually,thelifecycleofaPathis
p:=DrawNewPath()
foreveryfigure{
p.NewFigure(...)//orNewFigureWithArc
p.LineTo(...)//anynumberoftheseinanyorder
p.ArcTo(...)
p.BezierTo(...)
iffigureshouldbeclosed{
p.CloseFigure()
}
}
p.End()
//...
dp.Context.Stroke(p,...)//anynumberoftheseinanyorder
dp.Context.Fill(p,...)
dp.Context.Clip(p)
//...
p.Free()//whendonewiththepath
ADrawPathalsodefinesitsfillmode.(Thisshouldideallybeafill
parameter,butsomeimplementationspreventit.)
TODOtalkaboutfillmodes
funcDrawNewPath¶
funcDrawNewPath(fillModeDrawFillMode)*DrawPath
DrawNewPathcreatesanewDrawPathwiththegivenfillmode.
func(*DrawPath)AddRectangle¶
func(p*DrawPath)AddRectangle(xfloat64,yfloat64,widthfloat64,heightfloat64)
AddRectanglecreatesanewfigureintheDrawPaththatconsists
entirelyofarectanglewhosetop-leftcornerisatthegivenpoint
andwhosesizeisthegivensize.Therectangleisaclosedfigure;
youmusteitherstartanewfigureorendthePathaftercalling
thismethod.
func(*DrawPath)ArcTo¶
func(p*DrawPath)ArcTo(xCenterfloat64,yCenterfloat64,radiusfloat64,startAnglefloat64,sweepfloat64,isNegativebool)
ArcToaddsacirculararctothecurrentfigureoftheDrawPath.
Youpassitthecenterofthearc,itsradiusinradians,thestarting
angle(couterclockwise)inradians,andthenumberofradiansthe
arcshouldsweep(counterclockwise).Alinesegmentisdrawnfrom
thecurrentpointtothestartofthearc.Thecurrentpointissetto
theendofthearc.
func(*DrawPath)BezierTo¶
func(p*DrawPath)BezierTo(c1xfloat64,c1yfloat64,c2xfloat64,c2yfloat64,endXfloat64,endYfloat64)
BezierToaddsacubicBeziercurvetothecurrentfigureofthe
DrawPath.Itsstartpointisthecurrentpoint.c1xandc1yarethe
firstcontrolpoint.c2xandc2yarethesecondcontrolpoint.endX
andendYaretheendpoint.Thecurrentpointissettotheend
point.
func(*DrawPath)CloseFigure¶
func(p*DrawPath)CloseFigure()
CloseFiguredrawsalinesegmentfromthecurrentpointofthe
currentfigureoftheDrawPathbacktoitsinitialpoint.Aftercalling
this,thecurrentfigureisoverandyoumusteitherstartanew
figureorendtheDrawPath.Ifthisisnotcalledandyoustarta
newfigureorendtheDrawPath,thenthecurrentfigurewillnot
havethisclosinglinesegmentaddedtoit(butthefigurewillstill
beover).
func(*DrawPath)End¶
func(p*DrawPath)End()
EndendsthecurrentDrawPath.Youcannotaddfigurestoa
DrawPaththathasbeenended.Youcannotdrawwitha
DrawPaththathasnotbeenended.
func(*DrawPath)Free¶
func(p*DrawPath)Free()
FreedestroysaDrawPath.AftercallingFreetheDrawPathcannot
beused.
func(*DrawPath)LineTo¶
func(p*DrawPath)LineTo(xfloat64,yfloat64)
LineToaddsalinetothecurrentfigureoftheDrawPathstarting
fromthecurrentpointandendingatthegivenpoint.Thecurrent
pointissettotheendingpoint.
func(*DrawPath)NewFigure¶
func(p*DrawPath)NewFigure(xfloat64,yfloat64)
NewFigurestartsanewfigureintheDrawPath.Thecurrentpoint
issettothegivenpoint.
func(*DrawPath)NewFigureWithArc¶
func(p*DrawPath)NewFigureWithArc(xCenterfloat64,yCenterfloat64,radiusfloat64,startAnglefloat64,sweepfloat64,isNegativebool)
NewFigureWithArcstartsanewfigureintheDrawPathandadds
anarcasthefirstelementofthefigure.UnlikeArcTo,
NewFigureWithArcdoesnotdrawaninitiallinesegment.
Otherwise,seeArcTo.
typeDrawStrokeParams¶
typeDrawStrokeParamsstruct{
CapDrawLineCap
JoinDrawLineJoin
Thicknessfloat64
MiterLimitfloat64
Dashes[]float64
DashPhasefloat64
}
TODO
typeDrawTextAlign¶
typeDrawTextAlignint
DrawTextAlignspecifiesthealignmentoflinesoftextina
DrawTextLayout.
TODOshouldthisreallyhaveDrawinthename?
const(
DrawTextAlignLeftDrawTextAlign=iota
DrawTextAlignCenter
DrawTextAlignRight
)
typeDrawTextLayout¶
typeDrawTextLayoutstruct{
//containsfilteredorunexportedfields
}
DrawTextLayoutisaconcreterepresentationofan
AttributedStringthatcanbedisplayedinaDrawContext.
Itincludesinformationimportantforthedrawingofablockof
text,includingtheboundingboxtowrapthetextwithin,the
alignmentoflinesoftextwithinthatbox,areastomarkas
beingselected,andotherthings.
UnlikeAttributedString,thecontentofaDrawTextLayoutis
immutableonceithasbeencreated.
TODOtalkaboutOS-specificdifferenceswithtextdrawingthatlibuican'taccountfor...
funcDrawNewTextLayout¶
funcDrawNewTextLayout(p*DrawTextLayoutParams)*DrawTextLayout
DrawNewTextLayout()createsanewDrawTextLayoutfrom
thegivenparameters.
func(*DrawTextLayout)Free¶
func(tl*DrawTextLayout)Free()
Freefreestl.TheunderlyingAttributedStringisnotfreed.
typeDrawTextLayoutParams¶
typeDrawTextLayoutParamsstruct{
String*AttributedString
DefaultFont*FontDescriptor
Widthfloat64
AlignDrawTextAlign
}
DrawTextLayoutParamsdescribesaDrawTextLayout.
DefaultFontisusedtorenderanytextthatisnotattributed
sufficientlyinString.Widthdeterminesthewidthofthebounding
boxofthetext;theheightisdeterminedautomatically.
typeEditableCombobox¶
typeEditableComboboxstruct{
ControlBase
//containsfilteredorunexportedfields
}
EditableComboboxisaControlthatrepresentsadrop-downlist
ofstringsthattheusercanchooseoneofatanytime.Italsohas
anentryfieldthattheusercantypeanalternatechoiceinto.
funcNewEditableCombobox¶
funcNewEditableCombobox()*EditableCombobox
NewEditableComboboxcreatesanewEditableCombobox.
func(*EditableCombobox)Append¶
func(e*EditableCombobox)Append(textstring)
AppendaddsthenameditemtotheendoftheEditableCombobox.
func(*EditableCombobox)OnChanged¶
func(e*EditableCombobox)OnChanged(ffunc(*EditableCombobox))
OnChangedregistersftoberunwhentheusereitherselectsan
itemorchangesthetextintheEditableCombobox.Onlyone
functioncanberegisteredatatime.
func(*EditableCombobox)SetText¶
func(e*EditableCombobox)SetText(textstring)
SetTextsetsthetextintheentryoftheEditableCombobox.
func(*EditableCombobox)Text¶
func(e*EditableCombobox)Text()string
TextreturnsthetextintheentryoftheEditableCombobox,which
couldbeoneofthechoicesinthelistiftheuserhasselectedone.
typeEntry¶
typeEntrystruct{
ControlBase
//containsfilteredorunexportedfields
}
EntryisaControlthatrepresentsaspacethattheusercan
typeasinglelineoftextinto.
funcNewEntry¶
funcNewEntry()*Entry
NewEntrycreatesanewEntry.
funcNewPasswordEntry¶
funcNewPasswordEntry()*Entry
NewPasswordEntrycreatesanewEntrywhosecontentsare
visiblyobfuscated,suitableforpasswords.
funcNewSearchEntry¶
funcNewSearchEntry()*Entry
NewSearchEntrycreatesanewEntrysuitableforsearchingwith.
Changedeventsmay,dependingonthesystem,bedelayed
withasearchEntry,toproduceasmootheruserexperience.
func(*Entry)OnChanged¶
func(e*Entry)OnChanged(ffunc(*Entry))
OnChangedregistersftoberunwhentheusermakesachangeto
theEntry.Onlyonefunctioncanberegisteredatatime.
func(*Entry)ReadOnly¶
func(e*Entry)ReadOnly()bool
ReadOnlyreturnswhethertheEntrycanbechanged.
func(*Entry)SetReadOnly¶
func(e*Entry)SetReadOnly(robool)
SetReadOnlysetswhethertheEntrycanbechanged.
func(*Entry)SetText¶
func(e*Entry)SetText(textstring)
SetTextsetstheEntry'stexttotext.
func(*Entry)Text¶
func(e*Entry)Text()string
TextreturnstheEntry'stext.
typeExtKey¶
typeExtKeyint
TODOdocument
Note:thesemustbenumericallyidenticaltotheirlibuiequivalents.
const(
EscapeExtKey=iota+1
Insert//equivalentto"Help"onApplekeyboards
Delete
Home
End
PageUp
PageDown
Up
Down
Left
Right
F1//F1..F12areguaranteedtobeconsecutive
F2
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
N0//numpadkeys;independentofNumLockstate
N1//N0..N9areguaranteedtobeconsecutive
N2
N3
N4
N5
N6
N7
N8
N9
NDot
NEnter
NAdd
NSubtract
NMultiply
NDivide
)
typeFontButton¶
typeFontButtonstruct{
ControlBase
//containsfilteredorunexportedfields
}
FontButtonisaControlthatrepresentsabuttonthattheusercan
clicktoselectafont.
funcNewFontButton¶
funcNewFontButton()*FontButton
NewFontButtoncreatesanewFontButton.
func(*FontButton)Font¶
func(b*FontButton)Font()*FontDescriptor
FontreturnsthefontcurrentlyselectedintheFontButton.
func(*FontButton)OnChanged¶
func(b*FontButton)OnChanged(ffunc(*FontButton))
OnChangedregistersftoberunwhentheuserchangesthe
currentlyselectedfontintheFontButton.Onlyonefunctioncan
beregisteredatatime.
typeFontDescriptor¶
typeFontDescriptorstruct{
FamilyTextFamily
SizeTextSize
WeightTextWeight
ItalicTextItalic
StretchTextStretch
}
FontDescriptorprovidesacompletedescriptionofafontwhere
oneisneeded.Currently,thismeansasthedefaultfontofa
DrawTextLayoutandasthedatareturnedbyFontButton.
typeForm¶
typeFormstruct{
ControlBase
//containsfilteredorunexportedfields
}
FormisaControlthatholdsagroupofControlsvertically
withlabelsnexttoeach.Bydefault,eachcontrolhasits
preferredheight;ifacontrolismarked"stretchy",itwilltake
whateverspaceisleftover.Ifmultiplecontrolsaremarked
stretchy,theywillbegivenequalsharesoftheleftoverspace.
Therecanalsobespacebetweeneachcontrol("padding").
funcNewForm¶
funcNewForm()*Form
NewFormcreatesanewhorizontalForm.
func(*Form)Append¶
func(f*Form)Append(labelstring,childControl,stretchybool)
AppendaddsthegivencontroltotheendoftheForm.
func(*Form)Delete¶
func(f*Form)Delete(nint)
DeletedeletesthenthcontroloftheForm.
func(*Form)Destroy¶
func(f*Form)Destroy()
DestroydestroystheForm.IftheFormhaschildren,
DestroycallsDestroyonthoseControlsaswell.
func(*Form)Padded¶
func(f*Form)Padded()bool
Paddedreturnswhetherthereisspacebetweeneachcontrol
oftheForm.
func(*Form)SetPadded¶
func(f*Form)SetPadded(paddedbool)
SetPaddedcontrolswhetherthereisspacebetweeneachcontrol
oftheForm.ThesizeofthepaddingisdeterminedbytheOSand
itsbestpractices.
typeGrid¶
typeGridstruct{
ControlBase
//containsfilteredorunexportedfields
}
GridisaControlthatarrangesotherControlsinagrid.
Gridisaverypowerfulcontainer:itcanpositionandsizeeach
Controlinseveralwaysandcan(andmust)haveControlsadded
toitinanydirection.ItcanalsohaveControlsspanningmultiple
rowsandcolumns.
EachControlinaGridhasassociated"expansion"and
"alignment"valuesinboththeXandYdirection.
Expansiondetermineswhetherallcellsinthesamerow/column
aregivenwhateverspaceisleftoverafterfiguringouthowbig
therestoftheGridshouldbe.Alignmentdeterminestheposition
ofaControlrelativetoitscellaftercomputingtheabove.The
specialalignmentFillcanbeusedtogrowaControltofititscell.
Notethatexpansionandalignmentareindependentvariables.
Formoreinformationonexpansionandalignment,read
https://developer.gnome.org/gtk3/unstable/ch28s02.html.
funcNewGrid¶
funcNewGrid()*Grid
NewGridcreatesanewGrid.
func(*Grid)Append¶
func(g*Grid)Append(childControl,left,topint,xspan,yspanint,hexpandbool,halignAlign,vexpandbool,valignAlign)
AppendaddsthegivencontroltotheGrid,atthegivencoordinate.
func(*Grid)InsertAt¶
func(g*Grid)InsertAt(childControl,existingControl,atAt,xspan,yspanint,hexpandbool,halignAlign,vexpandbool,valignAlign)
InsertAtaddsthegivencontroltotheGridrelativetoanexisting
control.
func(*Grid)Padded¶
func(g*Grid)Padded()bool
Paddedreturnswhetherthereisspacebetweeneachcontrol
oftheGrid.
func(*Grid)SetPadded¶
func(g*Grid)SetPadded(paddedbool)
SetPaddedcontrolswhetherthereisspacebetweeneachcontrol
oftheGrid.ThesizeofthepaddingisdeterminedbytheOSand
itsbestpractices.
typeGroup¶
typeGroupstruct{
ControlBase
//containsfilteredorunexportedfields
}
GroupisaControlthatholdsanotherControlandwrapsitaround
alabelledbox(thoughsomesystemsmakethisboxinvisible).
Youcanusethistogrouprelatedcontrolstogether.
funcNewGroup¶
funcNewGroup(titlestring)*Group
NewGroupcreatesanewGroup.
func(*Group)Destroy¶
func(g*Group)Destroy()
DestroydestroystheGroup.IftheGrouphasachild,
DestroycallsDestroyonthataswell.
func(*Group)Margined¶
func(g*Group)Margined()bool
MarginedreturnswhethertheGrouphasmarginsarounditschild.
func(*Group)SetChild¶
func(g*Group)SetChild(childControl)
SetChildsetstheGroup'schildtochild.Ifchildisnil,theGroup
willnothaveachild.
func(*Group)SetMargined¶
func(g*Group)SetMargined(marginedbool)
SetMarginedcontrolswhethertheGrouphasmarginsaroundits
child.ThesizeofthemarginsaredeterminedbytheOSandits
bestpractices.
func(*Group)SetTitle¶
func(g*Group)SetTitle(titlestring)
SetTitlesetstheGroup'stitletotitle.
func(*Group)Title¶
func(g*Group)Title()string
TitlereturnstheGroup'stitle.
typeImage¶
typeImagestruct{
//containsfilteredorunexportedfields
}
Imagestoresanimagefordisplayonscreen.
Imagesarebuiltfromoneormorerepresentations,eachwiththe
sameaspectratiobutadifferentpixelsize.Packageui
automaticallyselectsthemostappropriaterepresentationfor
drawingtheimagewhenitcomestimetodrawtheimage;what
thismeansdependsonthepixeldensityofthetargetcontext.
Therefore,onecanuseImagetodrawhigher-detailedimageson
higher-densitydisplays.Thetypicalusecasesareeither:
-havejustasinglerepresentation,atwhichpointallscreens
usethesameimage,andthusuiImageactslikeasimple
bitmapimage,or
-havetwoimages,oneatnormalresolutionandoneat2x
resolution;thismatchesthecurrentexpectationsofsome
desktopsystemsatthetimeofwriting(mid-2018)
ImageallocatesOSresources;youmustexplicitlyfreeanImage
whenyouarefinishedwithit.
funcNewImage¶
funcNewImage(width,heightfloat64)*Image
NewImagecreatesanewImagewiththegivenwidthand
height.Thiswidthandheightshouldbethesizeinpointsofthe
imageinthedevice-independentcase;typicallythisisthe1xsize.
func(*Image)Append¶
func(i*Image)Append(img*image.RGBA)
AppendaddsthegivenimageasarepresentationoftheImage.
func(*Image)Free¶
func(i*Image)Free()
FreefreestheImage.
typeLabel¶
typeLabelstruct{
ControlBase
//containsfilteredorunexportedfields
}
LabelisaControlthatrepresentsalineoftextthatcannotbe
interactedwith.
funcNewLabel¶
funcNewLabel(textstring)*Label
NewLabelcreatesanewLabelwiththegiventext.
func(*Label)SetText¶
func(l*Label)SetText(textstring)
SetTextsetstheLabel'stexttotext.
func(*Label)Text¶
func(l*Label)Text()string
TextreturnstheLabel'stext.
typeModifiers¶
typeModifiersuint
TODOdocument
Note:thesemustbenumericallyidenticaltotheirlibuiequivalents.
const(
CtrlModifiers=1<
延伸文章資訊
- 1ui - pkg.dev
github.com/andlabs/ui ... ui: platform-native GUI library for Go ... Main initializes package ui,...
- 2andlabs/ui - Platform-native GUI library for Go. : r/golang - Reddit
if you run linux and are not afraid of running go tip (until go1.3 is released) running the wakeu...
- 3go语言gui的库andlabs/ui官方代码实例 - 简书
今天我们记录andlabs/ui库的学习历程,我们看一下官方的例子,因为它教程比较少,只能看官方的案例,百度看介绍的时候功能也可以。
- 4Golang NewArea示例
Golang NewArea - 已找到6个示例。这些是从开源项目中提取的最受好评的github.com/andlabs/ui.NewArea现实Golang示例。您可以评价示例,以帮助我们提高...
- 5set andlabs go ui windows - YouTube
andlabs/ui library for GUI with golang on windowshttps://www.mchampaneri.in/2018/02/gui-programmi...