PureBasic Forum https://www.purebasic.fr/english/ |
|
[Done] Canvas Container and ResizeGadget (Workaround) https://www.purebasic.fr/english/viewtopic.php?f=24&t=71269 |
Page 1 of 1 |
Author: | mk-soft [ Wed Aug 22, 2018 12:48 pm ] |
Post subject: | [Done] Canvas Container and ResizeGadget (Workaround) |
The position Y of gadgets in the canvas gadget container are not calculated correctly. PB Version >= v5.60 MacOS 10.13.6 Code: ;-TOP
Procedure SizeWindow() Debug "1. PosY: " + GadgetY(1) ResizeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20) Debug "2. PosY: " + GadgetY(1) EndProcedure If OpenWindow(0, 0, 0, 220, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container) ButtonGadget(1, 10, 10, 80, 30, "Button") CloseGadgetList() BindEvent(#PB_Event_SizeWindow, @SizeWindow(), 0) Repeat Event = WaitWindowEvent() Until Event = #PB_Event_CloseWindow EndIf |
Author: | mk-soft [ Wed Aug 22, 2018 5:13 pm ] |
Post subject: | Re: Canvas Container and ResizeGadget |
Problem found! Is forget resize gadget container (subview) from canvas gadget... Workaround Update v0.6 Code: ;-TOP ; Workaround MacOS PB v5.60 - v5.62. Canvas Gadget Container Bugfix ; Link https://www.purebasic.fr/english/viewtopic.php?f=24&t=71269 ; ----------------------------------------------------------------------------- DeclareModule __Workaround Declare FixResizeGadget(Gadget, x, y, width, height) EndDeclareModule Module __Workaround Procedure FixResizeGadget(Gadget, x, y, width, height) ResizeGadget(Gadget, x, y, width, height) CompilerIf #PB_Compiler_OS = #PB_OS_MacOS ; Bugfix gadget container from canvasgadget Protected rect.NSRect, sv, container If GadgetType(Gadget) <> #PB_GadgetType_Canvas ProcedureReturn 1 EndIf sv = CocoaMessage(0, GadgetID(Gadget), "subviews") If CocoaMessage(0, sv, "count") container = CocoaMessage(0, sv, "objectAtIndex:", 0) If container CocoaMessage(@rect, GadgetID(Gadget), "frame") rect\origin\x = 0 rect\origin\y = 0 CocoaMessage(0, container, "setFrame:@", @rect) EndIf EndIf CompilerEndIf EndProcedure EndModule DeclareModule Workaround CompilerIf #PB_Compiler_OS = #PB_OS_MacOS Macro ResizeGadget(Gadget, x, y, width, height) __Workaround::FixResizeGadget(Gadget, x, y, width, height) EndMacro CompilerEndIf EndDeclareModule Module Workaround EndModule ; ----------------------------------------------------------------------------- CompilerIf #PB_Compiler_IsMainFile UseModule Workaround Procedure SizeWindow() ResizeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20) StartDrawing(CanvasOutput(0)) Box(2, 2, GadgetWidth(0) - 4, GadgetHeight(0) - 4, $B48246) StopDrawing() EndProcedure Define Event If OpenWindow(0, 0, 0, 220, 220, "Canvas Container Workaround", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container) ButtonGadget(1, 10, 10, 80, 30, "Button") CloseGadgetList() StartDrawing(CanvasOutput(0)) Box(2, 2, GadgetWidth(0) - 4, GadgetHeight(0) - 4, $B48246) StopDrawing() BindEvent(#PB_Event_SizeWindow, @SizeWindow(), 0) Repeat Event = WaitWindowEvent() Until Event = #PB_Event_CloseWindow EndIf CompilerEndIf How to get subViews from CanvasGadget |
Author: | wilbert [ Wed Aug 22, 2018 7:17 pm ] |
Post subject: | Re: Canvas Container and ResizeGadget |
mk-soft wrote: How to get subViews from CanvasGadget Off course there's no guarantee PB internals will stay the same but at the moment PB_CanvasView contains PB_NSFlippedView contains PBButtonGadgetView So it's the subviews of the subview you are looking for. Code: Procedure.i GetSubviews(View, Array Subviews.i(1))
Protected sv = CocoaMessage(0, View, "subviews") Protected r.NSRange\length = CocoaMessage(0, sv, "count") If r\length ReDim Subviews(r\length - 1) CocoaMessage(0, sv, "getObjects:", @Subviews(0), "range:@", @r) EndIf ProcedureReturn r\length EndProcedure If OpenWindow(0, 0, 0, 220, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container) ButtonGadget(1, 10, 10, 80, 30, "Button 1") ButtonGadget(2, 10, 40, 80, 30, "Button 2") CloseGadgetList() Dim Subviews.i(0) Count = GetSubviews(GadgetID(0), Subviews()); Count = 1 Count = GetSubviews(Subviews(0), Subviews()); Count = 2 (Button 1 & 2) For i = 0 To Count - 1 Debug Subviews(i); Output equal to GadgetID(1) and GadgetID(2) Next Repeat Event = WaitWindowEvent() Until Event = #PB_Event_CloseWindow EndIf |
Author: | mk-soft [ Wed Aug 22, 2018 8:36 pm ] |
Post subject: | Re: Canvas Container and ResizeGadget |
Thanks you, wilbert I have optimize the workaround. |
Author: | mk-soft [ Thu Aug 23, 2018 11:20 am ] |
Post subject: | Re: Canvas Container and ResizeGadget (Workaround) |
Workaround Update v0.4 Now as module for use inside modules... |
Author: | mk-soft [ Tue Sep 25, 2018 6:19 pm ] |
Post subject: | Re: Canvas Container and ResizeGadget (Workaround) |
Remember There's still time, but please don't forget ![]() |
Author: | Fred [ Fri Apr 12, 2019 4:31 pm ] |
Post subject: | Re: Canvas Container and ResizeGadget (Workaround) |
Fixed. Thanks for the fix ! |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |