-
Notifications
You must be signed in to change notification settings - Fork 47
add tabbed brush editor with Tip Shape, Paint, and Behaviors tabs #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f1039b0
2a9db79
526ae31
14c9fb9
4a4f8e3
17c1e8c
1bca86d
fa582f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,4 @@ | |
| .cxx | ||
| local.properties | ||
| ink-proto/bin/ | ||
| gradle/gradle-daemon-jvm.properties | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,284 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.example.cahier.developer.brushdesigner.ui | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.FilledTonalButton | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import com.example.cahier.R | ||
| import com.example.cahier.developer.brushdesigner.viewmodel.PrefabBehaviors | ||
| import ink.proto.BrushBehavior | ||
| import ink.proto.BrushFamily as ProtoBrushFamily | ||
|
|
||
| /** | ||
| * Tab 2: Dynamics & Behaviors controls — editable behavior stack with nested | ||
| * node graph editor, standard dynamics presets, and advanced dynamics presets. | ||
| * | ||
| * Uses [EditableListWidget] for managing behaviors (outer list) and nodes | ||
| * within each behavior (inner nested list), with [NodeEditor] for | ||
| * type-specific node editing. | ||
| * | ||
| * Stateless: receives data and callbacks, does not access ViewModel. | ||
| */ | ||
| @Composable | ||
| internal fun BehaviorsTabContent( | ||
| activeProto: ProtoBrushFamily, | ||
| selectedCoatIndex: Int, | ||
| onUpdateBehaviors: (List<BrushBehavior>) -> Unit, | ||
| onClearBehaviors: () -> Unit, | ||
| onAddBehavior: (List<BrushBehavior.Node>) -> Unit, | ||
| ) { | ||
| val behaviors = activeProto | ||
| .coatsList.getOrNull(selectedCoatIndex)?.tip?.behaviorsList | ||
| ?: emptyList() | ||
|
|
||
| Text( | ||
| stringResource(R.string.brush_designer_dynamics_behaviors), | ||
| style = MaterialTheme.typography.titleMedium, | ||
| modifier = Modifier.padding(top = 8.dp) | ||
| ) | ||
|
|
||
| EditableListWidget( | ||
| title = stringResource(R.string.brush_designer_behavior_stack), | ||
| items = behaviors, | ||
| defaultItem = BrushBehavior.newBuilder() | ||
| .addNodes( | ||
| BrushBehavior.Node.newBuilder().setSourceNode( | ||
| BrushBehavior.SourceNode.newBuilder() | ||
| .setSource(BrushBehavior.Source.SOURCE_NORMALIZED_PRESSURE) | ||
| .setSourceValueRangeStart(0f) | ||
| .setSourceValueRangeEnd(1f) | ||
| .setSourceOutOfRangeBehavior( | ||
| BrushBehavior.OutOfRange.OUT_OF_RANGE_CLAMP | ||
| ) | ||
| ) | ||
| ) | ||
| .addNodes( | ||
| BrushBehavior.Node.newBuilder().setTargetNode( | ||
| BrushBehavior.TargetNode.newBuilder() | ||
| .setTarget(BrushBehavior.Target.TARGET_SIZE_MULTIPLIER) | ||
| .setTargetModifierRangeStart(0.5f) | ||
| .setTargetModifierRangeEnd(1.5f) | ||
| ) | ||
| ) | ||
| .build(), | ||
| onItemsChanged = onUpdateBehaviors, | ||
| itemHeader = { behavior -> | ||
| val source = behavior.nodesList | ||
| .find { it.hasSourceNode() } | ||
| ?.sourceNode?.source?.name?.replace("SOURCE_", "") | ||
| ?: "INPUT" | ||
| val target = behavior.nodesList | ||
| .find { it.hasTargetNode() } | ||
| ?.targetNode?.target?.name?.replace("TARGET_", "") | ||
| ?: "OUTPUT" | ||
| "$source ➔ $target" | ||
| }, | ||
| editorContent = { behavior, onBehaviorChanged -> | ||
| BehaviorNodeGraphEditor( | ||
| behavior = behavior, | ||
| onBehaviorChanged = onBehaviorChanged | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| HorizontalDivider() | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
|
|
||
| StandardDynamicsSection(onAddBehavior = onAddBehavior) | ||
|
|
||
| Spacer(modifier = Modifier.height(16.dp)) | ||
|
|
||
| AdvancedDynamicsSection( | ||
| onAddBehavior = onAddBehavior | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Nested node graph editor for a single [BrushBehavior]. | ||
| * Uses a nested [EditableListWidget] to manage the ordered list of nodes. | ||
| */ | ||
| @Composable | ||
| private fun BehaviorNodeGraphEditor( | ||
| behavior: BrushBehavior, | ||
| onBehaviorChanged: (BrushBehavior) -> Unit | ||
| ) { | ||
| Text( | ||
| stringResource(R.string.brush_designer_nodes_in_behavior), | ||
| style = MaterialTheme.typography.labelLarge | ||
| ) | ||
|
|
||
| EditableListWidget( | ||
| title = "", | ||
| items = behavior.nodesList, | ||
| defaultItem = BrushBehavior.Node.newBuilder() | ||
| .setConstantNode( | ||
| BrushBehavior.ConstantNode.newBuilder().setValue(1f) | ||
| ) | ||
| .build(), | ||
| onItemsChanged = { newNodes -> | ||
| onBehaviorChanged( | ||
| behavior.toBuilder().clearNodes().addAllNodes(newNodes).build() | ||
| ) | ||
| }, | ||
| itemHeader = { node -> | ||
| node.nodeCase.name.replace("_NODE", "") | ||
| }, | ||
| editorContent = { node, onNodeChanged -> | ||
| NodeEditor(node = node, onNodeChanged = onNodeChanged) | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun StandardDynamicsSection( | ||
| onAddBehavior: (List<BrushBehavior.Node>) -> Unit | ||
| ) { | ||
| Text( | ||
| stringResource(R.string.brush_designer_standard_dynamics), | ||
| style = MaterialTheme.typography.labelLarge | ||
| ) | ||
| Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { | ||
| Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { | ||
| Button(modifier = Modifier.weight(1f), onClick = { | ||
| val s = BrushBehavior.Node.newBuilder().setSourceNode( | ||
| BrushBehavior.SourceNode.newBuilder() | ||
| .setSource(BrushBehavior.Source.SOURCE_NORMALIZED_PRESSURE) | ||
| .setSourceValueRangeStart(0f).setSourceValueRangeEnd(1f) | ||
| .setSourceOutOfRangeBehavior( | ||
| BrushBehavior.OutOfRange.OUT_OF_RANGE_CLAMP | ||
| ) | ||
| ).build() | ||
| val t = BrushBehavior.Node.newBuilder().setTargetNode( | ||
| BrushBehavior.TargetNode.newBuilder() | ||
| .setTarget(BrushBehavior.Target.TARGET_SIZE_MULTIPLIER) | ||
| .setTargetModifierRangeStart(0.5f).setTargetModifierRangeEnd(1.5f) | ||
| ).build() | ||
| onAddBehavior(listOf(s, t)) | ||
|
Comment on lines
+176
to
+189
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be using the behaviors in |
||
| }) { Text(stringResource(R.string.brush_designer_pressure_size)) } | ||
|
|
||
| Button(modifier = Modifier.weight(1f), onClick = { | ||
| val s = BrushBehavior.Node.newBuilder().setSourceNode( | ||
| BrushBehavior.SourceNode.newBuilder() | ||
| .setSource( | ||
| BrushBehavior.Source | ||
| .SOURCE_SPEED_IN_MULTIPLES_OF_BRUSH_SIZE_PER_SECOND | ||
| ) | ||
| .setSourceValueRangeStart(0f).setSourceValueRangeEnd(50f) | ||
| .setSourceOutOfRangeBehavior( | ||
| BrushBehavior.OutOfRange.OUT_OF_RANGE_CLAMP | ||
| ) | ||
| ).build() | ||
| val t = BrushBehavior.Node.newBuilder().setTargetNode( | ||
| BrushBehavior.TargetNode.newBuilder() | ||
| .setTarget(BrushBehavior.Target.TARGET_SIZE_MULTIPLIER) | ||
| .setTargetModifierRangeStart(0.2f).setTargetModifierRangeEnd(2.0f) | ||
| ).build() | ||
| onAddBehavior(listOf(s, t)) | ||
| }) { Text(stringResource(R.string.brush_designer_speed_size)) } | ||
| } | ||
|
|
||
| Button(modifier = Modifier.fillMaxWidth(), onClick = { | ||
| val s = BrushBehavior.Node.newBuilder().setSourceNode( | ||
| BrushBehavior.SourceNode.newBuilder() | ||
| .setSource( | ||
| BrushBehavior.Source | ||
| .SOURCE_SPEED_IN_MULTIPLES_OF_BRUSH_SIZE_PER_SECOND | ||
| ) | ||
| .setSourceValueRangeStart(5f).setSourceValueRangeEnd(40f) | ||
| .setSourceOutOfRangeBehavior( | ||
| BrushBehavior.OutOfRange.OUT_OF_RANGE_CLAMP | ||
| ) | ||
| ).build() | ||
| val t = BrushBehavior.Node.newBuilder().setTargetNode( | ||
| BrushBehavior.TargetNode.newBuilder() | ||
| .setTarget(BrushBehavior.Target.TARGET_OPACITY_MULTIPLIER) | ||
| .setTargetModifierRangeStart(1.0f).setTargetModifierRangeEnd(0.1f) | ||
| ).build() | ||
| onAddBehavior(listOf(s, t)) | ||
| }) { Text(stringResource(R.string.brush_designer_speed_opacity)) } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun AdvancedDynamicsSection( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the behaviors in |
||
| onAddBehavior: (List<BrushBehavior.Node>) -> Unit | ||
| ) { | ||
| Text( | ||
| stringResource(R.string.brush_designer_advanced_dynamics), | ||
| style = MaterialTheme.typography.labelLarge | ||
| ) | ||
|
|
||
| Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { | ||
| FilledTonalButton( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| onClick = { onAddBehavior(PrefabBehaviors.pressureToSize()) } | ||
| ) { | ||
| Icon( | ||
| painterResource(R.drawable.brush_24px), | ||
| null, | ||
| Modifier.size(18.dp) | ||
| ) | ||
| Spacer(Modifier.width(8.dp)) | ||
| Text(stringResource(R.string.brush_designer_smooth_pressure_size)) | ||
| } | ||
|
|
||
| FilledTonalButton( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| onClick = { onAddBehavior(PrefabBehaviors.slantJitter()) } | ||
| ) { | ||
| Icon( | ||
| painterResource(R.drawable.texture_24px), | ||
| null, | ||
| Modifier.size(18.dp) | ||
| ) | ||
| Spacer(Modifier.width(8.dp)) | ||
| Text(stringResource(R.string.brush_designer_pencil_jitter)) | ||
| } | ||
|
|
||
| FilledTonalButton( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| onClick = { onAddBehavior(PrefabBehaviors.speedToOpacity()) } | ||
| ) { | ||
| Icon( | ||
| painterResource(R.drawable.opacity_24px), | ||
| null, | ||
| Modifier.size(18.dp) | ||
| ) | ||
| Spacer(Modifier.width(8.dp)) | ||
| Text(stringResource(R.string.brush_designer_smooth_speed_opacity)) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
onClearBehaviorsparameter is defined but not used within theBehaviorsTabContentcomposable. If this functionality is intended to be exposed, ensure it's wired up to a UI element. If not, it can be removed to simplify the composable's signature.