doc: Upgrade the widget layout documentation.

This commit is contained in:
Emmanuel Lepage Vallee 2019-11-29 01:22:50 -05:00
parent be14666b4a
commit f21e0ba9dd
8 changed files with 207 additions and 82 deletions

View File

@ -1,42 +1,65 @@
--- Set a widget at a specific index, replace the current one.
-- **Signal:** widget::replaced The argument is the new widget and the old one
-- and the index.
--
-- @tparam number index A widget or a widget index
-- @param widget2 The widget to take the place of the first one
-- @tparam widget widget2 The widget to take the place of the first one
-- @treturn boolean If the operation is successful
-- @method set
-- @emits widget::replaced
-- @emitstparam widget::replaced widget self The layout.
-- @emitstparam widget::replaced widget widget index The inserted widget.
-- @emitstparam widget::replaced widget previous The previous widget.
-- @emitstparam widget::replaced number index The replaced index.
-- @interface layout
--- Replace the first instance of `widget` in the layout with `widget2`.
--
-- **Signal:** widget::replaced The argument is the new widget and the old one
-- and the index.
-- @param widget The widget to replace
-- @param widget2 The widget to replace `widget` with
-- @tparam widget widget The widget to replace
-- @tparam widget widget2 The widget to replace `widget` with
-- @tparam[opt=false] boolean recursive Dig in all compatible layouts to find the widget.
-- @treturn boolean If the operation is successful
-- @method replace_widget
-- @emits widget::replaced
-- @emitstparam widget::replaced widget self The layout.
-- @emitstparam widget::replaced widget widget index The inserted widget.
-- @emitstparam widget::replaced widget previous The previous widget.
-- @emitstparam widget::replaced number index The replaced index.
-- @interface layout
--- Swap 2 widgets in a layout.
-- **Signal:** widget::swapped The arguments are both widgets and both (new) indexes.
--
-- @tparam number index1 The first widget index
-- @tparam number index2 The second widget index
-- @treturn boolean If the operation is successful
-- @method swap
-- @emits widget::swapped
-- @emitstparam widget::swapped widget self The layout.
-- @emitstparam widget::swapped widget widget1 index The first widget.
-- @emitstparam widget::swapped widget widget2 index The second widget.
-- @emitstparam widget::swapped number index1 The first index.
-- @emitstparam widget::swapped number index1 The second index.
-- @interface layout
--- Swap 2 widgets in a layout.
-- If widget1 is present multiple time, only the first instance is swapped
-- **Signal:** widget::swapped The arguments are both widgets and both (new) indexes.
-- if the layouts not the same, then only `widget::replaced` will be emitted.
-- @param widget1 The first widget
-- @param widget2 The second widget
-- @tparam widget widget1 The first widget
-- @tparam widget widget2 The second widget
-- @tparam[opt=false] boolean recursive Dig in all compatible layouts to find the widget.
-- @treturn boolean If the operation is successful
-- @method swap_widgets
--- Get all direct children of this layout.
-- @param layout The layout you are modifying.
-- @property children
-- @emits widget::swapped
-- @emitstparam widget::swapped widget self The layout.
-- @emitstparam widget::swapped widget widget1 index The first widget.
-- @emitstparam widget::swapped widget widget2 index The second widget.
-- @emitstparam widget::swapped number index1 The first index.
-- @emitstparam widget::swapped number index1 The second index.
-- @interface layout
--- Reset a ratio layout. This removes all widgets from the layout.
-- **Signal:** widget::reset
-- @param layout The layout you are modifying.
-- @method reset
-- @emits widget::reset
-- @emitstparam widget::reset widget self The layout.
-- @interface layout

View File

@ -142,7 +142,8 @@ end
--- Set the layout's first widget.
-- This is the widget that is at the left/top
-- @property first
-- @param widget
-- @tparam widget first
-- @propemits true false
function align:set_first(widget)
if self._private.first == widget then
@ -150,11 +151,13 @@ function align:set_first(widget)
end
self._private.first = widget
self:emit_signal("widget::layout_changed")
self:emit_signal("property::first", widget)
end
--- Set the layout's second widget. This is the centered one.
-- @property second
-- @param widget
-- @tparam widget second
-- @propemits true false
function align:set_second(widget)
if self._private.second == widget then
@ -162,12 +165,14 @@ function align:set_second(widget)
end
self._private.second = widget
self:emit_signal("widget::layout_changed")
self:emit_signal("property::second", widget)
end
--- Set the layout's third widget.
-- This is the widget that is at the right/bottom
-- @property third
-- @param widget
-- @tparam widget third
-- @propemits true false
function align:set_third(widget)
if self._private.third == widget then
@ -175,6 +180,7 @@ function align:set_third(widget)
end
self._private.third = widget
self:emit_signal("widget::layout_changed")
self:emit_signal("property::third", widget)
end
for _, prop in ipairs {"first", "second", "third", "expand" } do
@ -183,12 +189,6 @@ for _, prop in ipairs {"first", "second", "third", "expand" } do
end
end
--- All direct children of this layout.
-- This can be used to replace all 3 widgets at once.
-- @treturn table a list of all widgets
-- @property children
-- @param table
function align:get_children()
return gtable.from_sparse {self._private.first, self._private.second, self._private.third}
end
@ -229,7 +229,7 @@ end
--- Set the expand mode which determines how sub widgets expand to take up
-- unused space.
--
-- @tparam[opt=inside] string mode How to use unused space.
-- The following values are valid:
--
-- * "inside" - Default option. Size of outside widgets is determined using
-- their fit function. Second, middle, or center widget expands to fill
@ -240,7 +240,9 @@ end
-- * "none" - All widgets are sized using their fit function, drawn to only the
-- returned space, or remaining space, whichever is smaller. Center widget
-- gets priority.
--
-- @property expand
-- @tparam[opt=inside] string mode How to use unused space.
function align:set_expand(mode)
if mode == "none" or mode == "outside" then
@ -249,6 +251,7 @@ function align:set_expand(mode)
self._private.expand = "inside"
end
self:emit_signal("widget::layout_changed")
self:emit_signal("property::expand", mode)
end
function align:reset()

View File

@ -62,9 +62,11 @@ function fixed:layout(context, width, height)
return result
end
--- Add some widgets to the given layout
--- Add some widgets to the given layout.
--
-- @method add
-- @param ... Widgets that should be added (must at least be one)
-- @tparam widget ... Widgets that should be added (must at least be one).
-- @interface layout
function fixed:add(...)
-- No table.pack in Lua 5.1 :-(
local args = { n=select('#', ...), ... }
@ -78,10 +80,12 @@ function fixed:add(...)
end
--- Remove a widget from the layout
--- Remove a widget from the layout.
--
-- @method remove
-- @tparam number index The widget index to remove
-- @treturn boolean index If the operation is successful
-- @interface layout
function fixed:remove(index)
if not index or index < 1 or index > #self._private.widgets then return false end
@ -92,12 +96,14 @@ function fixed:remove(index)
return true
end
--- Remove one or more widgets from the layout
--- Remove one or more widgets from the layout.
--
-- The last parameter can be a boolean, forcing a recursive seach of the
-- widget(s) to remove.
-- @method remove_widgets
-- @param widget ... Widgets that should be removed (must at least be one)
-- @tparam widget ... Widgets that should be removed (must at least be one)
-- @treturn boolean If the operation is successful
-- @interface layout
function fixed:remove_widgets(...)
local args = { ... }
@ -131,12 +137,13 @@ function fixed:set_children(children)
end
end
--- Replace the first instance of `widget` in the layout with `widget2`
--- Replace the first instance of `widget` in the layout with `widget2`.
-- @method replace_widget
-- @param widget The widget to replace
-- @param widget2 The widget to replace `widget` with
-- @tparam widget widget The widget to replace
-- @tparam widget widget2 The widget to replace `widget` with
-- @tparam[opt=false] boolean recursive Digg in all compatible layouts to find the widget.
-- @treturn boolean If the operation is successful
-- @interface layout
function fixed:replace_widget(widget, widget2, recursive)
local idx, l = self:index(widget, recursive)
@ -217,19 +224,27 @@ end
--@DOC_wibox_layout_fixed_spacing_widget_EXAMPLE@
--
-- @property spacing_widget
-- @param widget
-- @tparam widget spacing_widget
-- @propemits true false
-- @interface layout
function fixed:set_spacing_widget(wdg)
self._private.spacing_widget = base.make_widget_from_value(wdg)
self:emit_signal("widget::layout_changed")
self:emit_signal("property::spacing_widget", wdg)
end
--- Insert a new widget in the layout at position `index`.
-- **Signal:** widget::inserted The arguments are the widget and the index
--
-- @method insert
-- @tparam number index The position
-- @param widget The widget
-- @treturn boolean If the operation is successful
-- @tparam number index The position.
-- @tparam widget widget The widget.
-- @treturn boolean If the operation is successful.
-- @emits widget::inserted
-- @emitstparam widget::inserted widget self The fixed layout.
-- @emitstparam widget::inserted widget widget index The inserted widget.
-- @emitstparam widget::inserted number count The widget count.
-- @interface layout
function fixed:insert(index, widget)
if not index or index < 1 or index > #self._private.widgets + 1 then return false end
@ -286,18 +301,21 @@ function fixed:reset()
self._private.widgets = {}
self:emit_signal("widget::layout_changed")
self:emit_signal("widget::reseted")
self:emit_signal("widget::reset")
end
--- Set the layout's fill_space property. If this property is true, the last
-- widget will get all the space that is left. If this is false, the last widget
-- won't be handled specially and there can be space left unused.
-- @property fill_space
-- @param boolean
-- @tparam boolean fill_space
-- @propemits true false
function fixed:fill_space(val)
if self._private.fill_space ~= val then
self._private.fill_space = not not val
self:emit_signal("widget::layout_changed")
self:emit_signal("property::fill_space", val)
end
end
@ -346,11 +364,14 @@ end
--
-- @property spacing
-- @tparam number spacing Spacing between widgets.
-- @propemits true false
-- @interface layout
function fixed:set_spacing(spacing)
if self._private.spacing ~= spacing then
self._private.spacing = spacing
self:emit_signal("widget::layout_changed")
self:emit_signal("property::spacing", spacing)
end
end

View File

@ -15,30 +15,40 @@ local gtable = require("gears.table")
local flex = {}
--@DOC_fixed_COMMON@
--- Add some widgets to the given fixed layout
-- @param layout The layout you are modifying.
-- @tparam widget ... Widgets that should be added (must at least be one)
--- Add some widgets to the given fixed layout.
--
-- @tparam widget ... Widgets that should be added (must at least be one).
-- @method add
-- @interface layout
--- Remove a widget from the layout
-- @tparam index The widget index to remove
-- @treturn boolean index If the operation is successful
--- Remove a widget from the layout.
--
-- @tparam index The widget index to remove.
-- @treturn boolean index If the operation is successful.
-- @method remove
-- @interface layout
--- Remove one or more widgets from the layout
--- Remove one or more widgets from the layout.
--
-- The last parameter can be a boolean, forcing a recursive seach of the
-- widget(s) to remove.
-- @param widget ... Widgets that should be removed (must at least be one)
-- @treturn boolean If the operation is successful
--
-- @tparam widget ... Widgets that should be removed (must at least be one).
-- @treturn boolean If the operation is successful.
-- @method remove_widgets
-- @interface layout
--- Insert a new widget in the layout at position `index`
--- Insert a new widget in the layout at position `index`.
--
-- @tparam number index The position
-- @param widget The widget
-- @tparam widget widget The widget
-- @treturn boolean If the operation is successful
-- @method insert
-- @emits widget::inserted
-- @emitstparam widget::inserted widget self The fixed layout.
-- @emitstparam widget::inserted widget widget index The inserted widget.
-- @emitstparam widget::inserted number count The widget count.
-- @interface layout
--- The widget used to fill the spacing between the layout elements.
--
@ -47,7 +57,9 @@ local flex = {}
--@DOC_wibox_layout_flex_spacing_widget_EXAMPLE@
--
-- @property spacing_widget
-- @param widget
-- @tparam widget spacing_widget
-- @propemits true false
-- @interface layout
--- Add spacing between each layout widgets.
--
@ -55,6 +67,7 @@ local flex = {}
--
-- @property spacing
-- @tparam number spacing Spacing between widgets.
-- @propemits true false
function flex:layout(_, width, height)
local result = {}
@ -146,14 +159,18 @@ function flex:fit(context, orig_width, orig_height)
end
--- Set the maximum size the widgets in this layout will take.
--
--That is, maximum width for horizontal and maximum height for vertical.
--
-- @property max_widget_size
-- @param number
-- @tparam number max_widget_size
-- @propemits true false
function flex:set_max_widget_size(val)
if self._private.max_widget_size ~= val then
self._private.max_widget_size = val
self:emit_signal("widget::layout_changed")
self:emit_signal("property::max_widget_size", val)
end
end
@ -167,22 +184,30 @@ local function get_layout(dir, widget1, ...)
return ret
end
--- Returns a new horizontal flex layout. A flex layout shares the available space
-- equally among all widgets. Widgets can be added via :add(widget).
--- Returns a new horizontal flex layout.
--
-- A flex layout shares the available space.
-- equally among all widgets. Widgets can be added via `:add(widget)`.
--
-- @tparam widget ... Widgets that should be added to the layout.
-- @constructorfct wibox.layout.flex.horizontal
function flex.horizontal(...)
return get_layout("horizontal", ...)
end
--- Returns a new vertical flex layout. A flex layout shares the available space
-- equally among all widgets. Widgets can be added via :add(widget).
--- Returns a new vertical flex layout.
--
-- A flex layout shares the available space
-- equally among all widgets. Widgets can be added via `:add(widget)`.
--
-- @tparam widget ... Widgets that should be added to the layout.
-- @constructorfct wibox.layout.flex.vertical
function flex.vertical(...)
return get_layout("vertical", ...)
end
--@DOC_fixed_COMMON@
--@DOC_widget_COMMON@
--@DOC_object_COMMON@

View File

@ -959,6 +959,8 @@ function grid.mt:__call(...)
return new(...)
end
--@DOC_fixed_COMMON@
--@DOC_widget_COMMON@
--@DOC_object_COMMON@

View File

@ -18,21 +18,26 @@ local manual_layout = {}
--- Add some widgets to the given stack layout.
--
-- @method add
-- @param layout The layout you are modifying.
-- @tparam widget ... Widgets that should be added
--- Remove a widget from the layout.
--
-- @method remove
-- @tparam index The widget index to remove
-- @tparam number index The widget index to remove
-- @treturn boolean index If the operation is successful
-- @interface layout
--- Insert a new widget in the layout at position `index`.
--
-- @method insert
-- @tparam number index The position
-- @param widget The widget
-- @treturn boolean If the operation is successful
-- @tparam widget widget The widget
-- @treturn boolean If the operation is successful.
-- @emits widget::inserted
-- @emitstparam widget::inserted widget self The fixed layout.
-- @emitstparam widget::inserted widget widget index The inserted widget.
-- @emitstparam widget::inserted number count The widget count.
-- @interface layout
function manual_layout:insert(index, widget)
table.insert(self._private.widgets, index, widget)
@ -41,6 +46,8 @@ function manual_layout:insert(index, widget)
table.insert(self._private.pos, index, widget.point)
end
self:emit_signal("widget::inserted", widget, #self._private.widgets)
self:emit_signal("widget::layout_changed")
end
@ -50,7 +57,7 @@ end
-- widget(s) to remove.
--
-- @method remove_widgets
-- @param widget ... Widgets that should be removed (must at least be one)
-- @tparam widget ... Widgets that should be removed (must at least be one)
-- @treturn boolean If the operation is successful
@ -177,6 +184,7 @@ function manual_layout:add_at(widget, point)
end
--- Move a widget (by index).
--
-- @method move
-- @tparam number index The widget index.
-- @tparam table|function point A new point value.
@ -219,6 +227,7 @@ function manual_layout:reset()
end
--- Create a manual layout.
--
-- @constructorfct wibox.layout.manual
-- @tparam table ... Widgets to add to the layout.
@ -234,6 +243,7 @@ local function new_manual(...)
return ret
end
--@DOC_fixed_COMMON@
--@DOC_widget_COMMON@

View File

@ -20,8 +20,6 @@ local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility
local ratio = {}
--@DOC_fixed_COMMON@
--- The widget used to fill the spacing between the layout elements.
--
-- By default, no widget is used.
@ -29,7 +27,9 @@ local ratio = {}
--@DOC_wibox_layout_ratio_spacing_widget_EXAMPLE@
--
-- @property spacing_widget
-- @param widget
-- @tparam widget spacing_widget
-- @propemits true false
-- @interface layout
--- Add spacing between each layout widgets.
--
@ -37,6 +37,8 @@ local ratio = {}
--
-- @property spacing
-- @tparam number spacing Spacing between widgets.
-- @propemits true false
-- @interface layout
-- Compute the sum of all ratio (ideally, it should be 1).
local function gen_sum(self, i_s, i_e)
@ -227,7 +229,7 @@ end
-- do nothing.
--
-- @method inc_widget_ratio
-- @param widget The widget to ajust
-- @tparam widget widget The widget to ajust
-- @tparam number increment An floating point value between -1 and 1 where the
-- end result is within 0 and 1
function ratio:inc_widget_ratio(widget, increment)
@ -336,7 +338,7 @@ end
--- Update all widgets to match a set of a ratio.
--
-- @method ajust_widget_ratio
-- @param widget The widget to ajust
-- @tparam widget widget The widget to ajust
-- @tparam number before The sum of the ratio before the widget
-- @tparam number itself The ratio for "widget"
-- @tparam number after The sum of the ratio after the widget
@ -347,9 +349,10 @@ end
--- Add some widgets to the given fixed layout.
--
-- **Signal:** widget::added The argument are the widgets
-- @method add
-- @tparam widget ... Widgets that should be added (must at least be one)
-- @emits widget::added All new widgets are passed in the parameters.
-- @emitstparam widget::added widget self The layout.
function ratio:add(...)
-- No table.pack in Lua 5.1 :-(
local args = { n=select('#', ...), ... }
@ -367,10 +370,13 @@ end
--- Remove a widget from the layout.
--
-- **Signal:** widget::removed The arguments are the widget and the index
-- @method remove
-- @tparam number index The widget index to remove
-- @treturn boolean index If the operation is successful
-- @emits widget::removed
-- @emitstparam widget::removed widget self The fixed layout.
-- @emitstparam widget::removed widget widget index The removed widget.
-- @emitstparam widget::removed number index The removed index.
function ratio:remove(index)
if not index or not self._private.widgets[index] then return false end
@ -388,11 +394,14 @@ function ratio:remove(index)
end
--- Insert a new widget in the layout at position `index`.
-- **Signal:** widget::inserted The arguments are the widget and the index
--
-- @method insert
-- @tparam number index The position
-- @param widget The widget
-- @tparam number index The position.
-- @tparam widget widget The widget.
-- @emits widget::inserted
-- @emitstparam widget::inserted widget self The ratio layout.
-- @emitstparam widget::inserted widget widget index The inserted widget.
-- @emitstparam widget::inserted number count The widget count.
function ratio:insert(index, widget)
if not index or index < 1 or index > #self._private.widgets + 1 then return false end
@ -422,6 +431,7 @@ end
--
-- @property inner_fill_strategy
-- @tparam string inner_fill_strategy One of the value listed above.
-- @propemits true false
function ratio:get_inner_fill_strategy()
return self._private.inner_fill_strategy or "default"
@ -442,6 +452,7 @@ function ratio:set_inner_fill_strategy(strategy)
self._private.inner_fill_strategy = strategy
self:emit_signal("widget::layout_changed")
self:emit_signal("property::inner_fill_strategy", strategy)
end
local function get_layout(dir, widget1, ...)
@ -472,6 +483,8 @@ function ratio.vertical(...)
return get_layout("vertical", ...)
end
--@DOC_fixed_COMMON@
--@DOC_widget_COMMON@
--@DOC_object_COMMON@

View File

@ -22,35 +22,48 @@ local gtable = require("gears.table")
local stack = {mt={}}
--@DOC_fixed_COMMON@
--- Add some widgets to the given stack layout.
-- @param layout The layout you are modifying.
--
-- @tparam widget ... Widgets that should be added (must at least be one)
-- @method add
-- @interface layout
--- Remove a widget from the layout
--- Remove a widget from the layout.
--
-- @tparam index The widget index to remove
-- @treturn boolean index If the operation is successful
-- @method remove
-- @interface layout
--- Insert a new widget in the layout at position `index`.
--
-- @tparam number index The position
-- @param widget The widget
-- @tparam widget widget The widget
-- @treturn boolean If the operation is successful
-- @method insert
-- @emits widget::inserted
-- @emitstparam widget::inserted widget self The fixed layout.
-- @emitstparam widget::inserted widget widget index The inserted widget.
-- @emitstparam widget::inserted number count The widget count.
-- @interface layout
--- Remove one or more widgets from the layout.
--
-- The last parameter can be a boolean, forcing a recursive seach of the
-- widget(s) to remove.
-- @param widget ... Widgets that should be removed (must at least be one)
--
-- @tparam widget widget ... Widgets that should be removed (must at least be one)
-- @treturn boolean If the operation is successful
-- @method remove_widgets
-- @interface layout
--- Add spacing around the widget, similar to the margin container.
--
--@DOC_wibox_layout_stack_spacing_EXAMPLE@
-- @property spacing
-- @tparam number spacing Spacing between widgets.
-- @propemits true false
-- @interface layout
function stack:layout(_, width, height)
local result = {}
@ -83,7 +96,10 @@ function stack:fit(context, orig_width, orig_height)
end
--- If only the first stack widget is drawn.
--
-- @property top_only
-- @tparam boolean top_only
-- @propemits true false
function stack:get_top_only()
return self._private.top_only
@ -91,9 +107,12 @@ end
function stack:set_top_only(top_only)
self._private.top_only = top_only
self:emit_signal("widget::layout_changed")
self:emit_signal("property::top_only", top_only)
end
--- Raise a widget at `index` to the top of the stack.
--
-- @method raise
-- @tparam number index the widget index to raise
function stack:raise(index)
@ -107,8 +126,9 @@ function stack:raise(index)
end
--- Raise the first instance of `widget`.
--
-- @method raise_widget
-- @param widget The widget to raise
-- @tparam widget widget The widget to raise
-- @tparam[opt=false] boolean recursive Also look deeper in the hierarchy to
-- find the widget
function stack:raise_widget(widget, recursive)
@ -134,7 +154,9 @@ end
--@DOC_wibox_layout_stack_offset_EXAMPLE@
--
-- @property horizontal_offset
-- @param number
-- @tparam number horizontal_offset
-- @propemits true false
-- @see vertial_offset
--- Add an vertical offset to each layers.
--
@ -142,20 +164,24 @@ end
-- layers offsets.
--
-- @property vertial_offset
-- @param number
-- @tparam number vertial_offset
-- @propemits true false
-- @see horizontal_offset
function stack:set_horizontal_offset(value)
self._private.h_offset = value
self:emit_signal("widget::layout_changed")
self:emit_signal("widget::horizontal_offset")
self:emit_signal("property::top_only", value)
end
function stack:set_vertical_offset(value)
self._private.v_offset = value
self:emit_signal("widget::layout_changed")
self:emit_signal("property::vertical_offset", value)
end
--- Create a new stack layout.
--
-- @constructorfct wibox.layout.stack
-- @treturn widget A new stack layout
@ -174,6 +200,8 @@ function stack.mt:__call(_, ...)
return new(...)
end
--@DOC_fixed_COMMON@
--@DOC_widget_COMMON@
--@DOC_object_COMMON@