@@ -10,6 +10,14 @@ pub type Rect = euclid::default::Rect<f32>;
1010mod settings;
1111pub use settings:: * ;
1212
13+ pub fn center_y ( container_h : f32 , item_h : f32 ) -> f32 {
14+ container_h / 2.0 - item_h / 2.0
15+ }
16+
17+ pub fn center_x ( container_w : f32 , item_w : f32 ) -> f32 {
18+ container_w / 2.0 - item_w / 2.0
19+ }
20+
1321#[ derive( Default , Debug , Clone , Copy , PartialEq ) ]
1422pub struct Color {
1523 pub r : f32 ,
@@ -890,24 +898,16 @@ impl Button {
890898
891899 if self . label . is_empty ( ) {
892900 let icon_size = 20.0 ;
893- let half_size = icon_size / 2.0 ;
894901 let pad_x = pad_x * 2.0 ;
895902
896- let ( x, y) = match self . text_justify {
897- TextJustify :: Left => {
898- let y = rect. origin . y + rect. size . height / 2.0 - half_size;
899- ( rect. origin . x + pad_x, y)
900- }
903+ let y = rect. origin . y + self :: center_y ( rect. size . height , icon_size) ;
904+ let x = match self . text_justify {
905+ TextJustify :: Left => rect. origin . x + pad_x,
901906 TextJustify :: Right => {
902907 let x = rect. origin . x + rect. size . width - icon_size;
903- let y = rect. origin . y + rect. size . height / 2.0 - half_size;
904- ( x + pad_x, y)
905- }
906- TextJustify :: Center => {
907- let x = rect. origin . x + rect. size . width / 2.0 - half_size;
908- let y = rect. origin . y + rect. size . height / 2.0 - half_size;
909- ( x, y)
908+ x + pad_x
910909 }
910+ TextJustify :: Center => rect. origin . x + center_x ( rect. size . width , icon_size) ,
911911 } ;
912912
913913 layer. icons . push ( IconRenderElement {
@@ -1042,12 +1042,8 @@ impl Label {
10421042 }
10431043
10441044 if !self . icon . is_empty ( ) {
1045- let ( x, y) = {
1046- let half_size = self . font_size / 2.0 ;
1047- let x = rect. origin . x + rect. size . width / 2.0 - half_size;
1048- let y = rect. origin . y + rect. size . height / 2.0 - half_size;
1049- ( x, y)
1050- } ;
1045+ let x = rect. origin . x + center_x ( rect. size . width , self . font_size ) ;
1046+ let y = rect. origin . y + center_x ( rect. size . height , self . font_size ) ;
10511047
10521048 layer. icons . push ( IconRenderElement {
10531049 origin : Point :: new ( x, y) ,
0 commit comments