github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/frontend/desktop/windows/winc/README.md (about)

     1  # winc
     2  
     3  ** This is a fork of [tadvi/winc](https://github.com/tadvi/winc) for the sole
     4  purpose of integration with [Wails](https://github.com/AlpineAIO/wails). This
     5  repository comes with \***no support**\* **
     6  
     7  Common library for Go GUI apps on Windows. It is for Windows OS only. This makes
     8  library smaller than some other UI libraries for Go.
     9  
    10  Design goals: minimalism and simplicity.
    11  
    12  ## Dependencies
    13  
    14  No other dependencies except Go standard library.
    15  
    16  ## Building
    17  
    18  If you want to package icon files and other resources into binary **rsrc** tool
    19  is recommended:
    20  
    21      rsrc -manifest app.manifest -ico=app.ico,application_edit.ico,application_error.ico -o rsrc.syso
    22  
    23  Here app.manifest is XML file in format:
    24  
    25  ```
    26  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    27  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    28      <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="App" type="win32"/>
    29      <dependency>
    30          <dependentAssembly>
    31              <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
    32          </dependentAssembly>
    33      </dependency>
    34  </assembly>
    35  ```
    36  
    37  Most Windows applications do not display command prompt. Build your Go project
    38  with flag to indicate that it is Windows GUI binary:
    39  
    40      go build -ldflags="-H windowsgui"
    41  
    42  ## Samples
    43  
    44  Best way to learn how to use the library is to look at the included **examples**
    45  projects.
    46  
    47  ## Setup
    48  
    49  1. Make sure you have a working Go installation and build environment, see more
    50     for details on page below. http://golang.org/doc/install
    51  
    52  2. go get github.com/AlpineAIO/wails/v2/internal/frontend/desktop/windows/winc
    53  
    54  ## Icons
    55  
    56  When rsrc is used to pack icons into binary it displays IDs of the packed icons.
    57  
    58  ```
    59  rsrc -manifest app.manifest -ico=app.ico,lightning.ico,edit.ico,application_error.ico -o rsrc.syso
    60  Manifest ID:  1
    61  Icon  app.ico  ID:  10
    62  Icon  lightning.ico  ID:  13
    63  Icon  edit.ico  ID:  16
    64  Icon  application_error.ico  ID:  19
    65  ```
    66  
    67  Use IDs to reference packed icons.
    68  
    69  ```
    70  const myIcon = 13
    71  
    72  btn.SetResIcon(myIcon) // Set icon on the button.
    73  ```
    74  
    75  Included source **examples** use basic building via `release.bat` files. Note
    76  that icon IDs are order dependent. So if you change they order in -ico flag then
    77  icon IDs will be different. If you want to keep order the same, just add new
    78  icons to the end of -ico comma separated list.
    79  
    80  ## Layout Manager
    81  
    82  SimpleDock is default layout manager.
    83  
    84  Current design of docking and split views allows building simple apps but if you
    85  need to have multiple split views in few different directions you might need to
    86  create your own layout manager.
    87  
    88  Important point is to have **one** control inside SimpleDock set to dock as
    89  **Fill**. Controls that are not set to any docking get placed using SetPos()
    90  function. So you can have Panel set to dock at the Top and then have another
    91  dock to arrange controls inside that Panel or have controls placed using
    92  SetPos() at fixed positions.
    93  
    94  ![Example layout with two toolbars and status bar](dock_topbottom.png)
    95  
    96  This is basic layout. Instead of toolbars and status bar you can have Panel or
    97  any other control that can resize. Panel can have its own internal Dock that
    98  will arrange other controls inside of it.
    99  
   100  ![Example layout with two toolbars and navigation on the left](dock_topleft.png)
   101  
   102  This is layout with extra control(s) on the left. Left side is usually treeview
   103  or listview.
   104  
   105  The rule is simple: you either dock controls using SimpleDock OR use SetPos() to
   106  set them at fixed positions. That's it.
   107  
   108  At some point **winc** may get more sophisticated layout manager.
   109  
   110  ## Dialog Screens
   111  
   112  Dialog screens are not based on Windows resource files (.rc). They are just
   113  windows with controls placed at fixed coordinates. This works fine for dialog
   114  screens up to 10-14 controls.
   115  
   116  # Minimal Demo
   117  
   118  ```
   119  package main
   120  
   121  import (
   122  	"github.com/AlpineAIO/wails/v2/internal/frontend/desktop/windows/winc"
   123  )
   124  
   125  func main() {
   126  	mainWindow := winc.NewForm(nil)
   127  	mainWindow.SetSize(400, 300)  // (width, height)
   128  	mainWindow.SetText("Hello World Demo")
   129  
   130  	edt := winc.NewEdit(mainWindow)
   131  	edt.SetPos(10, 20)
   132  	// Most Controls have default size unless SetSize is called.
   133  	edt.SetText("edit text")
   134  
   135  	btn := winc.NewPushButton(mainWindow)
   136  	btn.SetText("Show or Hide")
   137  	btn.SetPos(40, 50)	// (x, y)
   138  	btn.SetSize(100, 40) // (width, height)
   139  	btn.OnClick().Bind(func(e *winc.Event) {
   140  		if edt.Visible() {
   141  			edt.Hide()
   142  		} else {
   143  			edt.Show()
   144  		}
   145  	})
   146  
   147  	mainWindow.Center()
   148  	mainWindow.Show()
   149  	mainWindow.OnClose().Bind(wndOnClose)
   150  
   151  	winc.RunMainLoop() // Must call to start event loop.
   152  }
   153  
   154  func wndOnClose(arg *winc.Event) {
   155  	winc.Exit()
   156  }
   157  ```
   158  
   159  ![Hello World](examples/hello.png)
   160  
   161  Result of running sample_minimal.
   162  
   163  ## Create Your Own
   164  
   165  It is good practice to create your own controls based on existing structures and
   166  event model. Library contains some of the controls built that way: IconButton
   167  (button.go), ErrorPanel (panel.go), MultiEdit (edit.go), etc. Please look at
   168  existing controls as examples before building your own.
   169  
   170  When designing your own controls keep in mind that types have to be converted
   171  from Go into Win32 API and back. This is usually due to string UTF8 and UTF16
   172  conversions. But there are other types of conversions too.
   173  
   174  When developing your own controls you might also need to:
   175  
   176      import "github.com/AlpineAIO/wails/v2/internal/frontend/desktop/windows/winc/w32"
   177  
   178  w32 has Win32 API low level constants and functions.
   179  
   180  Look at **sample_control** for example of custom built window.
   181  
   182  ## Companion Package
   183  
   184  [Go package for Windows Systray icon, menu and notifications](https://github.com/tadvi/systray)
   185  
   186  ## Credits
   187  
   188  This library is built on
   189  
   190  [AllenDang/gform Windows GUI framework for Go](https://github.com/AllenDang/gform)
   191  
   192  **winc** takes most design decisions from **gform** and adds many more controls
   193  and code samples to it.