@@ -136,18 +136,20 @@ impl Plugin for LogViewerPlugin {
136136 // Running update_log_ui in PreUpdate to prevent data races between updating the UI and filtering log lines.
137137 // `handle_level_filter_chip_toggle`` can modify the `{level}_visible` fields in `LogViewerState`
138138 // while `update_log_ui` is adding new loglines to the viewer in parallel based on older values.
139- app. add_systems (
140- PreUpdate ,
141- ( manage_scroll_ui_state, receive_logs, update_log_counts) . chain ( ) ,
142- ) ;
139+ app. add_systems ( PreUpdate , ( receive_logs, update_log_counts) . chain ( ) ) ;
143140
144141 app. add_systems (
145142 Update ,
146143 (
147144 on_traffic_light_button,
148145 on_auto_open_check,
149146 on_level_filter_chip,
150- ( handle_listcontainer_overflow, handle_scroll_update) . chain ( ) ,
147+ (
148+ manage_scroll_ui_state,
149+ handle_listcontainer_overflow,
150+ handle_scroll_update,
151+ )
152+ . chain ( ) ,
151153 ) ,
152154 ) ;
153155 }
@@ -546,39 +548,30 @@ fn handle_listcontainer_overflow(
546548}
547549
548550fn manage_scroll_ui_state (
549- mut log_viewer : ResMut < LogViewerState > ,
551+ log_viewer : Res < LogViewerState > ,
550552 mut border_color_q : Query < & mut BorderColor , With < LogViewerMarker > > ,
551553 mut scroll_to_bottom_btn_q : Query < & mut Node , With < GoDownBtnMarker > > ,
552554 mut scroll_query : Query < ( & ScrollPosition , & ComputedNode , & Children ) , With < ListContainerMarker > > ,
553555 child_comp_node_query : Query < & ComputedNode , With < ListMarker > > ,
554556) {
555- if let Ok ( ( scroll_position, parent_comp_node, children) ) = scroll_query. get_single_mut ( ) {
556- if let Ok ( child_comp_node) = child_comp_node_query. get ( children[ 0 ] ) {
557- // The list is at bottom if the sum of the parent's height and the scroll offset is equal to the child's height.
558- // We subtract the font size to account for the last log line being partially visible and still count that as being at the bottom.
559- let is_at_bottom = parent_comp_node. size ( ) . y + scroll_position. offset_y
560- >= child_comp_node. size ( ) . y - LOG_LINE_FONT_SIZE ;
557+ if let Ok ( ( _scroll_position, _parent_comp_node, children) ) = scroll_query. single_mut ( ) {
558+ if let Ok ( _child_comp_node) = child_comp_node_query. get ( children[ 0 ] ) {
559+ let hide_button = log_viewer. scroll_state != ScrollState :: Manual ;
561560
562- if let Ok ( mut border_color) = border_color_q. get_single_mut ( ) {
563- * border_color = if is_at_bottom {
561+ if let Ok ( mut border_color) = border_color_q. single_mut ( ) {
562+ * border_color = if hide_button {
564563 Color :: NONE . into ( )
565564 } else {
566565 css:: WHITE . with_alpha ( 0.25 ) . into ( )
567566 } ;
568567 }
569- if let Ok ( mut scroll_to_bottom_btn) = scroll_to_bottom_btn_q. get_single_mut ( ) {
570- scroll_to_bottom_btn. display = if is_at_bottom {
568+ if let Ok ( mut scroll_to_bottom_btn) = scroll_to_bottom_btn_q. single_mut ( ) {
569+ scroll_to_bottom_btn. display = if hide_button {
571570 Display :: None
572571 } else {
573572 Display :: Flex
574573 } ;
575574 }
576-
577- log_viewer. scroll_state = if is_at_bottom {
578- ScrollState :: Auto
579- } else {
580- ScrollState :: Manual
581- } ;
582575 }
583576 }
584577}
@@ -590,7 +583,7 @@ fn handle_scroll_to_bottom(
590583 computed_node_query : Query < & ComputedNode , With < ListMarker > > ,
591584) {
592585 // ListContainerMarker -> ListMarker have a Parent -> Child relationship.
593- if let Ok ( ( mut scroll_position, children) ) = scroll_query. get_single_mut ( ) {
586+ if let Ok ( ( mut scroll_position, children) ) = scroll_query. single_mut ( ) {
594587 if let Ok ( computed_node) = computed_node_query. get ( children[ 0 ] ) {
595588 scroll_position. offset_y = computed_node. size ( ) . y ;
596589 log_viewer. scroll_state = ScrollState :: Auto ;
@@ -645,7 +638,7 @@ fn spawn_logline(commands: &mut Commands, parent: Entity, event: &LogEvent) -> E
645638 TextFont :: from_font_size ( LOG_LINE_FONT_SIZE ) ,
646639 TextColor ( css:: WHITE . into ( ) ) ,
647640 ) )
648- . set_parent ( parent)
641+ . insert ( ChildOf { parent } )
649642 . id ( )
650643}
651644
0 commit comments