Skip to content

Commit

Permalink
add autowrapping to Yast2::Popup class
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 8, 2020
1 parent f7e1172 commit db877be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions library/general/example/popup_serie.rb
Expand Up @@ -4,6 +4,8 @@

Yast2::Popup.show("Simple text")

Yast2::Popup.show("First paragraph.\n\n" + "Long text without newlines. " * 50)

Yast2::Popup.show("Long text\n" * 50)

Yast2::Popup.show("Simple text with details", details: "More details here")
Expand Down
7 changes: 6 additions & 1 deletion library/general/src/lib/yast2/popup.rb
Expand Up @@ -23,6 +23,10 @@ class << self
RICHTEXT_WIDTH = 60
RICHTEXT_HEIGHT = 10

# Minimum width for auto wrapped labels. It is computed that max line or this
# value is used to ensure that it is reasonable wrapped.
LABEL_MINWIDTH = 60

# Show a popup, wait for a button press (or a timeout), return the button ID.
# @param message [String] message to show. The only mandatory argument.
# @param details [String] details that will be shown in another popup
Expand Down Expand Up @@ -175,7 +179,8 @@ def message_widget(message, richtext)
elsif message.lines.size >= LINES_THRESHOLD
message_widget(plain_to_richtext(message), true)
else
Left(Label(message))
width = [LABEL_MINWIDTH, message.lines.map(&:size).max].min
MinWidth(width, Left(Label(Opt(:autoWrap), message)))
end
end

Expand Down

0 comments on commit db877be

Please sign in to comment.