Correct question toolbar controls

This commit is contained in:
hz
2026-07-18 15:29:21 -05:00
parent ea36692c40
commit eb8747d48e
8 changed files with 125 additions and 75 deletions
+28 -56
View File
@@ -4,6 +4,8 @@ const Style := preload("res://scripts/ui/ui_style.gd")
const Brand := preload("res://scripts/ui/medmind_style.gd")
const CLEAR_HIGHLIGHT_DARK_ICON := preload("res://assets/icons/medmind/clear-highlight-darkmode.png")
const CLEAR_HIGHLIGHT_LIGHT_ICON := preload("res://assets/icons/medmind/clear-highlight-lightmode.png")
const LABS_DARK_ICON := preload("res://assets/icons/medmind/labs-darkmode.png")
const LABS_LIGHT_ICON := preload("res://assets/icons/medmind/labs-lightmode.png")
const REPORT_QUESTION_DARK_ICON := preload("res://assets/icons/medmind/report-question-darkmode.png")
const REPORT_QUESTION_LIGHT_ICON := preload("res://assets/icons/medmind/report-question-lightmode.png")
const FEEDBACK_FADE_SECONDS := 0.45
@@ -207,7 +209,11 @@ func _ready() -> void:
theme_button = Button.new()
theme_button.custom_minimum_size = Vector2(44, 44)
theme_button.add_theme_font_size_override("font_size", 22)
theme_button.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
theme_button.size_flags_vertical = Control.SIZE_SHRINK_CENTER
theme_button.alignment = HORIZONTAL_ALIGNMENT_CENTER
theme_button.icon_alignment = HORIZONTAL_ALIGNMENT_CENTER
theme_button.focus_mode = Control.FOCUS_NONE
UISoundService.set_button_sound(theme_button, "toggle")
theme_button.pressed.connect(theme_service.toggle_theme)
question_toolbar.add_child(theme_button)
@@ -233,9 +239,7 @@ func _ready() -> void:
labs_button = Button.new()
labs_button.tooltip_text = "Review lab results"
labs_button.icon = _make_labs_icon()
labs_button.custom_minimum_size = Vector2(44, 44)
Style.style_chip(labs_button, Style.LIME)
UISoundService.set_button_sound(labs_button, "open")
labs_button.pressed.connect(_show_labs_modal)
question_toolbar.add_child(labs_button)
@@ -657,6 +661,10 @@ func _theme_toggle_box(dark: bool, hovered: bool = false) -> StyleBoxFlat:
box.border_color = Brand.AMBER if hovered else (Color("33415d") if dark else Brand.LIGHT_BORDER)
box.set_border_width_all(1)
box.set_corner_radius_all(22)
box.content_margin_left = 0
box.content_margin_right = 0
box.content_margin_top = 0
box.content_margin_bottom = 0
return box
@@ -669,20 +677,20 @@ func _style_theme_toggle_button(dark: bool) -> void:
theme_button.add_theme_stylebox_override("hover", _theme_toggle_box(dark, true))
theme_button.add_theme_stylebox_override("pressed", _theme_toggle_box(dark, true))
theme_button.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
theme_button.add_theme_constant_override("h_separation", 0)
func _style_asset_toolbar_button(button: Button, texture: Texture2D) -> void:
if button == null:
return
button.text = ""
button.icon = texture
button.expand_icon = true
button.add_theme_constant_override("icon_max_width", 44)
var empty := StyleBoxEmpty.new()
for state in ["normal", "hover", "pressed", "focus"]:
button.add_theme_stylebox_override(state, empty)
for color_name in ["icon_normal_color", "icon_hover_color", "icon_pressed_color", "icon_focus_color"]:
button.add_theme_color_override(color_name, Color.WHITE)
button.icon = null
button.focus_mode = Control.FOCUS_NONE
var texture_box := StyleBoxTexture.new()
texture_box.texture = texture
for state in ["normal", "hover", "pressed"]:
button.add_theme_stylebox_override(state, texture_box)
button.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
func _primary_action_box(dark: bool, state: String) -> StyleBoxFlat:
@@ -806,7 +814,7 @@ func _apply_question_theme() -> void:
var navigator_heading := navigator_popup.find_child("NavigatorHeading", true, false) as Label
if navigator_heading != null:
navigator_heading.add_theme_color_override("font_color", Brand.text_color(dark))
for control in [text_smaller_button, text_larger_button, labs_button, flag_button, app_feedback_button]:
for control in [text_smaller_button, text_larger_button, flag_button, app_feedback_button]:
if control == null:
continue
var active: bool = control == flag_button and flagged
@@ -815,6 +823,7 @@ func _apply_question_theme() -> void:
control.add_theme_stylebox_override("pressed", _toolbar_box(dark, true))
control.add_theme_color_override("font_color", Brand.text_color(dark))
control.add_theme_color_override("icon_normal_color", Brand.SKY_BLUE)
_style_asset_toolbar_button(labs_button, LABS_DARK_ICON if dark else LABS_LIGHT_ICON)
_style_asset_toolbar_button(clear_highlight_button, CLEAR_HIGHLIGHT_DARK_ICON if dark else CLEAR_HIGHLIGHT_LIGHT_ICON)
_style_asset_toolbar_button(report_button, REPORT_QUESTION_DARK_ICON if dark else REPORT_QUESTION_LIGHT_ICON)
_style_theme_toggle_button(dark)
@@ -1637,26 +1646,18 @@ func _update_timer_bar() -> void:
if timer_bar == null:
return
var is_core_timer := BlockSessionService.session_kind == "core"
var ratio := BlockSessionService.get_core_question_elapsed_ratio() if is_core_timer else BlockSessionService.get_session_timer_ratio()
var ratio := BlockSessionService.get_session_timer_ratio()
timer_bar.value = ratio * 100.0
if is_core_timer and timer_label.visible:
_set_timer_display(int(floor(BlockSessionService.get_core_question_total_elapsed_seconds())))
var color_state := "blue"
var fill_color := Brand.ROYAL_BLUE
if is_core_timer:
if ratio >= 1.0:
color_state = "red"
fill_color = Style.RED
elif ratio >= 0.75:
color_state = "amber"
fill_color = Style.AMBER
else:
if ratio < 0.25:
color_state = "red"
fill_color = Style.RED
elif ratio <= 0.5:
color_state = "amber"
fill_color = Style.AMBER
if ratio < 0.25:
color_state = "red"
fill_color = Style.RED
elif ratio <= 0.5:
color_state = "amber"
fill_color = Style.AMBER
if color_state != timer_color_state:
timer_color_state = color_state
timer_bar.add_theme_stylebox_override("fill", Style.button_box(fill_color, fill_color))
@@ -1856,8 +1857,6 @@ func _refresh_toolbar_state() -> void:
func refresh_theme_controls() -> void:
if media_viewer_background != null:
media_viewer_background.color = Style.BACKGROUND
if labs_button != null:
labs_button.icon = _make_labs_icon()
if flag_button != null:
flag_button.icon = _make_flag_icon()
_refresh_toolbar_state()
@@ -3318,33 +3317,6 @@ func _update_question_elo_label(show_label: bool) -> void:
question_elo_label.visible = true
func _make_labs_icon() -> Texture2D:
var image := Image.create(24, 24, false, Image.FORMAT_RGBA8)
image.fill(Color(0, 0, 0, 0))
var glass_color := Style.TEXT
var fluid_color := Style.LIME
for x in range(8, 16):
image.set_pixel(x, 4, glass_color)
for y in range(5, 10):
image.set_pixel(10, y, glass_color)
image.set_pixel(13, y, glass_color)
for y in range(10, 20):
var left := 10 - int(floor(float(y - 10) / 3.0))
var right := 13 + int(floor(float(y - 10) / 3.0))
image.set_pixel(left, y, glass_color)
image.set_pixel(right, y, glass_color)
for x in range(7, 17):
image.set_pixel(x, 20, glass_color)
for y in range(15, 20):
for x in range(8, 16):
if x >= 10 - int(floor(float(y - 10) / 3.0)) and x <= 13 + int(floor(float(y - 10) / 3.0)):
image.set_pixel(x, y, fluid_color)
image.set_pixel(7, 7, Style.CYAN)
image.set_pixel(17, 9, Style.CYAN)
image.set_pixel(18, 6, Style.CYAN)
return ImageTexture.create_from_image(image)
func _make_flag_icon() -> Texture2D:
var image := Image.create(24, 24, false, Image.FORMAT_RGBA8)
image.fill(Color(0, 0, 0, 0))