-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Add support for only rendering certain sub-trees.
Fixes #58.
- Loading branch information
1 parent
fb698d8
commit 5c9afac
Showing
10 changed files
with
233 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
package radiography | ||
|
||
import radiography.ViewFilter.FilterResult | ||
import radiography.ViewFilter.FilterResult.INCLUDE | ||
|
||
/** | ||
* Used to filter out views from the output of [Radiography.scan]. | ||
*/ | ||
// TODO this isn't really just a "filter" anymore, it's more of a "selector". Rename? | ||
public interface ViewFilter { | ||
|
||
enum class FilterResult { | ||
/** Include this view and all of its children which also match the filter. */ | ||
INCLUDE, | ||
|
||
/** Exclude this view, but include all of its children which match the filter. */ | ||
INCLUDE_ONLY_CHILDREN, | ||
|
||
/** Exclude this view and don't process any of its children. */ | ||
EXCLUDE | ||
} | ||
|
||
/** | ||
* @return true to keep the view in the output of [Radiography.scan], false to filter it out. | ||
*/ | ||
public fun matches(view: Any): Boolean | ||
public fun matches(view: Any): FilterResult | ||
} | ||
|
||
/** | ||
* Base class for implementations of [ViewFilter] that only want to filter instances of a specific | ||
* type. Instances of other types are always "matched" by this filter. | ||
* type. Instances of other types are always [included][INCLUDE] by this filter. | ||
*/ | ||
internal abstract class TypedViewFilter<in T : Any>( | ||
private val filterClass: Class<T> | ||
) : ViewFilter { | ||
public abstract fun matchesTyped(view: T): Boolean | ||
public abstract fun matchesTyped(view: T): FilterResult | ||
|
||
final override fun matches(view: Any): FilterResult { | ||
if (!filterClass.isInstance(view)) return INCLUDE | ||
|
||
final override fun matches(view: Any): Boolean { | ||
@Suppress("UNCHECKED_CAST") | ||
return !filterClass.isInstance(view) || matchesTyped(view as T) | ||
return matchesTyped(view as T) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.