commit 8d0aea22fd4a1276a64e3a98f3c3b2c8fab195ac
parent 3d27e49e702c0b6832161ac257c9d7e3d82efd30
Author: William Casarin <jb55@jb55.com>
Date: Thu, 6 Apr 2023 17:28:43 -0700
Custom hashtag offsets
This allows you to tweak the positioning a bit
Diffstat:
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/bitcoin-hashtag.svg b/damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/bitcoin-hashtag.svg
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
- width="13.599426"
- height="18"
- viewBox="0 0 13.599426 17.999999"
+ width="12.843903"
+ height="17"
+ viewBox="0 0 12.843902 16.999999"
version="1.1"
id="svg2"
sodipodi:docname="bitcoin-hashtag.svg"
@@ -24,17 +24,17 @@
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="31.12"
- inkscape:cx="4.2255784"
- inkscape:cy="7.5032134"
+ inkscape:cx="4.2577121"
+ inkscape:cy="7.535347"
inkscape:window-width="1526"
inkscape:window-height="957"
inkscape:window-x="1637"
- inkscape:window-y="38"
+ inkscape:window-y="10"
inkscape:window-maximized="0"
inkscape:current-layer="svg2" />
<g
id="surface1"
- transform="translate(-4.867188,-3.484375)">
+ transform="matrix(0.94507527,0,0,0.94507527,-4.5943665,-3.2875042)">
<path
style="fill:#f59119;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.40637"
d="M 18.388175,10.742602 C 18.668352,8.874761 17.240002,7.8694225 15.295251,7.193703 L 15.927019,4.6611305 14.383304,4.2765743 13.768015,6.7432244 C 13.361486,6.644338 12.943967,6.545453 12.531944,6.4520613 L 13.152726,3.9689298 11.609011,3.584375 10.977241,6.1169476 C 10.642129,6.0400371 10.312509,5.9686201 9.988384,5.886215 L 9.993834,5.880715 7.8623408,5.3478364 7.4558114,6.9959316 c 0,0 1.1426793,0.2636953 1.1207046,0.2801765 0.6207823,0.1538223 0.7361485,0.5658464 0.714174,0.8954659 l -0.7196673,2.889659 c 0.043949,0.01099 0.098885,0.02747 0.1648089,0.04944 L 8.5710227,11.072223 7.5601911,15.11555 c -0.076912,0.192277 -0.26919,0.477948 -0.7031873,0.368073 0.010984,0.02198 -1.1261994,-0.280174 -1.1261994,-0.280174 l -0.7636164,1.76346 2.0106754,0.505417 c 0.3735682,0.0934 0.7361485,0.186784 1.0987301,0.280176 l -0.6427568,2.565534 1.5437155,0.384556 0.6317701,-2.538067 c 0.4230107,0.115364 0.8295407,0.219746 1.2305777,0.318632 l -0.63177,2.527079 1.543716,0.384557 0.637263,-2.560042 c 2.631459,0.499922 4.614667,0.296656 5.444208,-2.082094 0.670226,-1.917284 -0.03296,-3.021507 -1.417363,-3.741176 1.010832,-0.236227 1.768957,-0.895465 1.972221,-2.268877 z m -3.526922,4.944286 c -0.477949,1.917283 -3.702721,0.884477 -4.752008,0.620782 l 0.851514,-3.395075 c 1.043795,0.2582 4.394922,0.774604 3.900494,2.774293 z M 15.3392,10.715134 c -0.433999,1.74698 -3.120394,0.857008 -3.993884,0.642757 l 0.769111,-3.081939 c 0.87349,0.219746 3.675252,0.620784 3.224773,2.439182 z m 0,0"
diff --git a/damus/Util/Hashtags.swift b/damus/Util/Hashtags.swift
@@ -10,16 +10,18 @@ import SwiftUI
struct CustomHashtag {
let name: String
+ let offset: CGFloat?
let color: Color?
- init(name: String, color: Color? = nil) {
+ init(name: String, color: Color? = nil, offset: CGFloat? = nil) {
self.name = name
self.color = color
+ self.offset = offset
}
- static let coffee = CustomHashtag(name: "coffee", color: DamusColors.brown)
- static let bitcoin = CustomHashtag(name: "bitcoin", color: Color.orange)
- static let nostr = CustomHashtag(name: "nostr", color: DamusColors.purple)
+ static let coffee = CustomHashtag(name: "coffee", color: DamusColors.brown, offset: -1.0)
+ static let bitcoin = CustomHashtag(name: "bitcoin", color: Color.orange, offset: -3.0)
+ static let nostr = CustomHashtag(name: "nostr", color: DamusColors.purple, offset: -2.0)
}
@@ -44,13 +46,13 @@ func hashtag_str(_ htag: String) -> CompatibleText {
let name = custom_hashtag.name
- text = Text(attributedString)
if let img = UIImage(named: "\(name)-hashtag") {
attributedString = attributedString + " "
attributed_string_attach_icon(&attributedString, img: img)
}
+ text = Text(attributedString)
let img = Image("\(name)-hashtag")
- text = text + Text(" \(img)")
+ text = text + Text("\(img)").baselineOffset(custom_hashtag.offset ?? 0.0)
} else {
attributedString.foregroundColor = DamusColors.purple
}