Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
b7af6567
Verified
Commit
b7af6567
authored
Aug 30, 2023
by
Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
Add item bullets as texts instead of using annotations
parent
0055f1d0
No related branches found
No related tags found
1 merge request
!366
Add support for HTML blog posts
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt
+12
-41
12 additions, 41 deletions
...in/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt
with
12 additions
and
41 deletions
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt
+
12
−
41
View file @
b7af6567
...
...
@@ -19,6 +19,7 @@
package
org.briarproject.briar.desktop.blog
import
androidx.compose.foundation.text.ClickableText
import
androidx.compose.foundation.text.selection.SelectionContainer
import
androidx.compose.material.MaterialTheme
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.getValue
...
...
@@ -27,7 +28,6 @@ import androidx.compose.runtime.remember
import
androidx.compose.runtime.setValue
import
androidx.compose.ui.Modifier
import
androidx.compose.ui.draw.drawBehind
import
androidx.compose.ui.geometry.Offset
import
androidx.compose.ui.geometry.Rect
import
androidx.compose.ui.graphics.Color
import
androidx.compose.ui.graphics.drawscope.DrawScope
...
...
@@ -36,10 +36,8 @@ import androidx.compose.ui.text.ExperimentalTextApi
import
androidx.compose.ui.text.ParagraphStyle
import
androidx.compose.ui.text.SpanStyle
import
androidx.compose.ui.text.buildAnnotatedString
import
androidx.compose.ui.text.drawText
import
androidx.compose.ui.text.font.FontStyle
import
androidx.compose.ui.text.font.FontWeight
import
androidx.compose.ui.text.rememberTextMeasurer
import
androidx.compose.ui.text.style.BaselineShift
import
androidx.compose.ui.text.style.TextDecoration
import
androidx.compose.ui.text.style.TextIndent
...
...
@@ -88,10 +86,12 @@ fun main() = preview {
</ul>
"""
.
trimIndent
()
SelectionContainer
{
HtmlText
(
testHtml
)
{
println
(
it
)
}
}
}
// This file is adapted from https://github.com/jeremyrempel/yahnapp (HtmlText.kt)
...
...
@@ -100,6 +100,12 @@ enum class ListType {
UNORDERED
}
val
listBullets
=
listOf
(
"\u2022"
,
"\u25e6"
,
"\u25aa"
,
)
@OptIn
(
ExperimentalTextApi
::
class
)
@Composable
@Suppress
(
"HardCodedStringLiteral"
)
...
...
@@ -263,6 +269,7 @@ fun HtmlText(
fun
startBullet
()
{
check
(
listNesting
.
isNotEmpty
())
{
"<li> outside of list"
}
appendAndUpdateCursor
(
listBullets
[
listNesting
.
size
]
+
" "
)
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
}
...
...
@@ -347,17 +354,6 @@ fun HtmlText(
}
}
val
textMeasurer
=
rememberTextMeasurer
()
// todo: doesn't respect actual text size, but also cannot be changed currently
val
listBullets
=
remember
{
listOf
(
textMeasurer
.
measure
(
"\u2022"
),
textMeasurer
.
measure
(
"\u25e6"
),
textMeasurer
.
measure
(
"\u25aa"
),
)
}
val
color
=
MaterialTheme
.
colors
.
onSurface
var
onDraw
:
DrawScope
.()
->
Unit
by
remember
{
mutableStateOf
({})
}
ClickableText
(
...
...
@@ -386,20 +382,6 @@ fun HtmlText(
)
}
data class
BulletInfo
(
val
rect
:
Rect
,
val
nestingLevel
:
Int
)
val
bullets
=
formattedString
.
getStringAnnotations
(
"bullet"
).
map
{
val
line
=
layoutResult
.
getLineForOffset
(
it
.
start
)
BulletInfo
(
rect
=
Rect
(
top
=
layoutResult
.
getLineTop
(
line
),
bottom
=
layoutResult
.
getLineBottom
(
line
),
left
=
layoutResult
.
getLineLeft
(
line
),
right
=
layoutResult
.
getLineLeft
(
line
)
),
nestingLevel
=
it
.
item
.
toInt
()
)
}
onDraw
=
{
quotes
.
forEach
{
val
line
=
it
.
copy
(
left
=
it
.
left
+
10
.
dp
.
toPx
(),
right
=
it
.
right
+
11
.
dp
.
toPx
())
...
...
@@ -409,17 +391,6 @@ fun HtmlText(
size
=
line
.
size
,
)
}
bullets
.
forEach
{
val
bullet
=
listBullets
[
it
.
nestingLevel
%
listBullets
.
size
]
drawText
(
textLayoutResult
=
bullet
,
color
=
color
,
topLeft
=
Offset
(
it
.
rect
.
left
-
10
.
dp
.
toPx
()
-
bullet
.
size
.
width
/
2
,
it
.
rect
.
center
.
y
-
bullet
.
size
.
height
/
2
,
),
)
}
}
}
)
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment