Skip to content

オーバレイ表示の前後関係の安定化#436

Merged
Freeesia merged 4 commits into
masterfrom
copilot/fix-435
Aug 19, 2025
Merged

オーバレイ表示の前後関係の安定化#436
Freeesia merged 4 commits into
masterfrom
copilot/fix-435

Conversation

Copilot AI commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

This PR implements a solution to prevent large text rectangles from obscuring smaller ones by using a WPF value converter to calculate Z-index based on area. Small text elements like tooltips and buttons will now always appear in front of larger background text.

Implementation Details

Area-Based ZIndex Converter

Created AreaToZIndexConverter that calculates the negative area (Width × Height) as the ZIndex value:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    if (value is not TextRect rect)
        return DependencyProperty.UnsetValue;

    // Small area = large negative value = high ZIndex = front display
    var area = rect.Width * rect.Height;
    return -(int)area;
}

WPF Template Integration

Updated the XAML template to bind Panel.ZIndex directly to the converter:

<Setter Property="Panel.ZIndex" Value="{Binding Converter={StaticResource a2zConv}}" />

Removed Previous ZOrder Implementation

  • Removed ZOrder property from TextRect record
  • Removed area-based sorting logic from MainViewModelBase.CreateTextOverlayAsync()
  • Simplified the codebase by leveraging WPF's built-in data binding capabilities

Example Behavior

The converter automatically calculates Z-index values based on area:

Small tooltip (100px²) → ZIndex = -100 (appears on top)
Medium button (2500px²) → ZIndex = -2500
Large subtitle (10000px²) → ZIndex = -10000
Background title (50000px²) → ZIndex = -50000 (appears behind everything)

This approach eliminates the need for explicit sorting and ZOrder management while achieving the same visual result through WPF's native Z-index system.

Fixes #435.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: Freeesia <9002657+Freeesia@users.noreply.github.com>
Copilot AI changed the title [WIP] テキスト矩形を小さい順にソートして表示する Add ZOrder property and area-based sorting for text rectangles Aug 17, 2025
Copilot AI requested a review from Freeesia August 17, 2025 14:11
Comment thread WindowTranslator/Controls/OverlayTextsControl.cs
Co-authored-by: Freeesia <9002657+Freeesia@users.noreply.github.com>
Copilot AI requested a review from Freeesia August 18, 2025 04:01
@Freeesia

Copy link
Copy Markdown
Owner

@copilot
やっぱりTextRect.ZOrderプロパティを削除してPanel.ZIndexにWidthとHeightをバインドしてコンバーターで面積のマイナス値をZIndexの値とすることで、面積の小さい順に前面に描画されるようにして。

Co-authored-by: Freeesia <9002657+Freeesia@users.noreply.github.com>

Copilot AI commented Aug 18, 2025

Copy link
Copy Markdown
Contributor Author

@copilot
やっぱりTextRect.ZOrderプロパティを削除してPanel.ZIndexにWidthとHeightをバインドしてコンバーターで面積のマイナス値をZIndexの値とすることで、�...

要求された変更を実装しました。TextRect.ZOrderプロパティを削除し、代わりにAreaToZIndexConverterを作成して面積ベースのZIndex計算を行うようにしました。

変更内容:

  • TextRect.ZOrderプロパティを削除
  • MainViewModelBaseからZOrder関連のソート処理を削除
  • AreaToZIndexConverterを作成(面積のマイナス値をZIndexとして返す)
  • Generic.xamlでPanel.ZIndexを新しいコンバーターにバインド

これにより、小さい面積のテキストほど前面に表示されるようになります。

コミット: 10f05d6

Copilot AI changed the title Add ZOrder property and area-based sorting for text rectangles Implement area-based Z-ordering using WPF converter for text rectangles Aug 18, 2025
@Freeesia Freeesia marked this pull request as ready for review August 19, 2025 11:33
@Freeesia Freeesia changed the title Implement area-based Z-ordering using WPF converter for text rectangles オーバレイ表示の前後関係の安定化 Aug 19, 2025
@Freeesia Freeesia merged commit 0a88475 into master Aug 19, 2025
7 checks passed
@Freeesia Freeesia deleted the copilot/fix-435 branch August 19, 2025 12:30
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.

テキスト矩形を小さい順にソートして表示する

2 participants