Skip to content

Commit

Permalink
fix duplicate icon drawing code and switch to MultiSkin in a couple p…
Browse files Browse the repository at this point in the history
…laces
  • Loading branch information
joshtynjala committed Feb 23, 2024
1 parent a41907b commit 9feb1a6
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,11 @@ class MinimalComboBoxStyles {
var icon = new MultiSkin();

var defaultIcon = new Shape();
defaultIcon.graphics.beginFill(theme.labelTextColor);
defaultIcon.graphics.drawRect(2.0, 0.0, 1.0, 5.0);
defaultIcon.graphics.drawRect(0.0, 2.0, 5.0, 1.0);
defaultIcon.graphics.endFill();
drawArrowIcon(defaultIcon, theme.labelTextColor);
icon.defaultView = defaultIcon;

var disabledIcon = new Shape();
disabledIcon.graphics.beginFill(theme.labelTextDisabledColor);
disabledIcon.graphics.drawRect(2.0, 0.0, 1.0, 5.0);
disabledIcon.graphics.drawRect(0.0, 2.0, 5.0, 1.0);
disabledIcon.graphics.endFill();
drawArrowIcon(disabledIcon, theme.labelTextDisabledColor);
icon.disabledView = disabledIcon;

button.icon = icon;
Expand All @@ -89,4 +83,11 @@ class MinimalComboBoxStyles {
});
}
}

private static function drawArrowIcon(icon:Shape, color:UInt):Void {
icon.graphics.beginFill(color);
icon.graphics.drawRect(2.0, 0.0, 1.0, 5.0);
icon.graphics.drawRect(0.0, 2.0, 5.0, 1.0);
icon.graphics.endFill();
}
}
212 changes: 104 additions & 108 deletions src/com/feathersui/themes/minimal/components/MinimalDatePickerStyles.hx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ class MinimalDatePickerStyles {
var isDesktop = DeviceUtil.isDesktop();
if (button.backgroundSkin == null) {
var backgroundSkin = new MultiSkin();
var buttonSkin = new MinimalButtonSkin(theme);
backgroundSkin.defaultView = buttonSkin;
backgroundSkin.defaultView = new MinimalButtonSkin(theme);
backgroundSkin.disabledView = new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None);
backgroundSkin.setViewForState(ButtonState.UP, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
backgroundSkin.setViewForState(ButtonState.DISABLED, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
if (isDesktop) {
backgroundSkin.width = 16.0;
backgroundSkin.height = 16.0;
Expand All @@ -78,30 +77,17 @@ class MinimalDatePickerStyles {
button.backgroundSkin = backgroundSkin;
}
if (button.icon == null) {
var icon = new Shape();
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
icon.graphics.endFill();
icon.graphics.beginFill(theme.labelTextColor);
icon.graphics.moveTo(2.0, 4.0);
icon.graphics.lineTo(6.0, 0.0);
icon.graphics.lineTo(6.0, 8.0);
icon.graphics.lineTo(2.0, 4.0);
icon.graphics.endFill();
button.icon = icon;
}
if (button.getIconForState(ButtonState.DISABLED) == null) {
var icon = new MultiSkin();

var defaultIcon = new Shape();
drawDecrementMonthIcon(defaultIcon, theme.labelTextColor);
icon.defaultView = defaultIcon;

var disabledIcon = new Shape();
disabledIcon.graphics.beginFill(0xff00ff, 0.0);
disabledIcon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
disabledIcon.graphics.endFill();
disabledIcon.graphics.beginFill(theme.labelTextDisabledColor);
disabledIcon.graphics.moveTo(2.0, 4.0);
disabledIcon.graphics.lineTo(6.0, 0.0);
disabledIcon.graphics.lineTo(6.0, 8.0);
disabledIcon.graphics.lineTo(2.0, 4.0);
disabledIcon.graphics.endFill();
button.setIconForState(ButtonState.DISABLED, disabledIcon);
drawDecrementMonthIcon(disabledIcon, theme.labelTextDisabledColor);
icon.disabledView = disabledIcon;

button.icon = icon;
}
button.setPadding(2.0);
button.gap = 2.0;
Expand All @@ -112,10 +98,9 @@ class MinimalDatePickerStyles {
var isDesktop = DeviceUtil.isDesktop();
if (button.backgroundSkin == null) {
var backgroundSkin = new MultiSkin();
var buttonSkin = new MinimalButtonSkin(theme);
backgroundSkin.defaultView = buttonSkin;
backgroundSkin.defaultView = new MinimalButtonSkin(theme);
backgroundSkin.disabledView = new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None);
backgroundSkin.setViewForState(ButtonState.UP, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
backgroundSkin.setViewForState(ButtonState.DISABLED, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
if (isDesktop) {
backgroundSkin.width = 16.0;
backgroundSkin.height = 16.0;
Expand All @@ -126,30 +111,17 @@ class MinimalDatePickerStyles {
button.backgroundSkin = backgroundSkin;
}
if (button.icon == null) {
var icon = new Shape();
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
icon.graphics.endFill();
icon.graphics.beginFill(theme.labelTextColor);
icon.graphics.moveTo(2.0, 0.0);
icon.graphics.lineTo(6.0, 4.0);
icon.graphics.lineTo(2.0, 8.0);
icon.graphics.lineTo(2.0, 0.0);
icon.graphics.endFill();
button.icon = icon;
}
if (button.getIconForState(ButtonState.DISABLED) == null) {
var icon = new MultiSkin();

var defaultIcon = new Shape();
drawIncrementMonthIcon(defaultIcon, theme.labelTextColor);
icon.defaultView = defaultIcon;

var disabledIcon = new Shape();
disabledIcon.graphics.beginFill(0xff00ff, 0.0);
disabledIcon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
disabledIcon.graphics.endFill();
disabledIcon.graphics.beginFill(theme.labelTextDisabledColor);
disabledIcon.graphics.moveTo(2.0, 0.0);
disabledIcon.graphics.lineTo(6.0, 4.0);
disabledIcon.graphics.lineTo(2.0, 8.0);
disabledIcon.graphics.lineTo(2.0, 0.0);
disabledIcon.graphics.endFill();
button.setIconForState(ButtonState.DISABLED, disabledIcon);
drawIncrementMonthIcon(disabledIcon, theme.labelTextDisabledColor);
icon.disabledView = disabledIcon;

button.icon = icon;
}
button.setPadding(2.0);
button.gap = 2.0;
Expand All @@ -160,10 +132,9 @@ class MinimalDatePickerStyles {
var isDesktop = DeviceUtil.isDesktop();
if (button.backgroundSkin == null) {
var backgroundSkin = new MultiSkin();
var buttonSkin = new MinimalButtonSkin(theme);
backgroundSkin.defaultView = buttonSkin;
backgroundSkin.defaultView = new MinimalButtonSkin(theme);
backgroundSkin.disabledView = new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None);
backgroundSkin.setViewForState(ButtonState.UP, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
backgroundSkin.setViewForState(ButtonState.DISABLED, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
if (isDesktop) {
backgroundSkin.width = 16.0;
backgroundSkin.height = 16.0;
Expand All @@ -174,32 +145,17 @@ class MinimalDatePickerStyles {
button.backgroundSkin = backgroundSkin;
}
if (button.icon == null) {
var icon = new Shape();
icon.graphics.beginFill(theme.labelTextColor);
icon.graphics.moveTo(0.0, 4.0);
icon.graphics.lineTo(4.0, 0.0);
icon.graphics.lineTo(4.0, 8.0);
icon.graphics.lineTo(0.0, 4.0);
icon.graphics.moveTo(4.0, 4.0);
icon.graphics.lineTo(8.0, 0.0);
icon.graphics.lineTo(8.0, 8.0);
icon.graphics.lineTo(4.0, 4.0);
icon.graphics.endFill();
button.icon = icon;
}
if (button.getIconForState(ButtonState.DISABLED) == null) {
var icon = new MultiSkin();

var defaultIcon = new Shape();
drawDecrementYearIcon(defaultIcon, theme.labelTextColor);
icon.defaultView = defaultIcon;

var disabledIcon = new Shape();
disabledIcon.graphics.beginFill(theme.labelTextDisabledColor);
disabledIcon.graphics.moveTo(0.0, 4.0);
disabledIcon.graphics.lineTo(4.0, 0.0);
disabledIcon.graphics.lineTo(4.0, 8.0);
disabledIcon.graphics.lineTo(0.0, 4.0);
disabledIcon.graphics.moveTo(4.0, 4.0);
disabledIcon.graphics.lineTo(8.0, 0.0);
disabledIcon.graphics.lineTo(8.0, 8.0);
disabledIcon.graphics.lineTo(4.0, 4.0);
disabledIcon.graphics.endFill();
button.setIconForState(ButtonState.DISABLED, disabledIcon);
drawDecrementYearIcon(disabledIcon, theme.labelTextDisabledColor);
icon.disabledView = disabledIcon;

button.icon = icon;
}
button.setPadding(2.0);
button.gap = 2.0;
Expand All @@ -210,10 +166,9 @@ class MinimalDatePickerStyles {
var isDesktop = DeviceUtil.isDesktop();
if (button.backgroundSkin == null) {
var backgroundSkin = new MultiSkin();
var buttonSkin = new MinimalButtonSkin(theme);
backgroundSkin.defaultView = buttonSkin;
backgroundSkin.defaultView = new MinimalButtonSkin(theme);
backgroundSkin.disabledView = new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None);
backgroundSkin.setViewForState(ButtonState.UP, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
backgroundSkin.setViewForState(ButtonState.DISABLED, new MinimalRectangleSkin(SolidColor(0xff00ff, 0.0), None));
if (isDesktop) {
backgroundSkin.width = 16.0;
backgroundSkin.height = 16.0;
Expand All @@ -224,32 +179,17 @@ class MinimalDatePickerStyles {
button.backgroundSkin = backgroundSkin;
}
if (button.icon == null) {
var icon = new Shape();
icon.graphics.beginFill(theme.labelTextColor);
icon.graphics.moveTo(0.0, 0.0);
icon.graphics.lineTo(4.0, 4.0);
icon.graphics.lineTo(0.0, 8.0);
icon.graphics.lineTo(0.0, 0.0);
icon.graphics.moveTo(4.0, 0.0);
icon.graphics.lineTo(8.0, 4.0);
icon.graphics.lineTo(4.0, 8.0);
icon.graphics.lineTo(4.0, 0.0);
icon.graphics.endFill();
button.icon = icon;
}
if (button.getIconForState(ButtonState.DISABLED) == null) {
var icon = new MultiSkin();

var defaultIcon = new Shape();
drawIncrementYearIcon(defaultIcon, theme.labelTextColor);
icon.defaultView = defaultIcon;

var disabledIcon = new Shape();
disabledIcon.graphics.beginFill(theme.labelTextDisabledColor);
disabledIcon.graphics.moveTo(0.0, 0.0);
disabledIcon.graphics.lineTo(4.0, 4.0);
disabledIcon.graphics.lineTo(0.0, 8.0);
disabledIcon.graphics.lineTo(0.0, 0.0);
disabledIcon.graphics.moveTo(4.0, 0.0);
disabledIcon.graphics.lineTo(8.0, 4.0);
disabledIcon.graphics.lineTo(4.0, 8.0);
disabledIcon.graphics.lineTo(4.0, 0.0);
disabledIcon.graphics.endFill();
button.setIconForState(ButtonState.DISABLED, disabledIcon);
drawIncrementYearIcon(disabledIcon, theme.labelTextDisabledColor);
icon.disabledView = disabledIcon;

button.icon = icon;
}
button.setPadding(2.0);
button.gap = 2.0;
Expand Down Expand Up @@ -345,4 +285,60 @@ class MinimalDatePickerStyles {
});
}
}

private static function drawDecrementMonthIcon(icon:Shape, color:UInt):Void {
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
icon.graphics.endFill();
icon.graphics.beginFill(color);
icon.graphics.moveTo(2.0, 4.0);
icon.graphics.lineTo(6.0, 0.0);
icon.graphics.lineTo(6.0, 8.0);
icon.graphics.lineTo(2.0, 4.0);
icon.graphics.endFill();
}

private static function drawIncrementMonthIcon(icon:Shape, color:UInt):Void {
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
icon.graphics.endFill();
icon.graphics.beginFill(color);
icon.graphics.moveTo(2.0, 0.0);
icon.graphics.lineTo(6.0, 4.0);
icon.graphics.lineTo(2.0, 8.0);
icon.graphics.lineTo(2.0, 0.0);
icon.graphics.endFill();
}

private static function drawDecrementYearIcon(icon:Shape, color:UInt):Void {
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
icon.graphics.endFill();
icon.graphics.beginFill(color);
icon.graphics.moveTo(0.0, 4.0);
icon.graphics.lineTo(4.0, 0.0);
icon.graphics.lineTo(4.0, 8.0);
icon.graphics.lineTo(0.0, 4.0);
icon.graphics.moveTo(4.0, 4.0);
icon.graphics.lineTo(8.0, 0.0);
icon.graphics.lineTo(8.0, 8.0);
icon.graphics.lineTo(4.0, 4.0);
icon.graphics.endFill();
}

private static function drawIncrementYearIcon(icon:Shape, color:UInt):Void {
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 8.0, 8.0);
icon.graphics.endFill();
icon.graphics.beginFill(color);
icon.graphics.moveTo(0.0, 0.0);
icon.graphics.lineTo(4.0, 4.0);
icon.graphics.lineTo(0.0, 8.0);
icon.graphics.lineTo(0.0, 0.0);
icon.graphics.moveTo(4.0, 0.0);
icon.graphics.lineTo(8.0, 4.0);
icon.graphics.lineTo(4.0, 8.0);
icon.graphics.lineTo(4.0, 0.0);
icon.graphics.endFill();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.feathersui.themes.minimal.components;

import feathers.skins.MultiSkin;
import feathers.controls.FormItem;
import feathers.style.Theme;
import openfl.display.Shape;
Expand All @@ -31,20 +32,16 @@ class MinimalFormItemStyles {
if (styleProvider.getStyleFunction(FormItem, null) == null) {
styleProvider.setStyleFunction(FormItem, null, function(formItem:FormItem):Void {
if (formItem.requiredSkin == null) {
var requiredSkin = new Shape();
requiredSkin.graphics.lineStyle(1.0, theme.dangerTextColor);
requiredSkin.graphics.moveTo(3.0, 0.5);
requiredSkin.graphics.lineTo(3.0, 4.5);

requiredSkin.graphics.moveTo(1.0, 1.5);
requiredSkin.graphics.lineTo(5.0, 3.5);
requiredSkin.graphics.moveTo(1.0, 3.5);
requiredSkin.graphics.lineTo(5.0, 1.5);

requiredSkin.graphics.lineStyle();
requiredSkin.graphics.beginFill(0xff00ff, 0.0);
requiredSkin.graphics.drawRect(0.0, 0.0, 6.0, 5.0);
requiredSkin.graphics.endFill();
var requiredSkin = new MultiSkin();

var defaultIcon = new Shape();
drawRequiredIcon(defaultIcon, theme.dangerTextColor);
requiredSkin.defaultView = defaultIcon;

var disabledIcon = new Shape();
drawRequiredIcon(disabledIcon, theme.labelTextDisabledColor);
requiredSkin.disabledView = disabledIcon;

formItem.requiredSkin = requiredSkin;
}

Expand All @@ -59,4 +56,20 @@ class MinimalFormItemStyles {
});
}
}

private static function drawRequiredIcon(icon:Shape, color:UInt):Void {
icon.graphics.lineStyle(1.0, color);
icon.graphics.moveTo(3.0, 0.5);
icon.graphics.lineTo(3.0, 4.5);

icon.graphics.moveTo(1.0, 1.5);
icon.graphics.lineTo(5.0, 3.5);
icon.graphics.moveTo(1.0, 3.5);
icon.graphics.lineTo(5.0, 1.5);

icon.graphics.lineStyle();
icon.graphics.beginFill(0xff00ff, 0.0);
icon.graphics.drawRect(0.0, 0.0, 6.0, 5.0);
icon.graphics.endFill();
}
}
Loading

0 comments on commit 9feb1a6

Please sign in to comment.