doc: Add many textbox examples.

This commit is contained in:
Emmanuel Lepage Vallee 2021-10-30 22:44:58 -07:00
parent c5f81d4aab
commit 1fa0204d80
11 changed files with 368 additions and 10 deletions

View File

@ -1,4 +1,5 @@
---------------------------------------------------------------------------
-- A widget to display either plain or HTML text.
--
--@DOC_wibox_widget_defaults_textbox_EXAMPLE@
--
@ -177,11 +178,23 @@ function textbox:set_markup_silently(text)
return true
end
--- Set the text of the textbox (with
-- [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)).
--- Set the HTML text of the textbox.
--
-- The main difference between `text` and `markup` is that `markup` is
-- able to render a small subset of HTML tags. See the
-- [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)) documentation
-- to see what is and isn't valid in this property.
--
-- @DOC_wibox_widget_textbox_markup1_EXAMPLE@
--
-- The `wibox.widget.textbox` colors are usually set by wrapping into a
-- `wibox.container.background` widget, but can also be done using the
-- markup:
--
-- @DOC_wibox_widget_textbox_markup2_EXAMPLE@
--
-- @property markup
-- @tparam string text The text to set. This can contain pango markup (e.g.
-- @tparam string markup The text to set. This can contain pango markup (e.g.
-- `<b>bold</b>`). You can use `gears.string.escape` to escape
-- parts of it.
-- @propemits true false
@ -198,7 +211,15 @@ function textbox:get_markup()
return self._private.markup
end
--- Set a textbox text.
--- Set a textbox plain text.
--
-- This property renders the text as-is, it does not interpret it:
--
-- @DOC_wibox_widget_textbox_text1_EXAMPLE@
--
-- One exception are the control characters, which are interpreted:
--
-- @DOC_wibox_widget_textbox_text2_EXAMPLE@
--
-- @property text
-- @tparam string text The text to display. Pango markup is ignored and shown
@ -237,7 +258,7 @@ end
--@DOC_wibox_widget_textbox_ellipsize_EXAMPLE@
--
-- @property ellipsize
-- @tparam string mode The ellipsize mode.
-- @tparam[opt="end"] string mode The ellipsize mode.
-- @propemits true false
function textbox:set_ellipsize(mode)
@ -261,8 +282,10 @@ end
-- * **char**
-- * **word_char**
--
-- @DOC_wibox_widget_textbox_wrap1_EXAMPLE@
--
-- @property wrap
-- @tparam string mode Where to wrap? After "word", "char" or "word_char".
-- @tparam[opt="word_char"] string mode Where to wrap? After "word", "char" or "word_char".
-- @propemits true false
function textbox:set_wrap(mode)
@ -286,8 +309,10 @@ end
-- * **center**
-- * **bottom**
--
--@DOC_wibox_widget_textbox_valign1_EXAMPLE@
--
-- @property valign
-- @tparam string mode Where should the textbox be drawn? "top", "center" or
-- @tparam[opt="center"] string mode Where should the textbox be drawn? "top", "center" or
-- "bottom".
-- @propemits true false
@ -312,8 +337,10 @@ end
-- * **center**
-- * **right**
--
--@DOC_wibox_widget_textbox_align1_EXAMPLE@
--
-- @property align
-- @tparam string mode Where should the textbox be drawn? "left", "center" or
-- @tparam[opt="left"] string mode Where should the textbox be drawn? "left", "center" or
-- "right".
-- @propemits true false
@ -363,10 +390,18 @@ end
--
-- In this case, the font could be `Sans 10` or `Sans Bold Italic 10`.
--
-- Here are examples of several font families:
--
--@DOC_wibox_widget_textbox_font1_EXAMPLE@
--
-- The font size is a number at the end of the font description string:
--
--@DOC_wibox_widget_textbox_font2_EXAMPLE@
--
-- @property font
-- @tparam string font The font description as string.
-- @tparam[opt=beautiful.font] string font The font description as string.
-- @propemits true false
-- @propbeautiful
-- @usebeautiful beautiful.font The default font.
function textbox:set_font(font)
if font == self._private.font then return end
@ -379,6 +414,10 @@ function textbox:set_font(font)
self:emit_signal("property::font", font)
end
function textbox:get_font()
return self._private.font
end
--- Create a new textbox.
--
-- @tparam[opt=""] string text The textbox content

View File

@ -0,0 +1,43 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
local ret = wibox.layout.fixed.vertical()
--DOC_HIDE_END
for _, align in ipairs {"left", "center", "right"} do
local w = wibox.widget {
align = align,
text = "some text",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
ret:add(
wibox.widget {
markup = "Alignement: <b>" .. align .."</b>",
widget = wibox.widget.textbox
},
wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
widget = wibox.container.margin,
},
{
forced_height = 10,
widget = wibox.widget.base.make_widget()
}
)
--DOC_HIDE_END
end
--DOC_HIDE_START
l:add(ret)
return 200, nil
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,61 @@
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE --DOC_GEN_OUTPUT
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
--DOC_HIDE_END
local pango = require("lgi").Pango
--DOC_HIDE_START
local ret = wibox.layout.fixed.vertical()
--DOC_HIDE_END
local fonts = {
"sans",
"Roboto, Bold",
"DejaVu Sans, Oblique",
"Noto Mono, Regular"
}
--DOC_NEWLINE
for _, font in ipairs(fonts) do
local w = wibox.widget {
font = font,
text = "The quick brown fox jumps over the lazy dog!",
widget = wibox.widget.textbox,
}
--DOC_NEWLINE
-- Use the low level Pango API to validate the font was parsed properly.
local desc = pango.FontDescription.from_string(w.font)
print(w.font, desc:get_size(), desc:get_family(), desc:get_variant(), desc:get_style())
--DOC_HIDE_START
assert(w._private.font == font)
ret:add(
wibox.widget {
markup = "Font: <b>" .. font .."</b>",
widget = wibox.widget.textbox
},
wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
forced_width = 500,
widget = wibox.container.margin,
},
{
forced_height = 10,
widget = wibox.widget.base.make_widget()
}
)
--DOC_HIDE_END
end
--DOC_HIDE_START
l:add(ret)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,4 @@
sans 0.0 sans NORMAL NORMAL
Roboto, Bold 0.0 Roboto NORMAL NORMAL
DejaVu Sans, Oblique 0.0 DejaVu Sans NORMAL OBLIQUE
Noto Mono, Regular 0.0 Noto Mono NORMAL NORMAL

View File

@ -0,0 +1,43 @@
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
local ret = wibox.layout.fixed.vertical()
--DOC_HIDE_END
for _, font in ipairs { "sans 8", "sans 10", "sans 12", "sans 14" } do
local w = wibox.widget {
font = font,
text = "The quick brown fox jumps over the lazy dog!",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
ret:add(
wibox.widget {
markup = "Font: <b>" .. font .."</b>",
widget = wibox.widget.textbox
},
wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
forced_width = 500,
widget = wibox.container.margin,
},
{
forced_height = 10,
widget = wibox.widget.base.make_widget()
}
)
--DOC_HIDE_END
end
--DOC_HIDE_START
l:add(ret)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,20 @@
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
--DOC_HIDE_END
local w = wibox.widget {
markup = "This is some <i>text</i>, <b>HTML tags</b> <u>WILL</u> work.",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
l:add(wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
widget = wibox.container.margin,
})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,21 @@
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
--DOC_HIDE_END
local w = wibox.widget {
markup = "<span background='#ff0000' foreground='#0000ff'>Some</span>"..
" nice <span foreground='#00ff00'>colors!</span>",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
l:add(wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
widget = wibox.container.margin,
})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,20 @@
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
--DOC_HIDE_END
local w = wibox.widget {
text = "This is some <i>text</i>, <b>HTML tags</b> will <u>NOT</u> work.",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
l:add(wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
widget = wibox.container.margin,
})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,21 @@
--DOC_GEN_IMAGE --DOC_HIDE_START --DOC_NO_USAGE
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
--DOC_HIDE_END
local w = wibox.widget {
text = "This is some text\nover\nmultiple lines!",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
l:add(wibox.widget{
w,
margins = 1,
forced_height = 60,
color = beautiful.bg_normal,
widget = wibox.container.margin,
})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,44 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
local ret = wibox.layout.fixed.vertical()
--DOC_HIDE_END
for _, valign in ipairs {"top", "center", "bottom"} do
local w = wibox.widget {
valign = valign,
text = "some text",
widget = wibox.widget.textbox,
forced_height = 50, --DOC_HIDE
}
--DOC_HIDE_START
ret:add(
wibox.widget {
markup = "Alignement: <b>" .. valign .."</b>",
widget = wibox.widget.textbox
},
wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
widget = wibox.container.margin,
},
{
forced_height = 10,
widget = wibox.widget.base.make_widget()
}
)
--DOC_HIDE_END
end
--DOC_HIDE_START
l:add(ret)
return 200, nil
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,42 @@
--DOC_GEN_IMAGE --DOC_HIDE_START
local l = ...
local wibox = require("wibox")
local beautiful = require("beautiful")
local ret = wibox.layout.fixed.vertical()
--DOC_HIDE_END
for _, wrap in ipairs {"word", "char", "word_char"} do
local w = wibox.widget {
wrap = wrap,
text = "Notable dinausors: Tyrannosaurus-Rex, Triceratops, Velociraptor, Sauropods, Archaeopteryx.",
widget = wibox.widget.textbox,
}
--DOC_HIDE_START
ret:add(
wibox.widget {
markup = "Wrap: <b>" .. wrap .."</b>",
widget = wibox.widget.textbox
},
wibox.widget{
w,
margins = 1,
color = beautiful.bg_normal,
forced_width = 85,
forced_height = 70,
widget = wibox.container.margin,
},
{
forced_height = 10,
widget = wibox.widget.base.make_widget()
}
)
--DOC_HIDE_END
end
--DOC_HIDE_START
l:add(ret)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80