Skip to content

Commit

Permalink
minor annotation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmdev committed Nov 23, 2022
1 parent f703c4b commit ab078f1
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 55 deletions.
2 changes: 1 addition & 1 deletion button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Button:toggle_expand(expand)
end

---Set the icon drawn alongside the button text.
---@param code string
---@param code? string
---@param color? renderer.color
---@param hover_color? renderer.color
function Button:set_icon(code, color, hover_color)
Expand Down
6 changes: 3 additions & 3 deletions dialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ local Button = require "widget.button"
local Label = require "widget.label"

---@class widget.dialog : widget
---@field private title widget.label
---@field private close widget.button
---@field private panel widget
---@field protected title widget.label
---@field protected close widget.button
---@field protected panel widget
local Dialog = Widget:extend()

---Constructor
Expand Down
2 changes: 1 addition & 1 deletion filepicker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function FilePicker:clear_filters()
end

---Set the operation mode for the file picker.
---@param mode widget.filepicker.modes | string
---@param mode widget.filepicker.modes | string | integer
function FilePicker:set_mode(mode)
if type(mode) == "string" then
---@type integer
Expand Down
13 changes: 8 additions & 5 deletions fontdialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
--

local core = require "core"
local command = require "core.command"
local style = require "core.style"
local Button = require "widget.button"
local CheckBox = require "widget.checkbox"
Expand All @@ -17,7 +16,11 @@ local SelectBox = require "widget.selectbox"
local MessageBox = require "widget.messagebox"
local Fonts = require "widget.fonts"

---@class widget.fontdialog.fontoptions : renderer.fontoptions
---@field size number

---@class widget.fontdialog : widget.dialog
---@field super widget.dialog
---@field fontdata widget.fontslist.font
---@field preview widget.label
---@field font_size widget.numberbox
Expand All @@ -37,7 +40,7 @@ local FontDialog = Dialog:extend()

---Constructor
---@param font? widget.fontslist.font
---@param options? renderer.fontoptions
---@param options? widget.fontdialog.fontoptions
function FontDialog:new(font, options)
FontDialog.super.new(self, "Font Selector")

Expand Down Expand Up @@ -190,7 +193,7 @@ function FontDialog:get_font()
return self.fontdata
end

---@param options renderer.fontoptions
---@param options widget.fontdialog.fontoptions
function FontDialog:set_options(options)
if options.size then
self.font_size:set_value(tonumber(options.size) or 15)
Expand Down Expand Up @@ -233,7 +236,7 @@ function FontDialog:set_options(options)
end
end

---@return renderer.fontoptions
---@return widget.fontdialog.fontoptions
function FontDialog:get_options()
return {
size = self.font_size:get_value(),
Expand All @@ -249,7 +252,7 @@ end

---Called when the user clicks on save
---@param font widget.fontslist.font
---@param options renderer.fontoptions
---@param options widget.fontdialog.fontoptions
function FontDialog:on_save(font, options) end

function FontDialog:update()
Expand Down
30 changes: 15 additions & 15 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ local WidgetFontReference = {}
---@field public background_color renderer.color
---@field public render_background boolean
---@field public type_name string
---@field private visible boolean
---@field private has_focus boolean
---@field private dragged boolean
---@field private tooltip string
---@field private label string
---@field private input_text boolean
---@field private textview widget
---@field private next_zindex integer
---@field private mouse widget.position
---@field private prev_size widget.position
---@field private mouse_is_pressed boolean
---@field private mouse_is_hovering boolean
---@field private mouse_pressed_outside boolean
---@field private is_scrolling boolean
---@field protected visible boolean
---@field protected has_focus boolean
---@field protected dragged boolean
---@field protected tooltip string
---@field protected label string | widget.styledtext
---@field protected input_text boolean
---@field protected textview widget
---@field protected next_zindex integer
---@field protected mouse widget.position
---@field protected prev_size widget.position
---@field protected mouse_is_pressed boolean
---@field protected mouse_is_hovering boolean
---@field protected mouse_pressed_outside boolean
---@field protected is_scrolling boolean
local Widget = View:extend()

---Indicates on a widget.styledtext that a new line follows.
Expand Down Expand Up @@ -584,7 +584,7 @@ function Widget:set_tooltip(tooltip)
end

---A text label for the widget, not all widgets support this.
---@param text string
---@param text string | widget.styledtext
function Widget:set_label(text)
self.label = text
end
Expand Down
1 change: 1 addition & 0 deletions inputdialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local Label = require "widget.label"
local TextBox = require "widget.textbox"

---@class widget.inputdialog : widget.dialog
---@field super widget.dialog
---@field message widget.label
---@field text widget.textbox
---@field save widget.button
Expand Down
1 change: 1 addition & 0 deletions keybinddialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local MessageBox = require "widget.messagebox"
local current_dialog = nil

---@class widget.keybinddialog : widget.dialog
---@field super widget.dialog
---@field selected integer
---@field shortcuts widget.listbox
---@field add widget.button
Expand Down
2 changes: 1 addition & 1 deletion listbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local ListBoxColumn = {}
---@alias widget.listbox.colpos table<integer,integer>

---@class widget.listbox : widget
---@field private rows widget.listbox.row[]
---@field rows widget.listbox.row[]
---@field private row_data any
---@field private columns widget.listbox.column[]
---@field private positions widget.listbox.colpos[]
Expand Down
55 changes: 27 additions & 28 deletions messagebox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ MessageBox.ICON_INFO = "i"
MessageBox.ICON_WARNING = "!"

---@alias widget.messagebox.icontype
---|>"MessageBox.ICON_ERROR"
---| "MessageBox.ICON_INFO"
---| "MessageBox.ICON_WARNING"
---|>`MessageBox.ICON_ERROR`
---| `MessageBox.ICON_INFO`
---| `MessageBox.ICON_WARNING`

MessageBox.BUTTONS_OK = 1
MessageBox.BUTTONS_OK_CANCEL = 2
MessageBox.BUTTONS_YES_NO = 3
MessageBox.BUTTONS_YES_NO_CANCEL = 4

---@alias widget.messagebox.buttonstype
---|>"MessageBox.BUTTONS_OK"
---| "MessageBox.BUTTONS_OK_CANCEL"
---| "MessageBox.BUTTONS_YES_NO"
---| "MessageBox.BUTTONS_YES_NO_CANCEL"
---|>`MessageBox.BUTTONS_OK`
---| `MessageBox.BUTTONS_OK_CANCEL`
---| `MessageBox.BUTTONS_YES_NO`
---| `MessageBox.BUTTONS_YES_NO_CANCEL`

---@alias widget.messagebox.onclosehandler fun(self: widget.messagebox, button_id: integer, button: widget.button):void
---@alias widget.messagebox.onclosehandler fun(self: widget.messagebox, button_id: integer, button: widget.button)

---Constructor
---@param parent widget
---@param title string
---@param message string
---@param message string | widget.styledtext
---@param icon widget.messagebox.icontype
---@param icon_color renderer.color
function MessageBox:new(parent, title, message, icon, icon_color)
Expand All @@ -65,14 +65,14 @@ function MessageBox:new(parent, title, message, icon, icon_color)
end

---Change the message box title.
---@param text string|widget.styledtext
---@param text string | widget.styledtext
function MessageBox:set_title(text)
self.title:set_label(text)
end

---Change the message box icon.
---@param icon widget.messagebox.icontype
---@param icon_color renderer.color
---@param color? renderer.color
function MessageBox:set_icon(icon, color)
if not color then
color = style.text
Expand All @@ -86,7 +86,7 @@ function MessageBox:set_icon(icon, color)
end

---Change the message box message.
---@param text string|widget.styledtext
---@param text string | widget.styledtext
function MessageBox:set_message(text)
self.message:set_label(text)
end
Expand All @@ -104,8 +104,8 @@ function MessageBox:add_button(button_or_label)
local button_id = #self.buttons
local new_button = self.buttons[button_id]
local on_click = new_button.on_click
new_button.on_click = function(this)
on_click(this)
new_button.on_click = function(this, ...)
on_click(this, ...)
self:on_close(button_id, new_button)
end
end
Expand Down Expand Up @@ -165,9 +165,8 @@ end
---Called when the user clicks one of the buttons in the message box.
---@param button_id integer
---@param button widget.button
function MessageBox:on_close(button_id, button)
self:hide()
end
---@diagnostic disable-next-line
function MessageBox:on_close(button_id, button) self:hide() end

function MessageBox:update()
if not MessageBox.super.update(self) then return false end
Expand Down Expand Up @@ -277,12 +276,12 @@ function MessageBox:draw()
end

---Wrapper to easily show a message box.
---@param title string
---@param message string
---@param title string | widget.styledtext
---@param message string | widget.styledtext
---@param icon widget.messagebox.icontype
---@param icon_color renderer.color
---@param on_close widget.messagebox.onclosehandler
---@param buttons widget.messagebox.buttonstype
---@param icon_color? renderer.color
---@param on_close? widget.messagebox.onclosehandler
---@param buttons? widget.messagebox.buttonstype
function MessageBox.alert(title, message, icon, icon_color, on_close, buttons)
buttons = buttons or MessageBox.BUTTONS_OK
---@type widget.messagebox
Expand Down Expand Up @@ -313,26 +312,26 @@ function MessageBox.alert(title, message, icon, icon_color, on_close, buttons)
end

---Wrapper to easily show a info message box.
---@param title string
---@param message string
---@param title string | widget.styledtext
---@param message string | widget.styledtext
---@param on_close? widget.messagebox.onclosehandler
---@param buttons? widget.messagebox.buttonstype
function MessageBox.info(title, message, on_close, buttons)
MessageBox.alert(title, message, MessageBox.ICON_INFO, nil, on_close, buttons)
end

---Wrapper to easily show a warning message box.
---@param title string
---@param message string
---@param title string | widget.styledtext
---@param message string | widget.styledtext
---@param on_close? widget.messagebox.onclosehandler
---@param buttons? widget.messagebox.buttonstype
function MessageBox.warning(title, message, on_close, buttons)
MessageBox.alert(title, message, MessageBox.ICON_WARNING, nil, on_close, buttons)
end

---Wrapper to easily show an error message box.
---@param title string
---@param message string
---@param title string | widget.styledtext
---@param message string | widget.styledtext
---@param on_close? widget.messagebox.onclosehandler
---@param buttons? widget.messagebox.buttonstype
function MessageBox.error(title, message, on_close, buttons)
Expand Down
3 changes: 2 additions & 1 deletion notebook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ end

---Called when a tab is clicked.
---@param pane widget.notebook.pane
---@diagnostic disable-next-line
function NoteBook:on_tab_click(pane) end

---Adds a new pane to the notebook and returns a container widget where
Expand Down Expand Up @@ -82,7 +83,7 @@ end
---@param name string
---@return widget.notebook.pane | nil
function NoteBook:get_pane(name)
for pos, pane in pairs(self.panes) do
for _, pane in pairs(self.panes) do
if pane.name == name then
return pane
end
Expand Down
1 change: 1 addition & 0 deletions selectbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ end
---Overwrite to listen to on_selected events.
---@param item_idx integer
---@param item_data widget.listbox.row
---@diagnostic disable-next-line
function SelectBox:on_selected(item_idx, item_data) end

function SelectBox:on_mouse_enter(...)
Expand Down
1 change: 1 addition & 0 deletions textbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ end
--- line, col, text, undo_stack, time
---remove arguments (see Doc:raw_remove):
--- line1, col1, line2, col2, undo_stack, time
---@diagnostic disable-next-line
function TextBox:on_text_change(action, ...) end

function TextBox:update()
Expand Down

0 comments on commit ab078f1

Please sign in to comment.