# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

.section Widgets
.topic widget.imagebutton
.title ImageButton
.toc 0 ImageButton
.index ImageButton
.index wgtImageButton
.index wgtImageButtonFromFile
.index wgtImageButtonSetData
.index wgtImageButtonLoadFile

.h2 ImageButton

A clickable button that displays an image instead of text. Has the same press/release visual feedback and focus handling as a regular Button. Can be created from raw pixel data or loaded from an image file. Typically used to populate a Toolbar.

Header: widgets/imgBtn.h

.h3 Creation

.code
WidgetT *btn = wgtImageButtonFromFile(parent, "icons/save.bmp");
btn->onClick = onSaveClicked;
.endcode

.h3 API Functions

.table
  Function                                                             Description
  --------                                                             -----------
  WidgetT *wgtImageButton(parent, data, w, h, pitch)                   Create from raw pixel data (in display's native format).
  WidgetT *wgtImageButtonFromFile(parent, path)                        Create by loading an image file.
  void wgtImageButtonSetData(w, data, imgW, imgH, pitch)               Replace the image with new raw pixel data.
  void wgtImageButtonLoadFile(w, path)                                 Replace the image by loading a new file.
.endtable

.h3 API Struct (wgtRegisterApi "imagebutton")

.table
  Slot         Function
  ----         --------
  create       wgtImageButton
  fromFile     wgtImageButtonFromFile
  setData      wgtImageButtonSetData
  loadFile     wgtImageButtonLoadFile
.endtable

.h3 Properties (BASIC Interface)

.table
  Property      Type       Access       Description
  --------      ----       ------       -----------
  Picture       String     Read/Write   Setting writes a file path (loads image). Reading returns the current path.
  ImageWidth    Integer    Read-only    Width of the currently loaded image in pixels.
  ImageHeight   Integer    Read-only    Height of the currently loaded image in pixels.
.endtable

.h3 Methods

No widget-specific BASIC methods. Setting Picture loads a new image.

.h3 Events

.table
  Callback     Description
  --------     -----------
  onClick      Fires when the image button is clicked (press and release inside).
.endtable

.h3 Default Event

"Click" (VB basName: ImageButton).
