Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make session grid item title font size variable #563

Merged

Conversation

shxun6934
Copy link
Contributor

@shxun6934 shxun6934 commented Aug 16, 2023

Issue

Overview (Required)

  • Added support for changing the title of the session displayed in the grid.

Links

Screenshot

en

Before After
Screen_recording_20230817_235512.mp4
Screen_recording_20230818_000041.mp4

ja

Before After
Screen_recording_20230817_235624.mp4
Screen_recording_20230817_235837.mp4

@shxun6934 shxun6934 changed the title Align Session Heights in Timetable Grid Display According to Time Duration Fixed FontSize by Session Grid Item Title Aug 16, 2023
@shxun6934 shxun6934 changed the title Fixed FontSize by Session Grid Item Title Make session grid item title font size variable Aug 16, 2023
val actualTitleHeight = rows * fontSizePx

val oneLine = 1
val minFontSize = 8.sp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Help]

We really have to calculate the appropriate size according to the session title length.

However, since the logic did not come to mind, a fixed minimum value is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to assemble a similar logic, but there is room for improvement.

84578b6

@github-actions
Copy link

Hi @shxun6934! Codes seem to be unformatted. To resolve this issue, please run ./gradlew spotlessKotlinApply and fix the results of ./gradlew lintDebug.. Thank you for your contribution.

@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Test Results

109 tests   109 ✔️  3m 47s ⏱️
    8 suites      0 💤
    8 files        0

Results for commit 5bfb94f.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Aug 16, 2023

Snapshot diff report

File name Image
TimetableScreenTest.
checkGridShot_compar
e.png
TimetableScreenTest.
checkGridScrollShot_
compare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-DarkMode-3
_4_null_5_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_PreviewTimet
ableItemDetailSummar
y-English-4_7_null_c
ompare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-DarkMode-3
_4_null_2_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-DarkMode-3
_4_null_3_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.section_null_Lan
guage_TimetablePrevi
ew-English-6_9_null_
compare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_PreviewTimet
ableGridLongTitleIte
m-English-2_5_null_c
ompare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-LightMode-
3_3_null_5_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-LightMode-
3_3_null_2_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-DarkMode-3
_4_null_0_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.section_null_The
me_TimetablePreview-
DarkMode-6_7_null_co
mpare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_PreviewTimet
ableItemDetailSummar
y-Japanese-4_6_null_
compare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_ReadMoreOutl
inedButtonPreview-Ja
panese-3_5_null_comp
are.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_PreviewTimet
ableGridLongTitleIte
m-Japanese-2_4_null_
compare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_ReadMoreOutl
inedButtonPreview-En
glish-3_6_null_compa
re.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_TimetableLis
tItemPreview-English
-5_8_null_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-LightMode-
3_3_null_3_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-LightMode-
3_3_null_0_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-LightMode-
3_3_null_4_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_L
anguage_TimetableLis
tItemPreview-Japanes
e-5_7_null_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-DarkMode-3
_4_null_4_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.section_null_The
me_TimetablePreview-
LightMode-6_6_null_c
ompare.png
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-LightMode-
3_3_null_1_compare.p
ng
io.github.droidkaigi
.confsched2023.sessi
ons.component_null_T
heme_PreviewTimetabl
eGridItem-DarkMode-3
_4_null_1_compare.pn
g
io.github.droidkaigi
.confsched2023.sessi
ons.section_null_Lan
guage_TimetablePrevi
ew-Japanese-6_8_null
_compare.png

Comment on lines 170 to 185
val titleToScheduleSpaceHeight = with(localDensity) { 4.dp.toPx() }
val scheduleHeight = with(localDensity) { 16.dp.toPx() }
val scheduleToSpeakerSpaceHeight = with(localDensity) { 16.dp.toPx() }
val horizontalPadding = with(localDensity) { (12 * 2).dp.toPx() }

// The height of the title that should be displayed.
var displayTitleHeight =
gridItemHeightPx - titleToScheduleSpaceHeight - scheduleHeight - scheduleToSpeakerSpaceHeight - horizontalPadding
displayTitleHeight -= if (speaker != null) with(localDensity) { 32.dp.toPx() } else 0f

// Actual height of displayed title.
val boxWidthWithoutPadding = with(localDensity) { (192 - 12 * 2).dp.toPx() }
val fontSizePx = with(localDensity) { textStyle.fontSize.toPx() }
val textLengthInRow = (boxWidthWithoutPadding / fontSizePx).roundToInt()
val rows = titleLength / textLengthInRow
val actualTitleHeight = rows * fontSizePx
Copy link
Contributor Author

@shxun6934 shxun6934 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Ask For Option]

I set up the logic as follows.

  1. I checked the height of the Box that displays the session title. (Lines 170-178 of the code)
  2. Based on the actual length of the session title, default font size, and width of the Box, I check whether it fits within the height I checked earlier.
  3. I set the default font size if it fits, or set the minimum font size if it doesn't fit.

It seems to be a little easier to calculate, but I couldn't come up with an opinion myself.

If you don't mind, I would appreciate it if you could give me your opinion.🙇‍♂️

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 16, 2023 13:55 Inactive
@github-actions github-actions bot temporarily deployed to deploygate-distribution August 16, 2023 14:38 Inactive

@Preview
@Composable
fun PreviewTimetableGridLongTitleItem() {
Copy link
Member

@takahirom takahirom Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I see how the text becomes small? In this preview, we see normal-size text right? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out!

In my environment, I confirmed that the text size is small, but it seems that it is not so in the snapshot in GithubActions, so I will check it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shxun6934 Thanks for your quick action!
It might be a reply after tomorrow(today) morning 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 16, 2023 16:49 Inactive
speaker: TimetableSpeaker?,
titleLength: Int,
): TextUnit {
val titleToScheduleSpaceHeight = with(localDensity) { 4.dp.toPx() }
Copy link
Member

@takahirom takahirom Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it const like private val titleToScheduleSpaceHeight =..? to maintain this 👀
Or I'm thinking if we can use Layout() composable. Did you think it? This could be rather complex so I'm not sure it is better 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it const like private val titleToScheduleSpaceHeight =..? to maintain this 👀
I'm thinking if we can use Layout() composable. Did you think it? This could be rather complex so I'm not sure it is better 👀

I see !

Layout composable can certainly be implemented, but I haven't touched it, so it looks like it will take a lot of time.

So, for the time being, we will make the size used for layout a constant while keeping the current implementation.
And, I will try a little with reference to the following documents and blogs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, making private val titleToScheduleSpaceHeight = 4.dp would be better 👍

Copy link
Contributor Author

@shxun6934 shxun6934 Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've made it possible to manage with constants! 🙇‍♂️

I am referring to TimetableSizes.

the fix commit is a1f29be

gridItemHeightPx: Int,
speaker: TimetableSpeaker?,
titleLength: Int,
): Pair<TextUnit, TextUnit> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made not only fontSize but also lineHeight variable.

Comment on lines 245 to 265
while (displayTitleHeight <= actualTitleHeight) {
if (fontResizePx <= minFontSizePx) {
fontResizePx = minFontSizePx
lineHeightResizePx = minLineHeightPx
break
}

fontResizePx -= with(localDensity) { 1.sp.toPx() }
val fontResize = with(localDensity) { fontResizePx.toSp() }
if (fontResize <= 12.sp) {
lineHeightResizePx = middleLineHeightPx
} else if (fontResize <= 10.sp) {
lineHeightResizePx = minLineHeightPx
}
actualTitleHeight = calculateTitleHeight(
fontSizePx = fontResizePx,
lineHeightPx = lineHeightResizePx,
titleLength = titleLength,
maxWidth = boxWidthWithoutPadding,
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added logic to vary font size and lineHeight until it fits inside the Box.

reference

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 17, 2023 15:29 Inactive
@github-actions github-actions bot temporarily deployed to deploygate-distribution August 18, 2023 02:13 Inactive
return fontSizePx + (lineHeightPx * (rows - 1f))
}

object TimetableGridItemSizes {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

Copy link
Member

@takahirom takahirom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigation and making difficult implementation!

@takahirom
Copy link
Member

Oh, we have a conflict. Could you solve it?

@shxun6934
Copy link
Contributor Author

@takahirom

Oh, we have a conflict. Could you solve it?

Thank you for pointing out.

Since the conflict has been resolved, please confirm. 🙇‍♂️

fe8b5d9
5bfb94f

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 18, 2023 03:55 Inactive
@takahirom takahirom merged commit f6e7b36 into DroidKaigi:main Aug 18, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align Session Heights in Timetable Grid Display According to Time Duration
3 participants