github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/framework/doc.go (about) 1 /* 2 Framework is an immediate mode GUI library for Go, its implementation is a partial source port of Nuklear [0] by Micha Mettke. 3 For a brief introduction to Immediate Mode GUI see [1] 4 5 Opening a Window 6 7 A window can be opened with the following three lines of code: 8 9 wnd := framework.NewMasterWindow(0, "Title", updatefn) 10 wnd.SetStyle(style.FromTheme(style.DarkTheme, 1.0)) 11 wnd.Main() 12 13 The first line creates the MasterWindow object and sets its flags (usually 0 is fine) and updatefn as the update function. 14 Updatefn will be responsible for drawing the contents of the window and handling the GUI logic (see the "Window Update and layout" section). 15 16 The second line configures the theme, the font (passing nil will use the default font face) and the default scaling factor (see the "Scaling" section). 17 18 The third line opens the window and starts its event loop, updatefn will be called whenever the window needs to be redrawn, this is usually only in response to mouse and keyboard events, if you want the window to be redrawn you can also manually call wnd.Changed(). 19 20 Window Update and layout 21 22 The update function is responsible for drawing the contents of the window as well as handling user events, this is usually done by calling methods of framework.Window. 23 24 For example, drawing a simple text button is done with this code: 25 26 if w.ButtonText("button caption") { 27 // code here only runs once every time the button is clicked 28 } 29 30 Widgets are laid out left to right and top to bottom, each row has a layout that can be configured calling the methods of framework.rowConstructor (an instance of which can be obtained by calling the `framework.Window.Row` or `framework.Window.RowScaled`). There are three main row layout modes: 31 32 - Static: in this mode the columns of the row have a fixed, user defined, width. This row layout can be selected calling Static or StaticScaled 33 34 - Dynamic: in this mode the columns of the row have a width proportional to the total width of the window. This row layout can be selected calling Dynamic, DynamicScaled or Ratio 35 36 - Space: in this mode widgets are positioned and sized arbitrarily. This row layout can be selected calling SpaceBegin or SpaceBeginRatio, once this row layout is selected widgets can be positioned using LayoutSpacePush or LayoutSpacePushRatio 37 38 Scaling 39 40 When calling SetStyle you can specify a scaling factor, this will be used to scale the sizes in the style argument and also all the size arguments for the methods of rowConstructor. 41 42 Links 43 44 [0] https://github.com/vurtun/nuklear/ 45 [1] https://mollyrocket.com/861 46 */ 47 package framework