Added tooltip to toolbar buttons

This commit is contained in:
Harinandan 2021-11-23 21:11:49 +05:30
parent fe88e100e2
commit 513df69042
9 changed files with 113 additions and 31 deletions

View File

@ -8,6 +8,7 @@ class FlowyCheckListButton extends StatefulWidget {
const FlowyCheckListButton({ const FlowyCheckListButton({
required this.controller, required this.controller,
required this.attribute, required this.attribute,
required this.tooltipText,
this.iconSize = defaultIconSize, this.iconSize = defaultIconSize,
this.fillColor, this.fillColor,
this.childBuilder = defaultToggleStyleButtonBuilder, this.childBuilder = defaultToggleStyleButtonBuilder,
@ -24,6 +25,8 @@ class FlowyCheckListButton extends StatefulWidget {
final Attribute attribute; final Attribute attribute;
final String tooltipText;
@override @override
_FlowyCheckListButtonState createState() => _FlowyCheckListButtonState(); _FlowyCheckListButtonState createState() => _FlowyCheckListButtonState();
} }
@ -35,7 +38,8 @@ class _FlowyCheckListButtonState extends State<FlowyCheckListButton> {
void _didChangeEditingValue() { void _didChangeEditingValue() {
setState(() { setState(() {
_isToggled = _getIsToggled(widget.controller.getSelectionStyle().attributes); _isToggled =
_getIsToggled(widget.controller.getSelectionStyle().attributes);
}); });
} }
@ -52,7 +56,8 @@ class _FlowyCheckListButtonState extends State<FlowyCheckListButton> {
if (attribute == null) { if (attribute == null) {
return false; return false;
} }
return attribute.value == widget.attribute.value || attribute.value == Attribute.checked.value; return attribute.value == widget.attribute.value ||
attribute.value == Attribute.checked.value;
} }
return attrs.containsKey(widget.attribute.key); return attrs.containsKey(widget.attribute.key);
} }
@ -80,10 +85,13 @@ class _FlowyCheckListButtonState extends State<FlowyCheckListButton> {
width: widget.iconSize * kIconButtonFactor, width: widget.iconSize * kIconButtonFactor,
iconName: 'editor/checkbox', iconName: 'editor/checkbox',
isToggled: _isToggled ?? false, isToggled: _isToggled ?? false,
tooltipText: widget.tooltipText,
); );
} }
void _toggleAttribute() { void _toggleAttribute() {
widget.controller.formatSelection(_isToggled! ? Attribute.clone(Attribute.unchecked, null) : Attribute.unchecked); widget.controller.formatSelection(_isToggled!
? Attribute.clone(Attribute.unchecked, null)
: Attribute.unchecked);
} }
} }

View File

@ -33,6 +33,7 @@ class _FlowyColorButtonState extends State<FlowyColorButton> {
late bool _isWhitebackground; late bool _isWhitebackground;
Style get _selectionStyle => widget.controller.getSelectionStyle(); Style get _selectionStyle => widget.controller.getSelectionStyle();
final tooltipText = 'Highlight';
void _didChangeEditingValue() { void _didChangeEditingValue() {
setState(() { setState(() {
@ -91,13 +92,17 @@ class _FlowyColorButtonState extends State<FlowyColorButton> {
? stringToColor('#ffffff') ? stringToColor('#ffffff')
: (widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor); : (widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor);
return QuillIconButton( return Tooltip(
message: tooltipText,
showDuration: Duration.zero,
child: QuillIconButton(
highlightElevation: 0, highlightElevation: 0,
hoverElevation: 0, hoverElevation: 0,
size: widget.iconSize * kIconButtonFactor, size: widget.iconSize * kIconButtonFactor,
icon: Icon(widget.icon, size: widget.iconSize, color: theme.iconTheme.color), icon: Icon(widget.icon, size: widget.iconSize, color: theme.iconTheme.color),
fillColor: widget.background ? fillColorBackground : fillColor, fillColor: widget.background ? fillColorBackground : fillColor,
onPressed: _showColorPicker, onPressed: _showColorPicker,
),
); );
} }

View File

@ -51,6 +51,7 @@ class _FlowyHeaderStyleButtonState extends State<FlowyHeaderStyleButton> {
// final child = // final child =
// _valueToText[_value] == _valueString[index] ? svg('editor/H1', color: Colors.white) : svg('editor/H1'); // _valueToText[_value] == _valueString[index] ? svg('editor/H1', color: Colors.white) : svg('editor/H1');
final headerTitle = 'Header ${index + 1}';
final _isToggled = _valueToText[_value] == _valueString[index]; final _isToggled = _valueToText[_value] == _valueString[index];
return ToolbarIconButton( return ToolbarIconButton(
onPressed: () { onPressed: () {
@ -63,6 +64,7 @@ class _FlowyHeaderStyleButtonState extends State<FlowyHeaderStyleButton> {
width: widget.iconSize * kIconButtonFactor, width: widget.iconSize * kIconButtonFactor,
iconName: _attributeImageName[index], iconName: _attributeImageName[index],
isToggled: _isToggled, isToggled: _isToggled,
tooltipText: headerTitle,
); );
}), }),
); );

View File

@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
class FlowyHistoryButton extends StatelessWidget {
final IconData icon;
final double iconSize;
final bool undo;
final QuillController controller;
final String tooltipText;
const FlowyHistoryButton({
required this.icon,
required this.controller,
required this.undo,
required this.tooltipText,
required this.iconSize,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Tooltip(
message: tooltipText,
showDuration: Duration.zero,
child: HistoryButton(
icon: icon,
iconSize: iconSize,
controller: controller,
undo: true,
),
);
}
}

View File

@ -5,6 +5,7 @@ import 'toolbar_icon_button.dart';
class FlowyImageButton extends StatelessWidget { class FlowyImageButton extends StatelessWidget {
const FlowyImageButton({ const FlowyImageButton({
required this.controller, required this.controller,
required this.tooltipText,
this.iconSize = defaultIconSize, this.iconSize = defaultIconSize,
this.onImagePickCallback, this.onImagePickCallback,
this.fillColor, this.fillColor,
@ -28,6 +29,8 @@ class FlowyImageButton extends StatelessWidget {
final MediaPickSettingSelector? mediaPickSettingSelector; final MediaPickSettingSelector? mediaPickSettingSelector;
final String tooltipText;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ToolbarIconButton( return ToolbarIconButton(
@ -35,6 +38,7 @@ class FlowyImageButton extends StatelessWidget {
width: iconSize * 1.77, width: iconSize * 1.77,
onPressed: () => _onPressedHandler(context), onPressed: () => _onPressedHandler(context),
isToggled: false, isToggled: false,
tooltipText: tooltipText,
); );
} }

View File

@ -9,11 +9,13 @@ class FlowyToggleStyleButton extends StatefulWidget {
final String normalIcon; final String normalIcon;
final double iconSize; final double iconSize;
final QuillController controller; final QuillController controller;
final String tooltipText;
const FlowyToggleStyleButton({ const FlowyToggleStyleButton({
required this.attribute, required this.attribute,
required this.normalIcon, required this.normalIcon,
required this.controller, required this.controller,
required this.tooltipText,
this.iconSize = defaultIconSize, this.iconSize = defaultIconSize,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -39,6 +41,7 @@ class _ToggleStyleButtonState extends State<FlowyToggleStyleButton> {
width: widget.iconSize * kIconButtonFactor, width: widget.iconSize * kIconButtonFactor,
isToggled: _isToggled ?? false, isToggled: _isToggled ?? false,
iconName: widget.normalIcon, iconName: widget.normalIcon,
tooltipText: widget.tooltipText,
); );
} }

View File

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:math'; import 'dart:math';
import 'package:app_flowy/workspace/presentation/stack_page/doc/widget/toolbar/history_button.dart';
import 'package:flutter_quill/flutter_quill.dart'; import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
@ -50,41 +51,47 @@ class EditorToolbar extends StatelessWidget implements PreferredSizeWidget {
key: key, key: key,
toolBarHeight: toolbarIconSize * 2, toolBarHeight: toolbarIconSize * 2,
children: [ children: [
HistoryButton( FlowyHistoryButton(
icon: Icons.undo_outlined, icon: Icons.undo_outlined,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
undo: true, undo: true,
tooltipText: 'Undo',
), ),
HistoryButton( FlowyHistoryButton(
icon: Icons.redo_outlined, icon: Icons.redo_outlined,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
undo: false, undo: false,
tooltipText: 'Redo',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.bold, attribute: Attribute.bold,
normalIcon: 'editor/bold', normalIcon: 'editor/bold',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
tooltipText: 'Bold',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.italic, attribute: Attribute.italic,
normalIcon: 'editor/italic', normalIcon: 'editor/italic',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
tooltipText: 'Italic',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.underline, attribute: Attribute.underline,
normalIcon: 'editor/underline', normalIcon: 'editor/underline',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
tooltipText: 'Underline',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.strikeThrough, attribute: Attribute.strikeThrough,
normalIcon: 'editor/strikethrough', normalIcon: 'editor/strikethrough',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
tooltipText: 'Strikethrough',
), ),
FlowyColorButton( FlowyColorButton(
icon: Icons.format_color_fill, icon: Icons.format_color_fill,
@ -109,29 +116,34 @@ class EditorToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
normalIcon: 'editor/numbers', normalIcon: 'editor/numbers',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
tooltipText: 'Numbered List',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.ul, attribute: Attribute.ul,
controller: controller, controller: controller,
normalIcon: 'editor/bullet_list', normalIcon: 'editor/bullet_list',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
tooltipText: 'Bulleted List',
), ),
FlowyCheckListButton( FlowyCheckListButton(
attribute: Attribute.unchecked, attribute: Attribute.unchecked,
controller: controller, controller: controller,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
tooltipText: 'Check List',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.inlineCode, attribute: Attribute.inlineCode,
controller: controller, controller: controller,
normalIcon: 'editor/inline_block', normalIcon: 'editor/inline_block',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
tooltipText: 'Inline Code',
), ),
FlowyToggleStyleButton( FlowyToggleStyleButton(
attribute: Attribute.blockQuote, attribute: Attribute.blockQuote,
controller: controller, controller: controller,
normalIcon: 'editor/quote', normalIcon: 'editor/quote',
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
tooltipText: 'Quote Block',
), ),
FlowyLinkStyleButton( FlowyLinkStyleButton(
controller: controller, controller: controller,

View File

@ -11,10 +11,16 @@ class ToolbarIconButton extends StatelessWidget {
final VoidCallback? onPressed; final VoidCallback? onPressed;
final bool isToggled; final bool isToggled;
final String iconName; final String iconName;
final String tooltipText;
const ToolbarIconButton( const ToolbarIconButton({
{Key? key, required this.onPressed, required this.isToggled, required this.width, required this.iconName}) Key? key,
: super(key: key); required this.onPressed,
required this.isToggled,
required this.width,
required this.iconName,
required this.tooltipText,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -23,9 +29,12 @@ class ToolbarIconButton extends StatelessWidget {
iconPadding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4), iconPadding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
onPressed: onPressed, onPressed: onPressed,
width: width, width: width,
icon: isToggled == true ? svg(iconName, color: Colors.white) : svg(iconName), icon: isToggled == true
? svg(iconName, color: Colors.white)
: svg(iconName),
fillColor: isToggled == true ? theme.main1 : theme.shader6, fillColor: isToggled == true ? theme.main1 : theme.shader6,
hoverColor: isToggled == true ? theme.main1 : theme.shader5, hoverColor: isToggled == true ? theme.main1 : theme.shader5,
tooltipText: tooltipText,
); );
} }
} }

View File

@ -12,6 +12,7 @@ class FlowyIconButton extends StatelessWidget {
final Color? hoverColor; final Color? hoverColor;
final EdgeInsets iconPadding; final EdgeInsets iconPadding;
final BorderRadius? radius; final BorderRadius? radius;
final String? tooltipText;
const FlowyIconButton({ const FlowyIconButton({
Key? key, Key? key,
@ -22,6 +23,7 @@ class FlowyIconButton extends StatelessWidget {
this.hoverColor = Colors.transparent, this.hoverColor = Colors.transparent,
this.iconPadding = EdgeInsets.zero, this.iconPadding = EdgeInsets.zero,
this.radius, this.radius,
this.tooltipText,
required this.icon, required this.icon,
}) : super(key: key); }) : super(key: key);
@ -48,6 +50,9 @@ class FlowyIconButton extends StatelessWidget {
return ConstrainedBox( return ConstrainedBox(
constraints: BoxConstraints.tightFor(width: size.width, height: size.height), constraints: BoxConstraints.tightFor(width: size.width, height: size.height),
child: Tooltip(
message: tooltipText ?? '',
showDuration: Duration.zero,
child: RawMaterialButton( child: RawMaterialButton(
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
hoverElevation: 0, hoverElevation: 0,
@ -65,6 +70,7 @@ class FlowyIconButton extends StatelessWidget {
child: SizedBox.fromSize(child: child, size: childSize), child: SizedBox.fromSize(child: child, size: childSize),
), ),
), ),
),
); );
} }
} }