Yast UI
YSpacing Class Reference

Fixed size empty space for layoutOptional Argument: integer|float size Example: More...

Detailed Description

Fixed size empty space for layout

Optional Argument: integer|float size Example:

Following widget variants exist: HSpacing VSpacing HStretch VStretch Id of widget: Spacing

# encoding: utf-8
module Yast
class Spacing1Client < Client
def main
Yast.import "UI"
# Build dialog with one input field field, 4 Beatles buttons and an OK button.
UI.OpenDialog(
VBox(
VSpacing(),
HBox(Label("Name:"), InputField(Id(:name), "")),
VSpacing(0.2),
HBox(
PushButton(Id(:john), "&John"),
HSpacing(0.5),
PushButton(Id(:paul), "&Paul"),
HSpacing(3),
PushButton(Id(:george), "&George"),
HSpacing(0.5),
PushButton(Id(:ringo), "&Ringo")
),
VSpacing(0.5),
PushButton(Id(:ok), "&OK")
)
)
# Wait for user input.
@button = nil
begin
@button = UI.UserInput
if @button == :john
UI.ChangeWidget(Id(:name), :Value, "John Lennon")
elsif @button == :paul
UI.ChangeWidget(Id(:name), :Value, "Paul McCartney")
elsif @button == :george
UI.ChangeWidget(Id(:name), :Value, "George Harrison")
elsif @button == :ringo
UI.ChangeWidget(Id(:name), :Value, "Ringo Starr")
end
end until @button == :ok
UI.CloseDialog
nil
end
end
end
Yast::Spacing1Client.new.main

Example:

# encoding: utf-8
module Yast
class LayoutButtonsEqualEvenSpaced2Client < Client
def main
Yast.import "UI"
# Layout example:
#
# Build a dialog with three equal sized buttons,
# this time with some spacing in between.
#
# The equal `HWeight()s will make the buttons even sized.
# When resized larger, all buttons will retain their size.
# Excess space will go to the HSpacing() widgets between the
# buttons, i.e. there will be empty space between the buttons.
#
# Notice the importance of `opt(`hstretch) for the `HSpacing()s
# here: This is what makes the HSpacing()s grow. Otherwise, they
# would retain a constant size, and the buttons would grow.
UI.OpenDialog(
HBox(
HWeight(1, PushButton(Opt(:default), "&OK")),
HSpacing(Opt(:hstretch), 3),
HWeight(1, PushButton("&Cancel everything")),
HSpacing(Opt(:hstretch), 3),
HWeight(1, PushButton("&Help"))
)
)
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::LayoutButtonsEqualEvenSpaced2Client.new.main

Example:

# encoding: utf-8
module Yast
class HStretch1Client < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
Label("Some text goes here"),
Label("This is some more text, that is quite long, as you can see."),
HBox(PushButton("&OK"), HStretch())
)
)
@ret = UI.UserInput
UI.CloseDialog
deep_copy(@ret)
end
end
end
Yast::HStretch1Client.new.main

Example:

# encoding: utf-8
module Yast
class LayoutButtonsEqualEvenSpaced1Client < Client
def main
Yast.import "UI"
# Layout example:
#
# Build a dialog with three equal sized buttons.
#
# The equal `HWeight()s will make the buttons equal sized.
# When resized larger, all buttons will retain their size.
# Excess space will go to the HStretch() widgets between the
# buttons, i.e. there will be empty space between the buttons.
UI.OpenDialog(
HBox(
HWeight(1, PushButton(Opt(:default), "&OK")),
HStretch(),
HWeight(1, PushButton("&Cancel everything")),
HStretch(),
HWeight(1, PushButton("&Help"))
)
)
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::LayoutButtonsEqualEvenSpaced1Client.new.main

Example:

# encoding: utf-8
module Yast
class Table2Client < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
Heading("Today's menu"),
MinSize(
30,
7,
Table(
Id(:table),
Opt(:keepSorting),
Header("Name", Right("Price"), Center("Rating")),
[
Item(Id(0), "Steak Sandwich", 12, "+++"),
Item(Id(1), "Salami Baguette", nil, "-"),
Item(Id(2), "Chili", 6, "--"),
Item(Id(3), "Spaghetti", 8, "+")
]
)
),
Right(
HBox(
PushButton(Id(:next), "&Next"),
PushButton(Id(:cancel), "&Close")
)
)
)
)
UI.ChangeWidget(Id(:table), :CurrentItem, 2)
while UI.UserInput != :cancel
UI.ChangeWidget(
Id(:table),
:CurrentItem,
Ops.modulo(
Ops.add(
Convert.to_integer(UI.QueryWidget(Id(:table), :CurrentItem)),
1
),
4
)
)
end
UI.CloseDialog
nil
end
end
end
Yast::Table2Client.new.main

Example:

# encoding: utf-8
# Table example: Exchange complete table content
module Yast
class Table3Client < Client
def main
Yast.import "UI"
@foodItems = [
Item(Id(3), "Spaghetti", 8),
Item(Id(4), "Steak Sandwich", 12),
Item(Id(1), "Chili", 6),
Item(Id(2), "Salami Baguette", nil)
]
@carItems = [
Item(Id(0), "Mercedes", 60000),
Item(Id(1), "Audi", 50000),
Item(Id(2), "VW", 40000),
Item(Id(3), "BMW", 60000),
Item(Id(3), "Porsche", 80000)
]
@itemLists = [@foodItems, @carItems]
@listNo = 0
UI.OpenDialog(
VBox(
Heading("Prices"),
MinSize(
30,
10,
Table(Id(:table), Header("Name", "Price"), @foodItems)
),
Right(
HBox(
PushButton(Id(:next), "Change &Table Contents"),
PushButton(Id(:cancel), "&Close")
)
)
)
)
while UI.UserInput != :cancel
# Change table contents
@listNo = Ops.subtract(1, @listNo)
UI.ChangeWidget(:table, :Items, Ops.get(@itemLists, @listNo))
# Double check: Retrieve contents and dump to log
Builtins.y2milestone(
"New table content:\n%1",
UI.QueryWidget(:table, :Items)
)
end
UI.CloseDialog
nil
end
end
end
Yast::Table3Client.new.main

HSpacing and VSpacing are layout helpers to add empty space between widgets.

VStretch and HStretch act as "rubber bands" in layouts that take excess space. They have a size of zero if there is no excess space.

The size given is measured in units roughly equivalent to the size of a character in the respective UI. Fractional numbers can be used here, but text based UIs may choose to round the number as appropriate - even if this means simply ignoring a spacing when its size becomes zero.

If size is omitted, it defaults to 1. HSpacing() will create a horizontal spacing with default width and zero height. VSpacing() will create a vertical spacing with default height and zero width. HStretch() will create a horizontal stretch with zero width and height. VStretch() will create a vertical stretch with zero width and height.

A HStretch or VStretch with a size specification will take at least the specified amount of space, but it will take more (in that dimension) if there is excess space in the layout.


The documentation for this class was generated from the following file: