Skip to content

Commit

Permalink
강의 셀 텍스트 그리기에 calculateAdjustedTextLayout 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
JuTaK97 committed Sep 5, 2024
1 parent 41dad16 commit 707f9e6
Showing 1 changed file with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -231,6 +232,8 @@ fun DrawLectures(lectures: List<LectureDto>, fittedTrimParam: TableTrimParam) {
fittedTrimParam = fittedTrimParam,
classTime = classTime,
courseTitle = lecture.course_title,
lectureNumber = lecture.lecture_number.orEmpty(),
instructorName = lecture.instructor,
bgColor =
if (lecture.colorIndex == 0L && lecture.color.bgColor != null) {
lecture.color.bgColor!!
Expand All @@ -257,6 +260,8 @@ private fun DrawClassTime(
fittedTrimParam: TableTrimParam,
classTime: ClassTimeDto,
courseTitle: String,
lectureNumber: String,
instructorName: String,
bgColor: Int,
fgColor: Int,
isCustom: Boolean = false,
Expand All @@ -265,6 +270,7 @@ private fun DrawClassTime(
val dayLabelHeight = 28.5.dp
val cellPadding = 4.dp
val compactMode = LocalCompactState.current
val textMeasurer = rememberTextMeasurer()

val dayOffset = classTime.day - fittedTrimParam.dayOfWeekFrom
val hourRangeOffset =
Expand Down Expand Up @@ -292,20 +298,37 @@ private fun DrawClassTime(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(
text = courseTitle,
color = Color(fgColor),
textAlign = TextAlign.Center,
overflow = TextOverflow.Ellipsis,
fontSize = 10.sp,
)
Text(
text = classTime.place,
color = Color(fgColor),
textAlign = TextAlign.Center,
overflow = TextOverflow.Ellipsis,
fontSize = 11.sp,
)
BoxWithConstraints {
val constraints = constraints
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
val adjustedTextLayouts = remember(constraints, courseTitle, classTime.place, lectureNumber, instructorName, fittedTrimParam) {
calculateAdjustedTextLayout(
listOf(
LectureCellInfo.titleTextLayout(courseTitle, true),
LectureCellInfo.placeTextLayout(classTime.place, true),
LectureCellInfo.lectureNumberTextLayout(lectureNumber, false),
LectureCellInfo.instructorNameTextLayout(instructorName, false),
),
textMeasurer,
constraints,
)
}

adjustedTextLayouts
.forEach { textLayout ->
Text(
text = textLayout.text,
style = textLayout.style.copy(color = Color(fgColor)),
maxLines = textLayout.maxLines,
textAlign = TextAlign.Center,
overflow = TextOverflow.Ellipsis,
)
}
}
}
}
}
}
Expand All @@ -315,7 +338,7 @@ private fun DrawSelectedLecture(selectedLecture: LectureDto?, fittedTrimParam: T
selectedLecture?.run {
for (classTime in class_time_json) {
DrawClassTime(
fittedTrimParam, classTime, course_title, -0x1f1f20, -0xcccccd,
fittedTrimParam, classTime, course_title, lecture_number.orEmpty(), instructor, -0x1f1f20, -0xcccccd,
)
}
}
Expand Down

0 comments on commit 707f9e6

Please sign in to comment.