Skip to content

feat: Added prfabs for checkbox 14px and 24px (MAPCO-9479)#29

Open
ofekazar wants to merge 1 commit intoMapColonies:masterfrom
ofekazar:MAPCO-9479-ui-checkbox
Open

feat: Added prfabs for checkbox 14px and 24px (MAPCO-9479)#29
ofekazar wants to merge 1 commit intoMapColonies:masterfrom
ofekazar:MAPCO-9479-ui-checkbox

Conversation

@ofekazar
Copy link
Collaborator

@ofekazar ofekazar commented Mar 5, 2026

No description provided.

Copy link
Collaborator

@baruchInsert-tech baruchInsert-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • no need to have duplicate prefabs (24px and 14px), we can just change the size when needed - thats why i provided you only with the 72px pngs, also when exporting from Figma export without empty boundaries, if you have blank spaces then the prefab image wont fit the design
  • remove all summary and comments in all files
  • the current _isPartial field is a manually set serialized boolean, with a comment
    saying it should eventually be replaced. here is how to implement it properly:
  1. add a List<Toggle> _childToggles serialized field to hold references to
    child toggles. the _isPartial state should be computed automatically — no longer
    serialized.
  2. in OnEnable(), subscribe to each child's onValueChanged. in OnDisable(),
    unsubscribe.
  3. when the parent is clicked: set all children to match the parent's isOn
    state (select all / deselect all). set _isPartial = false.
  4. when any child changes: count how many children are on vs off.
    -all on - parent isOn = true, _isPartial = false (checked)
    -all off - parent isOn = false, _isPartial = false (unchecked)
  • mixed - _isPartial = true (partial)
  • use SetIsOnWithoutNotify() to update the parent's isOn without triggering
    OnToggleChanged
  • updateVisualState() sprite priority: disabled > partial > checked/unchecked.

@ofekazar
Copy link
Collaborator Author

ofekazar commented Mar 5, 2026

@baruchInsert-tech When using the 4x pngs downsizing is done very poorly by unity. I couldn't get the settings quite right with that.

@baruchInsert-tech
Copy link
Collaborator

@baruchInsert-tech When using the 4x pngs downsizing is done very poorly by unity. I couldn't get the settings quite right with that.

have u tried to change Pixel Per Unit Multiplier on the image?

@ofekazar
Copy link
Collaborator Author

ofekazar commented Mar 5, 2026

@baruchInsert-tech Yes I tried to play with that value as well. the bottom one is the larger image. it is phsycally larger because it has no borders but you can see the artifacts even though it is larger.
image

@baruchInsert-tech
Copy link
Collaborator

@baruchInsert-tech Yes I tried to play with that value as well. the bottom one is the larger image. it is phsycally larger because it has no borders but you can see the artifacts even though it is larger. image

what size image are u using and what is the value u inserted?
if cant make it look ok, procced with the task, ill take a look when finished everything else

@ofekazar ofekazar force-pushed the MAPCO-9479-ui-checkbox branch from a72f809 to 9fe7872 Compare March 5, 2026 18:29
@ofekazar ofekazar force-pushed the MAPCO-9479-ui-checkbox branch from 9fe7872 to f32e4fa Compare March 5, 2026 18:35
@ofekazar
Copy link
Collaborator Author

ofekazar commented Mar 5, 2026

I tried all the values for 1 to 400.
Best I ever got to have a nice clear picture is to have a sprite renderer showing the original size but that wouldn't do with a single image.

Anyway I got the logic of the children working recusivly in this patch and I remember to add the unboardered images this time.

Comment on lines +63 to +69
protected override void OnValidate()
{
base.OnValidate();

RecomputeFromChildren();
UpdateVisualState();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not wrapped in #if UNITY_EDITOR (causes build warnings on non-editor)
calling RecomputeFromChildren() here is not needed - OnValidate is for editor preview only, UpdateVisualState() is enough

Comment on lines +83 to +88
private void HandleChildValueChanged(bool _)
{
RecomputeFromChildren();
UpdateVisualState();
PropagateStateToParent();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add _isUpdating guard.
PropagateStateToParent() is unnecessary
UpdateVisualState() is already called inside RecomputeFromChildren

Comment on lines +90 to +107
private void PropagateToChildren(bool value)
{
for (int i = 0; i < _childToggles.Count; i++) {
Toggle child = _childToggles[i];
if (child == null) {
continue;
}

if (child is YahalomCheckbox childCheckbox) {
childCheckbox.SetIsOnFromParent(value);
}
else {
child.isOn = value;
}
}

_isPartial = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this method entirely. Its logic should inline inside OnParentValueChanged


for (int i = 0; i < _childToggles.Count; i++) {
Toggle child = _childToggles[i];
if (child == null || !child.IsInteractable()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping non-interactable children makes the count unreliable. a disabled child that is checked should still count as checked.

Comment on lines +133 to +136
if (child is YahalomCheckbox childCheckbox && childCheckbox._isPartial) {
_isPartial = true;
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking child._isPartial directly couples to the concrete type. with the simplified approach this is unnecessary a simple count of checked vs total children is enough to determine the parent's state.

Comment on lines +181 to +185
bool isInteractable = IsInteractable();
if (isInteractable != _lastEffectiveInteractable) {
UpdateChildrenInteractable(isInteractable);
_lastEffectiveInteractable = isInteractable;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the interactable tracking and UpdateChildrenInteractable call doesn't belong here. a visual update method should only update visuals, not manage child state. Remove this block

{
base.OnInspectorGUI();

serializedObject.Update();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializedObject.Update() must come BEFORE base.OnInspectorGUI(), not after. When Update() is called after base, the serialized data shown in the base inspector may be stale for one frame.

Copy link
Collaborator

@baruchInsert-tech baruchInsert-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • rename prefab to match other components, something like yahalomcheckbox and not just checkbox.

  • rename ui assets to match other components, "toggle_check"
    or "toggle_disabled" , not just numbers

  • you have imported the exact size of the assets and not 4x. - please import the 4x size of the assets. it should solve the issues with quality

@baruchInsert-tech baruchInsert-tech added the In Progress task development has started label Mar 8, 2026
@asafmas-rnd asafmas-rnd changed the title Added prfabs for checkbox 14px and 24px (MAPCO-9479) feat: Added prfabs for checkbox 14px and 24px (MAPCO-9479) Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In Progress task development has started

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants