Tune contact bubble button insets

This commit is contained in:
Ilya Laktyushin 2024-01-28 23:30:03 +04:00
parent 0f48db9349
commit 089ef27b69
5 changed files with 9 additions and 8 deletions

View File

@ -83,13 +83,13 @@ public final class ChatMessageAttachedContentButtonNode: HighlightTrackingButton
}) })
} }
public typealias AsyncLayout = (_ width: CGFloat, _ iconImage: UIImage?, _ cornerIcon: Bool, _ title: String, _ titleColor: UIColor, _ inProgress: Bool, _ drawBackground: Bool) -> (CGFloat, (CGFloat, CGFloat) -> (CGSize, (ListViewItemUpdateAnimation) -> ChatMessageAttachedContentButtonNode)) public typealias AsyncLayout = (_ width: CGFloat, _ sideInset: CGFloat?, _ iconImage: UIImage?, _ cornerIcon: Bool, _ title: String, _ titleColor: UIColor, _ inProgress: Bool, _ drawBackground: Bool) -> (CGFloat, (CGFloat, CGFloat) -> (CGSize, (ListViewItemUpdateAnimation) -> ChatMessageAttachedContentButtonNode))
public static func asyncLayout(_ current: ChatMessageAttachedContentButtonNode?) -> AsyncLayout { public static func asyncLayout(_ current: ChatMessageAttachedContentButtonNode?) -> AsyncLayout {
let previousRegularIconImage = current?.regularIconImage let previousRegularIconImage = current?.regularIconImage
let maybeMakeTextLayout = (current?.textNode).flatMap(TextNode.asyncLayout) let maybeMakeTextLayout = (current?.textNode).flatMap(TextNode.asyncLayout)
return { width, iconImage, cornerIcon, title, titleColor, inProgress, drawBackground in return { width, sideInset, iconImage, cornerIcon, title, titleColor, inProgress, drawBackground in
let targetNode: ChatMessageAttachedContentButtonNode let targetNode: ChatMessageAttachedContentButtonNode
if let current = current { if let current = current {
targetNode = current targetNode = current
@ -114,7 +114,7 @@ public final class ChatMessageAttachedContentButtonNode: HighlightTrackingButton
iconWidth = iconImage.size.width + 5.0 iconWidth = iconImage.size.width + 5.0
} }
let labelInset: CGFloat = 8.0 let labelInset: CGFloat = sideInset ?? 8.0
let (textSize, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: title, font: buttonFont, textColor: titleColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(1.0, width - labelInset * 2.0 - iconWidth), height: CGFloat.greatestFiniteMagnitude), alignment: .left, cutout: nil, insets: UIEdgeInsets())) let (textSize, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: title, font: buttonFont, textColor: titleColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(1.0, width - labelInset * 2.0 - iconWidth), height: CGFloat.greatestFiniteMagnitude), alignment: .left, cutout: nil, insets: UIEdgeInsets()))
@ -146,7 +146,7 @@ public final class ChatMessageAttachedContentButtonNode: HighlightTrackingButton
let backgroundFrame = CGRect(origin: CGPoint(), size: CGSize(width: refinedWidth, height: size.height)) let backgroundFrame = CGRect(origin: CGPoint(), size: CGSize(width: refinedWidth, height: size.height))
var textFrame = CGRect(origin: CGPoint(x: floor((refinedWidth - textSize.size.width) / 2.0), y: floor((backgroundFrame.height - textSize.size.height) / 2.0)), size: textSize.size) var textFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((refinedWidth - textSize.size.width) / 2.0), y: floorToScreenPixels((backgroundFrame.height - textSize.size.height) / 2.0)), size: textSize.size)
if drawBackground { if drawBackground {
textFrame.origin.y += 1.0 textFrame.origin.y += 1.0
} }

View File

@ -555,6 +555,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
let (buttonWidth, continueLayout) = makeActionButtonLayout( let (buttonWidth, continueLayout) = makeActionButtonLayout(
maxContentsWidth, maxContentsWidth,
nil
buttonIconImage, buttonIconImage,
cornerIcon, cornerIcon,
actionTitle, actionTitle,

View File

@ -306,7 +306,7 @@ public class ChatMessageContactBubbleContentNode: ChatMessageBubbleContentNode {
avatarPlaceholderColor = item.presentationData.theme.theme.chat.message.outgoing.mediaPlaceholderColor avatarPlaceholderColor = item.presentationData.theme.theme.chat.message.outgoing.mediaPlaceholderColor
} }
let (messageButtonWidth, messageContinueLayout) = makeMessageButtonLayout(constrainedSize.width, nil, false, item.presentationData.strings.Conversation_ContactMessage.uppercased(), mainColor, false, false) let (messageButtonWidth, messageContinueLayout) = makeMessageButtonLayout(constrainedSize.width, 10.0, nil, false, item.presentationData.strings.Conversation_ContactMessage.uppercased(), mainColor, false, false)
let addTitle: String let addTitle: String
if !canMessage && !canAdd { if !canMessage && !canAdd {
@ -318,7 +318,7 @@ public class ChatMessageContactBubbleContentNode: ChatMessageBubbleContentNode {
addTitle = item.presentationData.strings.Conversation_ContactAddContactLong addTitle = item.presentationData.strings.Conversation_ContactAddContactLong
} }
} }
let (addButtonWidth, addContinueLayout) = makeAddButtonLayout(constrainedSize.width, nil, false, addTitle.uppercased(), mainColor, false, false) let (addButtonWidth, addContinueLayout) = makeAddButtonLayout(constrainedSize.width, 10.0, nil, false, addTitle.uppercased(), mainColor, false, false)
let maxButtonWidth = max(messageButtonWidth, addButtonWidth) let maxButtonWidth = max(messageButtonWidth, addButtonWidth)
var maxContentWidth: CGFloat = avatarSize.width + 7.0 var maxContentWidth: CGFloat = avatarSize.width + 7.0

View File

@ -536,7 +536,7 @@ public class ChatMessageGiveawayBubbleContentNode: ChatMessageBubbleContentNode,
titleColor = item.presentationData.theme.theme.chat.message.outgoing.accentTextColor titleColor = item.presentationData.theme.theme.chat.message.outgoing.accentTextColor
} }
let (buttonWidth, continueLayout) = makeButtonLayout(constrainedSize.width, nil, false, item.presentationData.strings.Chat_Giveaway_Message_LearnMore.uppercased(), titleColor, false, true) let (buttonWidth, continueLayout) = makeButtonLayout(constrainedSize.width, nil, nil, false, item.presentationData.strings.Chat_Giveaway_Message_LearnMore.uppercased(), titleColor, false, true)
let animationName: String let animationName: String
let months = giveaway?.months ?? 0 let months = giveaway?.months ?? 0

View File

@ -48,7 +48,7 @@ public final class ChatMessageUnsupportedBubbleContentNode: ChatMessageBubbleCon
} else { } else {
titleColor = presentationData.theme.theme.chat.message.outgoing.accentTextColor titleColor = presentationData.theme.theme.chat.message.outgoing.accentTextColor
} }
let (buttonWidth, continueActionButtonLayout) = makeButtonLayout(constrainedSize.width, nil, false, presentationData.strings.Conversation_UpdateTelegram, titleColor, false, true) let (buttonWidth, continueActionButtonLayout) = makeButtonLayout(constrainedSize.width, nil, nil, false, presentationData.strings.Conversation_UpdateTelegram, titleColor, false, true)
let initialWidth = buttonWidth + insets.left + insets.right let initialWidth = buttonWidth + insets.left + insets.right