AROS World Exec
Support => Free Pascal => Topic started by: MarcusF on July 20, 2023, 04:08:02 PM
-
Long title but bear with me.
I'm using FP-IDE on an emulated machine through Amiga Forever, workbench 3.x
I grabbed MUIClass and it's working but when I try the image example, I get some weird results.
It's a simple program
program ImageTest;
{$mode objfpc}{$H+}
uses
MUIClass.Base, MUIClass.Window, //needed for TMUIWindow
MUIClass.Group, //needed for TMUIGroup
MUIClass.Area, //needed for TMUIButton and TMUIText
MUIClass.Image; //needed for TMUIImage
type
// My Window (mainly because we need the Event attached to an Object)
TMyWindow = class(TMUIWindow)
Text: TMUIText; // Text field
Button: TMUIButton; // Button
Image: TMUIImage; // Image
Grp: TMUIGroup;
procedure ButtonClick(Sender: TObject);
constructor Create; override;
end;
//var
//Win: TMyWindow; // Window
// Event called, when Button is pressed
procedure TMyWindow.ButtonClick(Sender: TObject);
begin
// Delete the old image ;)
Image.Free;
//
// create a new image with different picture
// because the picture you only can change on creation
Image := TMUIImage.Create;
Image.FixWidth := 200;
Image.FixHeight := 123;
Image.FreeHoriz := True;
Image.FreeVert := True;
Image.Spec.SetPicture('test2.png');
Image.Parent := Grp; // now the element will be created an linked to application
end;
constructor TMyWindow.Create;
var
Grp2: TMUIGroup;
begin
inherited Create;
Title := 'Image Window';
// a group for holding the image
Grp := TMUIGroup.Create;
Grp.Parent := Self;
// Create a image object
Image := TMUIImage.Create;
Image.FixWidth := 174; // image size, it should be read automatically, but often does not work, so we fix it here
Image.FixHeight := 129;
Image.FreeHoriz := True; // do not scale the image
Image.FreeVert := True;
Image.Spec.SetPicture('test.png');
Image.Parent := Grp;
// separate group or the recreation will change the position of the image
Grp2 := TMUIGroup.Create;
Grp2.Parent := Self;
// Create a Button with some text
Button := TMUIButton.Create;
Button.Contents := 'Click Me';
Button.OnClick := @ButtonClick; // Connect the Click Event
Button.Parent := Grp2; // Insert Button in the Window
end;
begin
// Create a Window, with a title bar text
TMyWindow.Create;
// will actually start everything,
// Create MUI object, connect them together
// from the Parent relation we builded with Pascal Classes
// Open the Window and run the Message Loop
// destroy everything after the Window is closed again.
MUIApp.Run;
end.
Create a window, add a button, add an image.
When you click the button, destroy the first image, create a new one.
This works. The weirdness is that when clicking the button, the form resizes, and if I click it again the image is again destroyed and created again but the form resizes properly.
If I click it again, it goes back to the weirdly small size. Rinse and repeat.
I've tried a few things but nothing affects the weird resizing.
-
Are those pictures the actual visual representation of what you see (as per your description) ?
The resizing in itself is correct, as that is how MUI works (if you remove a widget the parent will automatically resize, that is one of the things why it is so difficult to implement LCL as you constantly fight against MUI to have it leave things as is).
What is odd however is the content of your second picture (should be empty, on the first resize) and the fact that the resizing seem to happen on every other sequence. Perhaps things are done to quickly for MUI (e.g. needs a application.processmessages after the deletion and/or creation -> to keep it in Lazarus speak as I do not know the name of the MUI variant) and requires a manual refresh.
I'll have a look but since I'm using my new Linux box, I haven't setup emulation yet so might take some time.
edit: came across method TMUIWindow.InitChange (https://build.alb42.de/MUIClass/html/muiclass.window/tmuiwindow.initchange.html) and Exitchange (https://build.alb42.de/MUIClass/html/muiclass.window/tmuiwindow.exitchange.html). Seems to be /the/ reason to use those so perhaps you can try that in the meanwhile ?
-
Yups, the init/exit change seem to have done the trick for me.
procedure TMyWindow.ButtonClick(Sender: TObject);
begin
InitChange;
// Delete the old image ;)
Image.Free;
//
// create a new image with different picture
// because the picture you only can change on creation
Image := TMUIImage.Create;
Image.FixWidth := 200;
Image.FixHeight := 123;
Image.FreeHoriz := True;
Image.FreeVert := True;
Image.Spec.SetPicture('test2.png');
Image.Parent := Grp; // now the element will be created an linked to application
ExitChange;
end;
-
You are a wonderful person. That did the trick! No more weird resizing ;D
-
Marcus, I tried to compile your source with PortablE on AROS One x86 and I get an error !
-
Marcus, I tried to compile your source with PortablE on AROS One x86 and I get an error !
I'm not surprised, it's FreePascal code ;)
-
mod: I have split the topic so that the "unit not found issue" from user AMIGASYSTEM can now be found here (https://ae.amigalife.org/index.php?topic=1160.0) instead as it was unrelated to the issue that TS posted.