comparison ios/dw.m @ 2647:34c4cb84834a

iOS: Fix a miscalculation during DWSplitBar resize. Also put in some safety checks, clamping percet 0 to 100.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 31 Aug 2021 08:57:46 +0000
parents 42bc7ddd6751
children 2362cb4b7ef9
comparison
equal deleted inserted replaced
2646:42bc7ddd6751 2647:34c4cb84834a
1989 @implementation DWSplitBar 1989 @implementation DWSplitBar
1990 -(void)setTag:(NSInteger)tag { Tag = tag; } 1990 -(void)setTag:(NSInteger)tag { Tag = tag; }
1991 -(void *)userdata { return userdata; } 1991 -(void *)userdata { return userdata; }
1992 -(void)setUserdata:(void *)input { userdata = input; } 1992 -(void)setUserdata:(void *)input { userdata = input; }
1993 -(float)percent { return percent; } 1993 -(float)percent { return percent; }
1994 -(void)setPercent:(float)input { percent = input; [self resize]; } 1994 -(void)setPercent:(float)input
1995 {
1996 percent = input;
1997 if(percent > 100.0)
1998 percent = 100.0;
1999 else if(percent < 0.0)
2000 percent = 0.0;
2001 [self resize];
2002 }
1995 -(id)topLeft { return topleft; } 2003 -(id)topLeft { return topleft; }
1996 -(void)setTopLeft:(id)input 2004 -(void)setTopLeft:(id)input
1997 { 2005 {
1998 topleft = input; 2006 topleft = input;
1999 [self addSubview:topleft]; 2007 [self addSubview:topleft];
2015 CGRect half = rect; 2023 CGRect half = rect;
2016 2024
2017 half.origin.x = half.origin.y = 0; 2025 half.origin.x = half.origin.y = 0;
2018 2026
2019 if(splittype == DW_HORZ) 2027 if(splittype == DW_HORZ)
2020 half.size.width = (100.0/percent) * rect.size.width; 2028 half.size.width = (percent/100.0) * rect.size.width;
2021 else 2029 else
2022 half.size.height = (100.0/percent) * rect.size.height; 2030 half.size.height = (percent/100.0) * rect.size.height;
2023 if(topleft) 2031 if(topleft)
2024 { 2032 {
2025 DWBox *view = topleft; 2033 DWBox *view = topleft;
2026 Box *box = [view box]; 2034 Box *box = [view box];
2027 [topleft setFrame:half]; 2035 [topleft setFrame:half];
2028 _dw_do_resize(box, half.size.width, half.size.height); 2036 _dw_do_resize(box, half.size.width, half.size.height);
2029 _dw_handle_resize_events(box); 2037 _dw_handle_resize_events(box);
2030 } 2038 }
2031 if(splittype == DW_HORZ) 2039 if(splittype == DW_HORZ)
2040 {
2032 half.origin.x = half.size.width; 2041 half.origin.x = half.size.width;
2042 half.size.width = rect.size.width - half.size.width;
2043 }
2033 else 2044 else
2045 {
2034 half.origin.y = half.size.height; 2046 half.origin.y = half.size.height;
2047 half.size.height = rect.size.height - half.size.height;
2048 }
2035 if(bottomright) 2049 if(bottomright)
2036 { 2050 {
2037 DWBox *view = bottomright; 2051 DWBox *view = bottomright;
2038 Box *box = [view box]; 2052 Box *box = [view box];
2039 [bottomright setFrame:half]; 2053 [bottomright setFrame:half];