Skip to content
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

Improve styling of buttons in toolbar & refactor CSS #8295

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion frontend/javascripts/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,6 @@ function Navbar({
paddingTop: navbarHeight > constants.DEFAULT_NAVBAR_HEIGHT ? constants.BANNER_HEIGHT : 0,
}}
/>

<div
style={{
display: "flex",
Expand Down
115 changes: 46 additions & 69 deletions frontend/javascripts/oxalis/view/action-bar/toolbar_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { setToolAction, showQuickSelectSettingsAction } from "oxalis/model/actio
import { updateUserSettingAction } from "oxalis/model/actions/settings_actions";
import { usePrevious, useKeyPress } from "libs/react_hooks";
import { userSettings } from "types/schemas/user_settings.schema";
import ButtonComponent from "oxalis/view/components/button_component";
import ButtonComponent, { ToggleButton } from "oxalis/view/components/button_component";
import { MaterializeVolumeAnnotationModal } from "oxalis/view/action-bar/starting_job_modals";
import {
ToolsWithOverwriteCapabilities,
Expand Down Expand Up @@ -91,12 +91,6 @@ const NARROW_BUTTON_STYLE = {
paddingLeft: 10,
paddingRight: 8,
};
// The z-index is needed so that the blue border of an active button does override the border color of the neighboring non active button.
const ACTIVE_BUTTON_STYLE = {
...NARROW_BUTTON_STYLE,
borderColor: "var(--ant-color-primary)",
zIndex: 1,
};
const imgStyleForSpaceyIcons = {
width: 19,
height: 19,
Expand Down Expand Up @@ -173,7 +167,7 @@ function RadioButtonWithTooltip({
disabledTitle?: string;
disabled?: boolean;
children: React.ReactNode;
style: React.CSSProperties;
style?: React.CSSProperties;
value: string;
onClick?: (event: React.MouseEvent) => void;
onMouseEnter?: () => void;
Expand Down Expand Up @@ -219,7 +213,7 @@ function ToolRadioButton({
disabledExplanation?: string;
disabled?: boolean;
children: React.ReactNode;
style: React.CSSProperties;
style?: React.CSSProperties;
value: string;
onClick?: (event: React.MouseEvent) => void;
onMouseEnter?: () => void;
Expand Down Expand Up @@ -297,7 +291,6 @@ function OverwriteModeSwitch({
>
<RadioButtonWithTooltip
title="Overwrite everything. This setting can be toggled by holding CTRL."
style={NARROW_BUTTON_STYLE}
value={OverwriteModeEnum.OVERWRITE_ALL}
>
<img
Expand All @@ -308,7 +301,6 @@ function OverwriteModeSwitch({
</RadioButtonWithTooltip>
<RadioButtonWithTooltip
title="Only overwrite empty areas. In case of erasing, only the current segment ID is overwritten. This setting can be toggled by holding CTRL."
style={NARROW_BUTTON_STYLE}
value={OverwriteModeEnum.OVERWRITE_EMPTY}
>
<img
Expand Down Expand Up @@ -420,32 +412,29 @@ function AdditionalSkeletonModesButtons() {

const toggleMergerMode = () => dispatch(setMergerModeEnabledAction(!isMergerModeEnabled));

const newNodeNewTreeModeButtonStyle = isNewNodeNewTreeModeOn
? ACTIVE_BUTTON_STYLE
: NARROW_BUTTON_STYLE;
const mergerModeButtonStyle = isMergerModeEnabled ? ACTIVE_BUTTON_STYLE : NARROW_BUTTON_STYLE;

const isMaterializeVolumeAnnotationEnabled =
dataset.dataStore.jobsSupportedByAvailableWorkers.includes(
APIJobType.MATERIALIZE_VOLUME_ANNOTATION,
);

return (
<React.Fragment>
<ButtonComponent
style={newNodeNewTreeModeButtonStyle}
<ToggleButton
style={NARROW_BUTTON_STYLE}
onClick={toggleNewNodeNewTreeMode}
active={isNewNodeNewTreeModeOn}
title="Toggle the Single node Tree (soma clicking) mode - If enabled, each node creation will create a new tree."
>
<img
style={imgStyleForSpaceyIcons}
src="/assets/images/soma-clicking-icon.svg"
alt="Single Node Tree Mode"
/>
</ButtonComponent>
<ButtonComponent
</ToggleButton>
<ToggleButton
active={isMergerModeEnabled}
style={{
...mergerModeButtonStyle,
...NARROW_BUTTON_STYLE,
opacity: isMergerModeDisabled ? 0.5 : 1,
}}
onClick={toggleMergerMode}
Expand All @@ -457,7 +446,7 @@ function AdditionalSkeletonModesButtons() {
src="/assets/images/merger-mode-icon.svg"
alt="Merger Mode"
/>
</ButtonComponent>
</ToggleButton>
{isMergerModeEnabled && isMaterializeVolumeAnnotationEnabled && isUserAdminOrManager && (
<ButtonComponent
style={NARROW_BUTTON_STYLE}
Expand Down Expand Up @@ -940,7 +929,6 @@ export default function ToolbarView() {
description="Use left-click to move around and right-click to open a context menu."
disabledExplanation=""
disabled={false}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.MOVE}
>
<i className="fas fa-arrows-alt" />
Expand All @@ -952,7 +940,6 @@ export default function ToolbarView() {
description={skeletonToolDescription}
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.SKELETON].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.SKELETON].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.SKELETON}
>
<i
Expand All @@ -973,7 +960,6 @@ export default function ToolbarView() {
}
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.BRUSH].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.BRUSH].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.BRUSH}
>
<i
Expand All @@ -993,7 +979,6 @@ export default function ToolbarView() {
}
disabled={disabledInfosForTools[AnnotationToolEnum.ERASE_BRUSH].isDisabled}
style={{
...NARROW_BUTTON_STYLE,
marginLeft: showEraseBrushTool ? 0 : -38,
zIndex: showEraseBrushTool ? "initial" : -10,
transition: "margin 0.3s",
Expand All @@ -1018,7 +1003,6 @@ export default function ToolbarView() {
description="Draw outlines around the voxels you would like to label."
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.TRACE].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.TRACE].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.TRACE}
>
<img
Expand All @@ -1041,7 +1025,6 @@ export default function ToolbarView() {
}
disabled={disabledInfosForTools[AnnotationToolEnum.ERASE_TRACE].isDisabled}
style={{
...NARROW_BUTTON_STYLE,
marginLeft: showEraseTraceTool ? 0 : -38,
zIndex: showEraseTraceTool ? "initial" : -10,
transition: "margin 0.3s",
Expand All @@ -1066,7 +1049,6 @@ export default function ToolbarView() {
description="Flood-fill the clicked region."
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.FILL_CELL].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.FILL_CELL].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.FILL_CELL}
>
<i
Expand All @@ -1085,7 +1067,6 @@ export default function ToolbarView() {
description="Click on a voxel to make its segment id the active segment id."
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.PICK_CELL].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.PICK_CELL].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.PICK_CELL}
>
<i
Expand All @@ -1095,31 +1076,33 @@ export default function ToolbarView() {
}}
/>
</ToolRadioButton>
<ToolRadioButton
name={TOOL_NAMES.QUICK_SELECT}
description="Click on a segment or draw a rectangle around it to automatically detect it"
disabledExplanation={
disabledInfosForTools[AnnotationToolEnum.QUICK_SELECT].explanation
}
disabled={disabledInfosForTools[AnnotationToolEnum.QUICK_SELECT].isDisabled}
value={AnnotationToolEnum.QUICK_SELECT}
>
<img
src="/assets/images/quick-select-tool.svg"
alt="Quick Select Icon"
style={{
opacity: disabledInfosForTools[AnnotationToolEnum.QUICK_SELECT].isDisabled
? 0.5
: 1,
...imgStyleForSpaceyIcons,
}}
/>
</ToolRadioButton>
</React.Fragment>
) : null}
<ToolRadioButton
name={TOOL_NAMES.QUICK_SELECT}
description="Click on a segment or draw a rectangle around it to automatically detect it"
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.QUICK_SELECT].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.QUICK_SELECT].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.QUICK_SELECT}
>
<img
src="/assets/images/quick-select-tool.svg"
alt="Quick Select Icon"
style={{
opacity: disabledInfosForTools[AnnotationToolEnum.QUICK_SELECT].isDisabled ? 0.5 : 1,
...imgStyleForSpaceyIcons,
}}
/>
</ToolRadioButton>
<ToolRadioButton
name={TOOL_NAMES.BOUNDING_BOX}
description="Create, resize and modify bounding boxes."
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].isDisabled}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.BOUNDING_BOX}
>
<img
Expand All @@ -1144,7 +1127,6 @@ export default function ToolbarView() {
!isAgglomerateMappingEnabled.value ||
disabledInfosForTools[AnnotationToolEnum.PROOFREAD].isDisabled
}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.PROOFREAD}
onMouseEnter={() => {
dispatch(ensureLayerMappingsAreLoadedAction());
Expand All @@ -1163,7 +1145,6 @@ export default function ToolbarView() {
description="Use to measure distances or areas."
disabledExplanation=""
disabled={false}
style={NARROW_BUTTON_STYLE}
value={AnnotationToolEnum.LINE_MEASUREMENT}
>
<i className="fas fa-ruler" />
Expand Down Expand Up @@ -1207,7 +1188,6 @@ function ToolSpecificSettings({
);
const isAISelectAvailable = features().segmentAnythingEnabled;
const isQuickSelectHeuristic = quickSelectConfig.useHeuristic || !isAISelectAvailable;
const heuristicButtonStyle = isQuickSelectHeuristic ? NARROW_BUTTON_STYLE : ACTIVE_BUTTON_STYLE;
const quickSelectTooltipText = isAISelectAvailable
? isQuickSelectHeuristic
? "The quick select tool is now working without AI. Activate AI for better results."
Expand Down Expand Up @@ -1264,9 +1244,10 @@ function ToolSpecificSettings({

{adaptedActiveTool === "QUICK_SELECT" && (
<>
<ButtonComponent
<ToggleButton
active={!isQuickSelectHeuristic}
style={{
...heuristicButtonStyle,
...NARROW_BUTTON_STYLE,
opacity: isQuickSelectHeuristic ? 0.5 : 1,
marginLeft: 12,
}}
Expand All @@ -1275,7 +1256,7 @@ function ToolSpecificSettings({
title={quickSelectTooltipText}
>
<i className="fas fa-magic icon-margin-right" /> AI
</ButtonComponent>
</ToggleButton>

<QuickSelectSettingsPopover />
</>
Expand Down Expand Up @@ -1350,15 +1331,15 @@ function QuickSelectSettingsPopover() {
dispatch(showQuickSelectSettingsAction(open));
}}
>
<ButtonComponent
<ToggleButton
title="Configure Quick Select"
tooltipPlacement="right"
className="narrow"
type={isQuickSelectActive || showNux ? "primary" : "default"}
active={isQuickSelectActive || showNux}
style={{ marginLeft: 12, marginRight: 12 }}
>
<SettingOutlined />
</ButtonComponent>
</ToggleButton>
</Popover>
</Wrapper>
</>
Expand Down Expand Up @@ -1421,30 +1402,26 @@ function ProofReadingComponents() {
>
<ClearOutlined />
</ButtonComponent>
<ButtonComponent
<ToggleButton
title={`${autoRenderMeshes ? "Disable" : "Enable"} automatic loading of meshes`}
style={{
...(autoRenderMeshes ? ACTIVE_BUTTON_STYLE : NARROW_BUTTON_STYLE),
opacity: autoRenderMeshes ? 1 : 0.5,
}}
active={autoRenderMeshes}
style={NARROW_BUTTON_STYLE}
onClick={() => handleToggleAutomaticMeshRendering(!autoRenderMeshes)}
>
<i className="fas fa-dice-d20" />
</ButtonComponent>
<ButtonComponent
</ToggleButton>
<ToggleButton
active={selectiveVisibilityInProofreading}
title={`${
selectiveVisibilityInProofreading ? "Disable" : "Enable"
} selective segment visibility. When enabled, only hovered or active segments will be shown.`}
style={{
...(selectiveVisibilityInProofreading ? ACTIVE_BUTTON_STYLE : NARROW_BUTTON_STYLE),
opacity: selectiveVisibilityInProofreading ? 1 : 0.5,
}}
style={NARROW_BUTTON_STYLE}
onClick={() =>
handleToggleSelectiveVisibilityInProofreading(!selectiveVisibilityInProofreading)
}
>
<i className="fas fa-highlighter" />
</ButtonComponent>
</ToggleButton>
</Space.Compact>
);
}
Expand Down
11 changes: 8 additions & 3 deletions frontend/javascripts/oxalis/view/components/button_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from "react";
import _ from "lodash";
import FastTooltip, { type FastTooltipPlacement } from "components/fast_tooltip";

type ButtonComponentProp = ButtonProps & {
type ButtonComponentProps = ButtonProps & {
faIcon?: string;
tooltipPlacement?: FastTooltipPlacement | undefined;
};
Expand All @@ -12,8 +12,8 @@ type ButtonComponentProp = ButtonProps & {
* after it was clicked.
*/

class ButtonComponent extends React.PureComponent<ButtonComponentProp> {
static defaultProps: ButtonComponentProp = {
class ButtonComponent extends React.PureComponent<ButtonComponentProps> {
static defaultProps: ButtonComponentProps = {
onClick: _.noop,
};

Expand Down Expand Up @@ -61,4 +61,9 @@ class ButtonComponent extends React.PureComponent<ButtonComponentProp> {
}
}

export function ToggleButton(props: { active: boolean } & ButtonComponentProps) {
const { active, ...restProps } = props;
return <ButtonComponent type={active ? "primary" : "default"} {...restProps} />;
}

export default ButtonComponent;
Loading